From 4b638fbb43c87e505fc1f2f348fe31cab1e50dca Mon Sep 17 00:00:00 2001 From: DanRJ Date: Tue, 18 Feb 2025 12:19:58 +0100 Subject: [PATCH] Fix account details model (#21) * Change Singleton to Transient * Update account details model Change to WhenAll for fetching account details * Remove uneccessary properties from bank models Add log text that explains which field went wrong when serializing * Refactor and enhance banking service and tests - Update `BankClient_v2.cs` to adjust JSON properties and make `CreditDebitIndicator` nullable. - Add `AccountExtensions.cs` with error logging method. - Add `HasErrors` property to `AccountV2` in `BankResponse.cs`. - Enhance `GetAccountDetailsV2` in `BankService.cs` for better error handling and logging. - Update `Altinn.Dan.Plugin.Banking.Test.csproj` to target `net8.0`, add `FakeItEasy`, and reference `Altinn.Dan.Plugin.Banking`. - Add `FakeableHttpMessageHandler.cs` for handling HTTP requests in tests and generating certificates. - Add `BankServiceTests.cs` with comprehensive unit tests for `BankService`. - Remove obsolete `UnitTest1.cs`. * Fix failed tests * Nullable enabled Remove all required and add back some Remove roles Remove unused extension Remove unused usings Add tests * Fix property references a bit after introducing nullable enable * Fix balances * Fix parallel request issues in GetAccounts method Modified GetAccounts in BankService to fetch account details sequentially instead of in parallel to avoid 200 OK Internal Server Errors from Nordea. Added try-catch block to handle ApiException for each account individually, logging and adding default values for accounts with errors. Non-API exceptions are rethrown. Added comments explaining changes. * Fix failing test --- .../Altinn.Dan.Plugin.Banking.Test/Services/BankServiceTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Altinn.Dan.Plugin.Banking.Test/Services/BankServiceTests.cs b/test/Altinn.Dan.Plugin.Banking.Test/Services/BankServiceTests.cs index 26b7d8e..a69c4a1 100644 --- a/test/Altinn.Dan.Plugin.Banking.Test/Services/BankServiceTests.cs +++ b/test/Altinn.Dan.Plugin.Banking.Test/Services/BankServiceTests.cs @@ -135,7 +135,7 @@ public async Task GetAccounts_GetAccountDetailsInternalServerError_AccountHasErr Assert.IsNotNull(result); Assert.AreEqual(1, result.BankAccounts.Count); Assert.IsFalse(result.BankAccounts.Single().HasErrors); - Assert.AreEqual(2, result.BankAccounts.Single().Accounts.Count); + Assert.AreEqual(3, result.BankAccounts.Single().Accounts.Count); Assert.IsTrue(result.BankAccounts.Single().Accounts.Any(x => x.HasErrors)); }