SMS služba: prostředník nad SMS-Služba.cz (API XML 3.0)
- JSON API /v1: odeslání SMS, doručenka, události, potvrzení událostí, kredit - vlastní API klíč pro každou aplikaci (X-Api-Key, API_KEYS) - po chybě přihlášení k bráně se volání zastaví, aby se účet nezablokoval - heslo maskované v logu, odeslání se nikdy neopakuje automaticky - /health, /docs a OpenAPI s prefixem z ROOT_PATH - .NET 10, šablona .NET 8 nahrazena projektem v src/, testy v tests/ - dokumentace: návrh, stav a návod pro napojení aplikací
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
using System.Net;
|
||||
using SmsSluzba.Api.Gateway;
|
||||
|
||||
namespace SmsSluzba.Api.Tests.Gateway;
|
||||
|
||||
public class GatewayResponseTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("400;1", nameof(GatewayErrorKind.InvalidRecipient))]
|
||||
[InlineData("400;2", nameof(GatewayErrorKind.MissingText))]
|
||||
[InlineData("400", nameof(GatewayErrorKind.Rejected))]
|
||||
[InlineData("401", nameof(GatewayErrorKind.AuthFailed))]
|
||||
[InlineData("401;1", nameof(GatewayErrorKind.AuthFailed))]
|
||||
[InlineData("402", nameof(GatewayErrorKind.InsufficientCredit))]
|
||||
[InlineData("503", nameof(GatewayErrorKind.Unavailable))]
|
||||
[InlineData("999", nameof(GatewayErrorKind.Unavailable))]
|
||||
public void Interpret_StatusInBody_ThrowsMappedKind(string code, string expectedKind)
|
||||
{
|
||||
var body = $"<status><id>{code}</id><message>Popis</message></status>";
|
||||
|
||||
var ex = Assert.Throws<GatewayException>(() => GatewayResponse.Interpret(HttpStatusCode.OK, body));
|
||||
|
||||
Assert.Equal(expectedKind, ex.Kind.ToString());
|
||||
Assert.Equal(code, ex.ProviderCode);
|
||||
Assert.Equal("Popis", ex.ProviderMessage);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(HttpStatusCode.BadRequest, nameof(GatewayErrorKind.Rejected))]
|
||||
[InlineData(HttpStatusCode.Unauthorized, nameof(GatewayErrorKind.AuthFailed))]
|
||||
[InlineData(HttpStatusCode.PaymentRequired, nameof(GatewayErrorKind.InsufficientCredit))]
|
||||
[InlineData(HttpStatusCode.BadGateway, nameof(GatewayErrorKind.Unavailable))]
|
||||
public void Interpret_HttpErrorWithoutXml_ThrowsMappedKind(HttpStatusCode status, string expectedKind)
|
||||
{
|
||||
var ex = Assert.Throws<GatewayException>(() => GatewayResponse.Interpret(status, "<html>error</html"));
|
||||
|
||||
Assert.Equal(expectedKind, ex.Kind.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Interpret_StatusOk_ReturnsDocument()
|
||||
{
|
||||
var document = GatewayResponse.Interpret(HttpStatusCode.OK, "<status><id>200</id><message>OK</message></status>");
|
||||
|
||||
Assert.NotNull(document);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Interpret_EmptySuccess_ReturnsNull()
|
||||
{
|
||||
Assert.Null(GatewayResponse.Interpret(HttpStatusCode.OK, string.Empty));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Interpret_ErrorCodeInBodyWinsOverHttpStatus()
|
||||
{
|
||||
var ex = Assert.Throws<GatewayException>(() =>
|
||||
GatewayResponse.Interpret(HttpStatusCode.BadRequest, "<status><id>400;1</id><message>x</message></status>"));
|
||||
|
||||
Assert.Equal(GatewayErrorKind.InvalidRecipient, ex.Kind);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user