Release 1.0.8-rc13
This commit is contained in:
parent
5b244e357f
commit
369a8eb3c8
3 changed files with 118 additions and 1 deletions
61
src/Yavsc.Api.Test/FrontOfficeApiControllerTests.cs
Normal file
61
src/Yavsc.Api.Test/FrontOfficeApiControllerTests.cs
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
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<ApiWebServerFixture>
|
||||
{
|
||||
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<ApplicationDbContext>();
|
||||
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<ApplicationDbContext>();
|
||||
var updated = assertDb.RdvQueries.Single(q => q.Id == queryId);
|
||||
|
||||
Assert.Equal(QueryStatus.Accepted, updated.Status);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
using System.Reflection;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Yavsc.Abstract.Workflow;
|
||||
using Yavsc.Helpers;
|
||||
using Yavsc.Models;
|
||||
|
||||
namespace Yavsc.Services
|
||||
|
|
@ -35,7 +36,34 @@ namespace Yavsc.Services
|
|||
|
||||
public static IQuery GetBillable(ApplicationDbContext context, string billingCode, long queryId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (context is null) throw new ArgumentNullException(nameof(context));
|
||||
if (string.IsNullOrWhiteSpace(billingCode) || queryId <= 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (Billing.Count == 0)
|
||||
{
|
||||
WorkflowHelpers.ConfigureBillingService();
|
||||
}
|
||||
|
||||
var getter = Billing
|
||||
.FirstOrDefault(kvp => string.Equals(kvp.Key, billingCode.Trim(), StringComparison.OrdinalIgnoreCase))
|
||||
.Value;
|
||||
|
||||
if (getter is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return getter(context, queryId);
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue