test(bff): relay a refused diploma as 422 with its reason, a down scanner as 503 (refs #192)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using Bff.Api;
|
||||
|
||||
namespace Bff.Tests;
|
||||
|
||||
// S-29 (#192): the BFF reads the domain's provide-documents answer — 422 carries the refusal reason,
|
||||
// 503 means the scanner was down — into a result the endpoint relays.
|
||||
public class DomainClientProvideDocumentsTests
|
||||
{
|
||||
private sealed class Reply(HttpStatusCode status, string? json) : HttpMessageHandler
|
||||
{
|
||||
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken ct)
|
||||
=> Task.FromResult(new HttpResponseMessage(status)
|
||||
{
|
||||
Content = new StringContent(json ?? "", Encoding.UTF8, "application/json"),
|
||||
});
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(HttpStatusCode.NoContent, null, ProvideDocumentsResult.Provided)]
|
||||
[InlineData(HttpStatusCode.NotFound, null, ProvideDocumentsResult.NotFound)]
|
||||
[InlineData(HttpStatusCode.UnprocessableEntity, """{"reason":"not-a-pdf"}""", ProvideDocumentsResult.NotAPdf)]
|
||||
[InlineData(HttpStatusCode.UnprocessableEntity, """{"reason":"infected"}""", ProvideDocumentsResult.Infected)]
|
||||
[InlineData(HttpStatusCode.ServiceUnavailable, null, ProvideDocumentsResult.ScannerUnavailable)]
|
||||
public async Task Maps_the_domain_answer_to_a_result(HttpStatusCode status, string? body, ProvideDocumentsResult expected)
|
||||
{
|
||||
var client = new DomainClient(new HttpClient(new Reply(status, body)) { BaseAddress = new Uri("http://domain/") });
|
||||
|
||||
Assert.Equal(expected, await client.ProvideDocumentsAsync("reg-1", "123456782", "JVBERi0=", null, null));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user