From bedbe3b84d49ae3dfaed444775c1292d6de25c39 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 24 Sep 2023 15:15:18 +0200 Subject: [PATCH] Add test --- backend.unittests/Tests/TransactionTests.cs | 39 +++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/backend.unittests/Tests/TransactionTests.cs b/backend.unittests/Tests/TransactionTests.cs index b66c82d..3599342 100644 --- a/backend.unittests/Tests/TransactionTests.cs +++ b/backend.unittests/Tests/TransactionTests.cs @@ -1091,6 +1091,45 @@ public async void UpdateTransactionWithOnlyAccessToSingleAccount(string account) Assert.Equal("New description", updatedTransaction.Description); Assert.Equal("test category", updatedTransaction.Lines.First().Category); } + + [Fact] + public async void CreateModifyTransactionMultipleLines() + { + var model = new ViewModifyTransaction + { + Total = 1000, + DateTime = DateTime.Now, + Description = "Test description", + SourceId = AccountA.Id, + DestinationId = null, + Identifiers = new List(), + Lines = new List { + new ViewTransactionLine(500, "", "Category 1" ), + new ViewTransactionLine(500, "", "Category 2" ), + }, + MetaData = new List(), + }; + + // Make sure the transaction was properly created + var transaction = (await TransactionController.Create(model)).OkValue(); + Assert.NotNull(transaction); + Assert.Equivalent(transaction, (await TransactionController.Get(transaction.Id)).OkValue()); + + // Modify the transaction to be unsplit + model.Lines = new List { new ViewTransactionLine(1000, "", "Category 1") }; + var modifiedTransaction = (await TransactionController.Update(transaction.Id, model)).OkValue(); + Assert.NotNull(modifiedTransaction); + Assert.Equivalent(modifiedTransaction, (await TransactionController.Get(transaction.Id)).OkValue()); + + // Modify the transaction to be split again + model.Lines = new List { + new ViewTransactionLine(500, "", "Category 1" ), + new ViewTransactionLine(500, "", "Category 2" ), + }; + modifiedTransaction = (await TransactionController.Update(transaction.Id, model)).OkValue(); + Assert.NotNull(modifiedTransaction); + Assert.Equivalent(modifiedTransaction, (await TransactionController.Get(transaction.Id)).OkValue()); + } } }