using System.Net; using System.Net.Http.Json; using BigRegister.Api.Contracts; using Microsoft.AspNetCore.Mvc.Testing; namespace BigRegister.Tests; public class EndpointTests(WebApplicationFactory factory) : IClassFixture> { private readonly HttpClient _client = factory.CreateClient(); [Fact] public async Task DashboardView_computes_eligibility_decision() { var dto = await _client.GetFromJsonAsync("/api/dashboard-view"); Assert.NotNull(dto); Assert.Equal("19012345601", dto.Registration.BigNummer); Assert.Equal("Geregistreerd", dto.Registration.Status.Tag); // seed deadline 2027-03-01 is within 12 months of "today" (2026) → eligible Assert.True(dto.Decisions.EligibleForHerregistratie); Assert.NotNull(dto.Decisions.HerregistratieReason); } [Fact] public async Task Notes_returns_seeded_aantekeningen() { var notes = await _client.GetFromJsonAsync>("/api/notes"); Assert.Equal(3, notes!.Count); } [Fact] public async Task Brp_returns_address() { var dto = await _client.GetFromJsonAsync("/api/brp/address"); Assert.True(dto!.Gevonden); Assert.Equal("2514 EA", dto.Adres!.Postcode); } [Fact] public async Task Duo_lookup_carries_server_decided_questions_and_professions() { var dto = await _client.GetFromJsonAsync("/api/duo/diplomas"); Assert.NotNull(dto); var english = dto.Diplomas.Single(d => d.Id == "d2"); Assert.Equal("Arts", english.Beroep); Assert.Contains(english.PolicyQuestions, q => q.Id == "nl-taalvaardigheid"); var dutch = dto.Diplomas.Single(d => d.Id == "d1"); Assert.Empty(dutch.PolicyQuestions); // DUO "not found" fallback: an unlisted diploma → user uses the manual path, // which the same lookup provides (maximal question set + declarable professions). Assert.DoesNotContain(dto.Diplomas, d => d.Id == "unknown-id"); Assert.Equal(3, dto.Handmatig.PolicyQuestions.Count); Assert.Equal(5, dto.Handmatig.Beroepen.Count); } [Fact] public async Task IntakePolicy_returns_scholing_threshold() { var dto = await _client.GetFromJsonAsync("/api/intake/policy"); Assert.Equal(1000, dto!.ScholingThreshold); } [Fact] public async Task Registration_with_duo_diploma_succeeds() { var res = await _client.PostAsJsonAsync("/api/registrations", new RegistratieRequest("duo")); res.EnsureSuccessStatusCode(); var body = await res.Content.ReadFromJsonAsync(); Assert.StartsWith("BIG-2026-", body!.Referentie); } [Fact] public async Task Registration_with_manual_diploma_is_rejected_with_problem_details() { var res = await _client.PostAsJsonAsync("/api/registrations", new RegistratieRequest("handmatig")); Assert.Equal(HttpStatusCode.UnprocessableEntity, res.StatusCode); Assert.Contains("application/problem+json", res.Content.Headers.ContentType!.ToString()); } [Theory] [InlineData("/api/intakes")] [InlineData("/api/herregistraties")] public async Task Zero_hours_submission_is_rejected(string route) { var res = await _client.PostAsJsonAsync(route, new { uren = 0 }); Assert.Equal(HttpStatusCode.UnprocessableEntity, res.StatusCode); } [Theory] [InlineData("/api/intakes")] [InlineData("/api/herregistraties")] public async Task Worked_hours_submission_succeeds(string route) { var res = await _client.PostAsJsonAsync(route, new { uren = 40 }); res.EnsureSuccessStatusCode(); } }