Fix international order VAT and currencies in Enova and Optima
This commit is contained in:
1 parent
75ef1ed69c
commit
248d7bac64
23 files changed
+308
-34
No files matched your search
@@ -3,6 +3,8 @@ using System.Reflection;
|
||||
using System.Runtime.Loader;
|
||||
using SmartB2B.Sync.Contracts;
|
||||
using SmartB2B.Sync.Service;
|
||||
using SmartB2B.Enova.Adapter;
|
||||
using Soneta.Core;
|
||||
using SmartB2B.Enova.Service;
|
||||
using SmartB2B.Enova.Service.Configuration;
|
||||
using SmartB2B.Sync.Service.Orders;
|
||||
@@ -29,7 +31,8 @@ var tests = new (string Name, Func<Task> Run)[]
|
||||
("place_order zwraca nazwany wynik", PlaceOrderKeywordResult),
|
||||
("Warstwa WAMP wysyła wynik jako kwargs", WampKeywordWireResult),
|
||||
("Brak waluty zwraca stabilny błąd", MissingCurrency),
|
||||
("Waluta inna niż PLN jest odrzucana", UnsupportedCurrency),
|
||||
("Waluty i flagi kontrahenta z WampOrder są obsługiwane", ForeignCurrencyMapping),
|
||||
("Rodzaj VAT Enovy wynika z obu flag kontrahenta", EnovaCustomerTypeMapping),
|
||||
("Błąd adaptera jest wypisywany na stderr", AdapterErrorIsWrittenToStderr),
|
||||
("Brak katalogu Enovy jest wykrywany", MissingEnovaDirectory),
|
||||
("Sekrety są odczytywane z pliku konfiguracji", SecretsComeFromConfigurationFile),
|
||||
@@ -43,8 +46,15 @@ var tests = new (string Name, Func<Task> Run)[]
|
||||
};
|
||||
|
||||
var failures = 0;
|
||||
var skipped = 0;
|
||||
foreach (var test in tests)
|
||||
{
|
||||
if (!OperatingSystem.IsWindows() && test.Run == (Func<Task>)DatabaseRegistrationUsesConnectionString)
|
||||
{
|
||||
skipped++;
|
||||
Console.WriteLine($"SKIP: {test.Name}: test wymaga instalacji Enovy na Windows.");
|
||||
continue;
|
||||
}
|
||||
try
|
||||
{
|
||||
await test.Run();
|
||||
@@ -57,7 +67,7 @@ foreach (var test in tests)
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine($"Wynik: {tests.Length - failures}/{tests.Length} testów zaliczonych.");
|
||||
Console.WriteLine($"Wynik: {tests.Length - skipped - failures}/{tests.Length - skipped} testów zaliczonych, pominięto: {skipped}.");
|
||||
return failures == 0 ? 0 : 1;
|
||||
|
||||
static Task SqlProviderIsSupported()
|
||||
@@ -263,13 +273,42 @@ static async Task MissingCurrency()
|
||||
await AssertWampError(handler.HandleAsync(invocation, CancellationToken.None), "eu.smartb2b.missing_currency");
|
||||
}
|
||||
|
||||
static async Task UnsupportedCurrency()
|
||||
static async Task ForeignCurrencyMapping()
|
||||
{
|
||||
var handler = new PlaceOrderHandler(new FakeAdapter(), CreateConfiguration());
|
||||
var invocation = CreateInvocation("EUR");
|
||||
await AssertWampError(
|
||||
handler.HandleAsync(invocation, CancellationToken.None),
|
||||
"eu.smartb2b.erp.currency_not_supported");
|
||||
foreach (var currency in new[] { "EUR", "USD", "CZK", "PLN" })
|
||||
foreach (var (international, eu) in new[] { (false, true), (true, true), (true, false) })
|
||||
{
|
||||
var adapter = new FakeAdapter();
|
||||
var arguments = new Dictionary<string, object?>(CreateInvocation($" {currency.ToLowerInvariant()} ").KeywordArguments)
|
||||
{
|
||||
["companyIsInternational"] = international,
|
||||
["companyIsInEuropeanUnion"] = eu
|
||||
};
|
||||
await new PlaceOrderHandler(adapter, CreateConfiguration())
|
||||
.HandleAsync(new RpcInvocation([], arguments), CancellationToken.None);
|
||||
AssertEqual(currency, adapter.LastRequest?.CurrencyIso, "currency_iso");
|
||||
AssertEqual(international, adapter.LastRequest?.CompanyIsInternational, "companyIsInternational");
|
||||
AssertEqual(eu, adapter.LastRequest?.CompanyIsInEuropeanUnion, "companyIsInEuropeanUnion");
|
||||
}
|
||||
}
|
||||
|
||||
static Task EnovaCustomerTypeMapping()
|
||||
{
|
||||
foreach (var (international, eu, expected) in new[]
|
||||
{
|
||||
(false, true, RodzajPodmiotu.Krajowy),
|
||||
(false, false, RodzajPodmiotu.Krajowy),
|
||||
(true, true, RodzajPodmiotu.Unijny),
|
||||
(true, false, RodzajPodmiotu.Eksportowy)
|
||||
})
|
||||
{
|
||||
AssertEqual(expected, EnovaOrderAdapter.GetCustomerType(new OrderRequest
|
||||
{
|
||||
CompanyIsInternational = international,
|
||||
CompanyIsInEuropeanUnion = eu
|
||||
}), "rodzaj podmiotu na dokumencie");
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
static async Task AdapterErrorIsWrittenToStderr()
|
||||
@@ -535,11 +574,6 @@ file sealed class FakeAdapter : IErpOrderAdapter
|
||||
|
||||
public OrderResult CreateOrder(OrderRequest request)
|
||||
{
|
||||
if (!string.Equals(request.CurrencyIso, "PLN", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
throw new ErpOperationException("eu.smartb2b.erp.currency_not_supported", "Waluta nie jest obsługiwana.");
|
||||
}
|
||||
|
||||
LastRequest = request;
|
||||
return new OrderResult(
|
||||
1,
|
||||
|
||||
Reference in new issue
Block a user