Files
atomic-design-poc/backend/tests/BigRegister.Tests/Acceptance/PhoneFormatContractTests.cs
T
ehoandClaude Sonnet 5 8560746d15 refactor: strip WP-/RB- ticket refs from backend (RD-19)
The backend half of the sweep RD-18 did for the front end. git blame
holds the provenance and stays correct when the code moves; the
comment names a closed ticket and tells the reader nothing the
sentence around it does not.

public/letter.css and LetterHtml.golden.html change together, because
the renderer inlines the CSS and the golden file snapshots the
result.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-04 21:48:08 +02:00

55 lines
2.5 KiB
C#

using System.Net;
using System.Net.Http.Json;
using BigRegister.Api.Contracts;
namespace BigRegister.Tests.Acceptance;
/// <summary>
/// Contract test for the FE/BE seam on phone-number stripping. Both sides share
/// the same format regex (<c>^0\d{9}$</c>) but, until this test, diverged on what they
/// strip before checking it: the FE's <c>parseTelefoonnummer</c>
/// (registratie/domain/value-objects/telefoonnummer.ts) also drops parentheses and maps a
/// leading <c>+31</c> to a leading <c>0</c>; <see cref="BigRegister.Domain.Submissions.SubmissionRules.RejectPhoneChange"/>
/// used to strip only spaces and dashes. This was latent, not live — the FE always sends
/// its already-normalised value over the wire — but a crafted/future caller posting a raw,
/// FE-valid number would hit a backend that disagrees with the FE about what's valid. The
/// backend is the authority (ADR-0001), so it must agree with the FE on every FE-valid input.
/// </summary>
public class PhoneFormatContractTests(TestWebApplicationFactory factory) : IClassFixture<TestWebApplicationFactory>
{
private readonly HttpClient _client = factory.CreateClient();
private Task<HttpResponseMessage> PostChangeRequest(string telefoon) =>
_client.PostAsJsonAsync("/api/v1/change-requests", new ChangeRequestRequest(telefoon));
[Fact]
public async Task A_leading_plus31_is_accepted_like_the_frontends_normalised_form()
{
// Given a phone number in international form — parseTelefoonnummer maps a leading
// "+31" to "0" and accepts it (it becomes "0612345678", 10 digits starting 0).
// When it is posted to the backend exactly as the user typed it (not FE-normalised)...
var res = await PostChangeRequest("+31612345678");
// Then the backend must agree it's valid, not reject it as malformed.
res.EnsureSuccessStatusCode();
var body = (await res.Content.ReadFromJsonAsync<ReferentieResponse>())!;
Assert.NotNull(body.Referentie);
}
[Fact]
public async Task Parentheses_around_the_area_code_are_accepted_like_the_frontend()
{
// Given a phone number with the area code in parentheses — parseTelefoonnummer strips
// "()" along with spaces/dashes and accepts it (it becomes "0612345678").
// When it is posted to the backend exactly as the user typed it...
var res = await PostChangeRequest("(06) 12345678");
// Then the backend must agree it's valid, not reject it as malformed.
res.EnsureSuccessStatusCode();
var body = (await res.Content.ReadFromJsonAsync<ReferentieResponse>())!;
Assert.NotNull(body.Referentie);
}
}