feat(api): initialize account with starting balance
This commit is contained in:
@@ -42,8 +42,14 @@ internal static class Endpoint
|
|||||||
return Results.Conflict();
|
return Results.Conflict();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: We need to get the initial balance
|
||||||
|
// of the account
|
||||||
|
|
||||||
var accountMetadata = PlaidAccountMetadata.From(request.PlaidAccountId, request.PlaidAccountName);
|
var accountMetadata = PlaidAccountMetadata.From(request.PlaidAccountId, request.PlaidAccountName);
|
||||||
var account = Account.From(user.Institutions.First().Id, request.PlaidAccountName, accountMetadata);
|
var account = Account.From(user.Institutions.First().Id, request.PlaidAccountName, accountMetadata);
|
||||||
|
var balance = Balance.From(request.AccountCurrentBalance, request.AccountAvailableBalance);
|
||||||
|
|
||||||
|
account.AddBalance(balance);
|
||||||
user.AddAccount(account);
|
user.AddAccount(account);
|
||||||
|
|
||||||
await appDbContext.SaveChangesAsync(ct);
|
await appDbContext.SaveChangesAsync(ct);
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ public record Request : IValidatableObject
|
|||||||
public string PlaidInstitutionId { get; init; } = string.Empty;
|
public string PlaidInstitutionId { get; init; } = string.Empty;
|
||||||
public string PlaidAccountId { get; init; } = string.Empty;
|
public string PlaidAccountId { get; init; } = string.Empty;
|
||||||
public string PlaidAccountName { get; init; } = string.Empty;
|
public string PlaidAccountName { get; init; } = string.Empty;
|
||||||
|
public decimal AccountCurrentBalance { get; init; }
|
||||||
|
public decimal AccountAvailableBalance { get; init; }
|
||||||
|
|
||||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -222,6 +222,7 @@ public class AddTests(TestApi testApi) : IntegrationTest(testApi)
|
|||||||
|
|
||||||
var newAccountId = "newAccountId";
|
var newAccountId = "newAccountId";
|
||||||
var newAccountName = "New Account";
|
var newAccountName = "New Account";
|
||||||
|
var expectedBalance = 100;
|
||||||
|
|
||||||
using var request = HttpRequestBuilder.New()
|
using var request = HttpRequestBuilder.New()
|
||||||
.Post(AddUri)
|
.Post(AddUri)
|
||||||
@@ -231,6 +232,8 @@ public class AddTests(TestApi testApi) : IntegrationTest(testApi)
|
|||||||
plaidInstitutionId = ((PlaidMetadata)institution.Metadata!).PlaidId,
|
plaidInstitutionId = ((PlaidMetadata)institution.Metadata!).PlaidId,
|
||||||
plaidAccountId = newAccountId,
|
plaidAccountId = newAccountId,
|
||||||
plaidAccountName = newAccountName,
|
plaidAccountName = newAccountName,
|
||||||
|
accountCurrentBalance = expectedBalance,
|
||||||
|
accountAvailableBalance = expectedBalance,
|
||||||
})
|
})
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
@@ -242,6 +245,9 @@ public class AddTests(TestApi testApi) : IntegrationTest(testApi)
|
|||||||
async (context, ct) => await context.Set<User>()
|
async (context, ct) => await context.Set<User>()
|
||||||
.Include(u => u.Accounts)
|
.Include(u => u.Accounts)
|
||||||
.ThenInclude(a => a.Metadata)
|
.ThenInclude(a => a.Metadata)
|
||||||
|
.Include(u => u.Accounts)
|
||||||
|
.ThenInclude(a => a.Balances)
|
||||||
|
.AsSplitQuery()
|
||||||
.FirstAsync(u => u.Id == user.Id, ct),
|
.FirstAsync(u => u.Id == user.Id, ct),
|
||||||
TestContext.Current.CancellationToken
|
TestContext.Current.CancellationToken
|
||||||
);
|
);
|
||||||
@@ -253,5 +259,12 @@ public class AddTests(TestApi testApi) : IntegrationTest(testApi)
|
|||||||
((PlaidAccountMetadata)a.Metadata).PlaidId == newAccountId &&
|
((PlaidAccountMetadata)a.Metadata).PlaidId == newAccountId &&
|
||||||
((PlaidAccountMetadata)a.Metadata).PlaidName == newAccountName
|
((PlaidAccountMetadata)a.Metadata).PlaidName == newAccountName
|
||||||
);
|
);
|
||||||
|
|
||||||
|
updatedUser.Accounts.First()
|
||||||
|
.Balances.Should().ContainSingle(
|
||||||
|
b => b.AccountId == updatedUser.Accounts.First().Id &&
|
||||||
|
b.Current == expectedBalance &&
|
||||||
|
b.Available == expectedBalance
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user