using System.Net; using System.Net.Http.Headers; using Microsoft.Extensions.DependencyInjection; using Yavsc.Api.Test.Fixtures; using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Tests.Shared; namespace Yavsc.Api.Test; [Collection("Yavsc Api")] public sealed class FrontOfficeApiControllerTests : IClassFixture { private readonly ApiWebServerFixture _fixture; public FrontOfficeApiControllerTests(ApiWebServerFixture fixture) { _fixture = fixture; } private HttpClient NewClient(string subject = "alice", string scope = "api") { var handler = new HttpClientHandler { ServerCertificateCustomValidationCallback = (_, _, _, _) => true }; var http = new HttpClient(handler) { BaseAddress = new Uri(_fixture.BaseAddress) }; http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", TestTokenIssuer.Issue(subject, scope)); return http; } [Fact] public async Task Front_accept_query_updates_status_without_server_error() { WorkflowHelpers.ConfigureBillingService(); _fixture.ResetAndSeedRdvQueryGraph(); long queryId; using (var scope = _fixture.Services.CreateScope()) { var db = scope.ServiceProvider.GetRequiredService(); queryId = db.RdvQueries.Select(q => q.Id).Single(); } using var http = NewClient(); var response = await http.PostAsync($"/api/v1/front/query/accept?billingCode=Rdv&queryId={queryId}", content: null, TestContext.Current.CancellationToken); Assert.Equal(HttpStatusCode.OK, response.StatusCode); using var assertScope = _fixture.Services.CreateScope(); var assertDb = assertScope.ServiceProvider.GetRequiredService(); var updated = assertDb.RdvQueries.Single(q => q.Id == queryId); Assert.Equal(QueryStatus.Accepted, updated.Status); } }