Skip to content

Commit

Permalink
Adds Integration Tests for Delete Transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
Chingling152 committed Jan 25, 2024
1 parent 83e3981 commit 42fb109
Showing 1 changed file with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,51 @@ public async Task Delete_PaidTransaction_RemovesTransactionFromDatabase()
}

[Test]
public async Task Delete_NotPaidTransaction_RemovesTransactionFromDatabase()
public async Task Delete_EarnPaidTransaction_DecreasesBalanceFromDatabase()
{
var body = this.modelBuilder
.WithStatus(TransactionStatus.NotCommitted)
.WithStatus(TransactionStatus.Committed)
.WithType(TransactionType.Earn)
.WithActiveStatus(true)
.Generate();

body.Id = this.InsertTransaction(body);
var oldBalanceAmount = this.fixture.GetData<BalanceEntity>().FirstOrDefault(x => x.Id == body.BalanceId).Amount;

await this.client.DeleteAsync($"{baseEndpoint}/{body.Id}");

var balance = this.fixture.GetData<BalanceEntity>().FirstOrDefault(x => x.Id == body.BalanceId);
Assert.That(balance.Amount, Is.EqualTo(oldBalanceAmount - body.Amount));
}

[Test]
public async Task Delete_ExpensePaidTransaction_DecreasesBalanceFromDatabase()
{
var body = this.modelBuilder
.WithStatus(TransactionStatus.Committed)
.WithType(TransactionType.Expense)
.WithActiveStatus(true)
.Generate();

body.Id = this.InsertTransaction(body);
var oldBalanceAmount = this.fixture.GetData<BalanceEntity>().FirstOrDefault(x => x.Id == body.BalanceId).Amount;

await this.client.DeleteAsync($"{baseEndpoint}/{body.Id}");

var balance = this.fixture.GetData<BalanceEntity>().FirstOrDefault(x => x.Id == body.BalanceId);
Assert.That(balance.Amount, Is.EqualTo(oldBalanceAmount + body.Amount));
}

[TestCase(TransactionStatus.NotCommitted, true)]
[TestCase(TransactionStatus.NotCommitted, false)]
[TestCase(TransactionStatus.Committed, false)]
public async Task Delete_NotPaidTransaction_RemovesTransactionFromDatabase(TransactionStatus status, bool isActive)
{
var body = this.modelBuilder
.WithStatus(status)
.WithActiveStatus(isActive)
.Generate();

body.Id = this.InsertTransaction(body);

await this.client.DeleteAsync($"{baseEndpoint}/{body.Id}");
Expand Down

0 comments on commit 42fb109

Please sign in to comment.