|
- using System.Net;
- using System.Net.Http.Headers;
- using System.Net.Http.Json;
-
- namespace Campaign_Tracker.Server.Tests;
-
- public sealed class ExtensionRecordControllerTests
- {
- [Fact]
- public async Task SaveExtensionRecord_StoresRequiredLegacyReference_AC1()
- {
- await using var factory = new AuthIntegrationTestFactory();
- using var client = factory.CreateClient();
- client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
- "Bearer", AuthIntegrationTestFactory.CreateToken("admin@example.test", "admin"));
-
- var response = await client.PostAsJsonAsync("/api/admin/extension-records", new
- {
- recordType = "MunicipalityProfile",
- recordId = "mp-001",
- legacyLink = new { type = 0, value = "FAIR01" },
- });
-
- var body = await response.Content.ReadFromJsonAsync<ExtensionRecordResponse>();
-
- Assert.Equal(HttpStatusCode.OK, response.StatusCode);
- Assert.NotNull(body);
- Assert.Equal("MunicipalityProfile", body.RecordType);
- Assert.Equal("mp-001", body.RecordId);
- Assert.Equal("JurisdictionJCode", body.LinkType);
- Assert.Equal("FAIR01", body.LinkValue);
- }
-
- [Fact]
- public async Task SaveExtensionRecord_InvalidLegacyReference_IsRejectedBeforeSave_AC3()
- {
- await using var factory = new AuthIntegrationTestFactory();
- using var client = factory.CreateClient();
- client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
- "Bearer", AuthIntegrationTestFactory.CreateToken("admin@example.test", "admin"));
-
- var response = await client.PostAsJsonAsync("/api/admin/extension-records", new
- {
- recordType = "MunicipalityProfile",
- recordId = "mp-ghost",
- legacyLink = new { type = 0, value = "NOPE" },
- });
-
- var body = await response.Content.ReadFromJsonAsync<ExtensionRecordValidationProblem>();
-
- Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
- Assert.NotNull(body);
- Assert.Contains("NOPE", body.Error);
- }
-
- private sealed record ExtensionRecordResponse(
- string RecordType,
- string RecordId,
- string LinkType,
- string LinkValue);
-
- private sealed record ExtensionRecordValidationProblem(string Error);
- }
|