feat: continued wip on supporting transactions
This commit is contained in:
@@ -1,6 +1,3 @@
|
||||
using Aspire.Hosting;
|
||||
using Aspire.Hosting.Testing;
|
||||
|
||||
namespace FiscalOS.AppHost.Tests.Infra;
|
||||
|
||||
public sealed class AspireFixture : IAsyncLifetime
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
global using Aspire.Hosting;
|
||||
global using Aspire.Hosting.Testing;
|
||||
|
||||
global using FiscalOS.AppHost.Tests.Infra;
|
||||
|
||||
global using Microsoft.Playwright;
|
||||
global using Microsoft.Playwright.Xunit.v3;
|
||||
@@ -0,0 +1,44 @@
|
||||
namespace FiscalOS.Infra.Tests.Integration;
|
||||
|
||||
public abstract class IntegrationTest : IAsyncLifetime
|
||||
{
|
||||
private bool _isDisposed;
|
||||
private readonly FileSystem _fileSystem = new();
|
||||
protected AppDbContext AppDbContext { get; }
|
||||
|
||||
protected IntegrationTest()
|
||||
{
|
||||
var options = Options.Create(new AppDbContextOptions()
|
||||
{
|
||||
DatabaseFilePath = $"{Guid.NewGuid()}.db",
|
||||
});
|
||||
|
||||
AppDbContext = new(options, _fileSystem);
|
||||
}
|
||||
|
||||
public async ValueTask InitializeAsync()
|
||||
{
|
||||
await AppDbContext.Database.MigrateAsync();
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
await DisposeAsync(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual async Task DisposeAsync(bool disposing)
|
||||
{
|
||||
if (_isDisposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
await AppDbContext.DisposeAsync();
|
||||
}
|
||||
|
||||
_isDisposed = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
namespace FiscalOS.Infra.Tests.Integration;
|
||||
|
||||
public class PlaidRemovedTransactionHandlerTests : IntegrationTest
|
||||
{
|
||||
private readonly Mock<ILogger<PlaidRemovedTransactionHandler>> _mockLogger = new();
|
||||
private readonly PlaidRemovedTransactionHandler _sut;
|
||||
|
||||
public PlaidRemovedTransactionHandlerTests()
|
||||
{
|
||||
_sut = PlaidRemovedTransactionHandler.From(AppDbContext, _mockLogger.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenCalled_ItShouldRemoveTheCorrectTransactions()
|
||||
{
|
||||
var user = User.From(
|
||||
"username",
|
||||
"hashedPassword",
|
||||
EncryptedDataKey.From("keyUsed", "encryptedKey")
|
||||
);
|
||||
|
||||
var institutionMetadata = PlaidInstitutionMetadata.From(
|
||||
"plaidId",
|
||||
"plaidName",
|
||||
"encryptedAccessToken",
|
||||
"itemId"
|
||||
);
|
||||
var institution = Institution.From("institutionName", institutionMetadata);
|
||||
user.AddInstitution(institution);
|
||||
|
||||
var accountMetadata = PlaidAccountMetadata.From("plaidId", "plaidName");
|
||||
var account = Account.From("some account", accountMetadata);
|
||||
user.AddAccount(account);
|
||||
institution.AddAccount(account);
|
||||
|
||||
var transactionMetadata = PlaidTransactionMetadata.From("plaidId");
|
||||
var transaction = Transaction.From(
|
||||
"merchantName",
|
||||
"description",
|
||||
100,
|
||||
DateTimeOffset.UtcNow,
|
||||
transactionMetadata
|
||||
);
|
||||
user.AddTransaction(transaction);
|
||||
account.AddTransaction(transaction);
|
||||
|
||||
await AppDbContext.AddAsync(user, TestContext.Current.CancellationToken);
|
||||
await AppDbContext.SaveChangesAsync(TestContext.Current.CancellationToken);
|
||||
|
||||
var transactionToRemove = new Going.Plaid.Entity.RemovedTransaction()
|
||||
{
|
||||
TransactionId = transactionMetadata.PlaidId,
|
||||
};
|
||||
|
||||
var result = await _sut.HandleAsync([transactionToRemove], TestContext.Current.CancellationToken);
|
||||
|
||||
result.Should().Be(1);
|
||||
}
|
||||
}
|
||||
@@ -7,19 +7,26 @@ global using System.Text.Json;
|
||||
|
||||
global using AwesomeAssertions.Primitives;
|
||||
|
||||
global using FiscalOS.Core.Accounts;
|
||||
global using FiscalOS.Core.Identity;
|
||||
global using FiscalOS.Core.Security;
|
||||
global using FiscalOS.Core.Transactions;
|
||||
global using FiscalOS.Infra.Accounts.Plaid;
|
||||
global using FiscalOS.Infra.Authentication;
|
||||
global using FiscalOS.Infra.Authorization;
|
||||
global using FiscalOS.Infra.Data;
|
||||
global using FiscalOS.Infra.Security;
|
||||
global using FiscalOS.Infra.Tests.Assertions;
|
||||
global using FiscalOS.Infra.Tests.Mocks;
|
||||
global using FiscalOS.Infra.Transactions.Plaid;
|
||||
|
||||
global using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
global using Microsoft.AspNetCore.Authorization;
|
||||
global using Microsoft.AspNetCore.Authorization.Policy;
|
||||
global using Microsoft.AspNetCore.Http;
|
||||
global using Microsoft.AspNetCore.Mvc;
|
||||
global using Microsoft.EntityFrameworkCore;
|
||||
global using Microsoft.Extensions.Configuration;
|
||||
global using Microsoft.Extensions.Logging;
|
||||
global using Microsoft.Extensions.Options;
|
||||
global using Microsoft.IdentityModel.Tokens;
|
||||
Reference in New Issue
Block a user