Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

64 строки
2.3KB

  1. using System.Net;
  2. using System.Net.Http.Headers;
  3. using System.Net.Http.Json;
  4. namespace Campaign_Tracker.Server.Tests;
  5. public sealed class ExtensionRecordControllerTests
  6. {
  7. [Fact]
  8. public async Task SaveExtensionRecord_StoresRequiredLegacyReference_AC1()
  9. {
  10. await using var factory = new AuthIntegrationTestFactory();
  11. using var client = factory.CreateClient();
  12. client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
  13. "Bearer", AuthIntegrationTestFactory.CreateToken("admin@example.test", "admin"));
  14. var response = await client.PostAsJsonAsync("/api/admin/extension-records", new
  15. {
  16. recordType = "MunicipalityProfile",
  17. recordId = "mp-001",
  18. legacyLink = new { type = 0, value = "FAIR01" },
  19. });
  20. var body = await response.Content.ReadFromJsonAsync<ExtensionRecordResponse>();
  21. Assert.Equal(HttpStatusCode.OK, response.StatusCode);
  22. Assert.NotNull(body);
  23. Assert.Equal("MunicipalityProfile", body.RecordType);
  24. Assert.Equal("mp-001", body.RecordId);
  25. Assert.Equal("JurisdictionJCode", body.LinkType);
  26. Assert.Equal("FAIR01", body.LinkValue);
  27. }
  28. [Fact]
  29. public async Task SaveExtensionRecord_InvalidLegacyReference_IsRejectedBeforeSave_AC3()
  30. {
  31. await using var factory = new AuthIntegrationTestFactory();
  32. using var client = factory.CreateClient();
  33. client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
  34. "Bearer", AuthIntegrationTestFactory.CreateToken("admin@example.test", "admin"));
  35. var response = await client.PostAsJsonAsync("/api/admin/extension-records", new
  36. {
  37. recordType = "MunicipalityProfile",
  38. recordId = "mp-ghost",
  39. legacyLink = new { type = 0, value = "NOPE" },
  40. });
  41. var body = await response.Content.ReadFromJsonAsync<ExtensionRecordValidationProblem>();
  42. Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
  43. Assert.NotNull(body);
  44. Assert.Contains("NOPE", body.Error);
  45. }
  46. private sealed record ExtensionRecordResponse(
  47. string RecordType,
  48. string RecordId,
  49. string LinkType,
  50. string LinkValue);
  51. private sealed record ExtensionRecordValidationProblem(string Error);
  52. }

Powered by TurnKey Linux.