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()); + } } }