Initial commit: Purrse personal finance app
Self-hosted, plugin-extensible personal finance manager built with ASP.NET Core 9.0, Vue 3 + Vuetify 3, and PostgreSQL 17. Backend (8 .NET projects): - Core: 19 domain models, 6 enums, 14 DTOs, 12 service interfaces - Data: EF Core DbContext, 16 entity configurations, category seeder - API: 14 controllers, 15 services, JWT auth, SignalR, middleware - Plugins: Abstractions + OFX/CSV/QIF file parsers - Tests: 28 xUnit tests (fingerprinting, duplicate detection, parsers) Frontend (Vue 3 + Vuetify 3 + TypeScript): - 13 views, Pinia stores, Axios API services with JWT interceptors - Dashboard, accounts, transactions, categories, imports, and more Deployment: - Docker Compose (PostgreSQL 17 + .NET API + nginx frontend) - Auto-migration on startup Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
using FluentAssertions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Purrse.Api.Services;
|
||||
using Purrse.Core.Enums;
|
||||
using Purrse.Core.Helpers;
|
||||
using Purrse.Core.Models;
|
||||
using Purrse.Data;
|
||||
|
||||
namespace Purrse.Tests.Services;
|
||||
|
||||
public class DuplicateDetectionServiceTests
|
||||
{
|
||||
private PurrseDbContext CreateContext()
|
||||
{
|
||||
var options = new DbContextOptionsBuilder<PurrseDbContext>()
|
||||
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
||||
.Options;
|
||||
return new PurrseDbContext(options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CalculateConfidence_ExactMatch_ReturnsHighScore()
|
||||
{
|
||||
using var db = CreateContext();
|
||||
var service = new DuplicateDetectionService(db);
|
||||
|
||||
var existing = new Transaction
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Amount = -42.50m,
|
||||
Date = new DateTime(2024, 1, 15),
|
||||
PayeeName = "WALMART STORE #1234",
|
||||
CheckNumber = "1001"
|
||||
};
|
||||
|
||||
var score = service.CalculateConfidence(existing, new DateTime(2024, 1, 15), -42.50m, "WALMART STORE #1234", null, "1001");
|
||||
|
||||
score.Should().BeGreaterOrEqualTo(0.85, "exact match on amount + date + payee + check# should auto-match");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CalculateConfidence_DifferentAmount_ReturnsLowScore()
|
||||
{
|
||||
using var db = CreateContext();
|
||||
var service = new DuplicateDetectionService(db);
|
||||
|
||||
var existing = new Transaction
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Amount = -42.50m,
|
||||
Date = new DateTime(2024, 1, 15),
|
||||
PayeeName = "WALMART"
|
||||
};
|
||||
|
||||
var score = service.CalculateConfidence(existing, new DateTime(2024, 1, 15), -100.00m, "TARGET", null, null);
|
||||
|
||||
score.Should().BeLessThan(0.50, "different amount and payee should not match");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CalculateConfidence_SameAmountDifferentDay_ReturnsMediumScore()
|
||||
{
|
||||
using var db = CreateContext();
|
||||
var service = new DuplicateDetectionService(db);
|
||||
|
||||
var existing = new Transaction
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Amount = -42.50m,
|
||||
Date = new DateTime(2024, 1, 15),
|
||||
PayeeName = "WALMART"
|
||||
};
|
||||
|
||||
var score = service.CalculateConfidence(existing, new DateTime(2024, 1, 16), -42.50m, "WALMART", null, null);
|
||||
|
||||
// Amount match (0.40) + 1-day date (0.20) + payee match (0.20) = 0.80
|
||||
score.Should().BeGreaterOrEqualTo(0.50);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FindDuplicateAsync_ExactFingerprint_ReturnsMatch()
|
||||
{
|
||||
using var db = CreateContext();
|
||||
var accountId = Guid.NewGuid();
|
||||
var date = new DateTime(2024, 1, 15);
|
||||
var amount = -42.50m;
|
||||
var fitId = "FIT123";
|
||||
|
||||
var fingerprint = TransactionFingerprint.Generate(accountId, date, amount, fitId);
|
||||
|
||||
db.Transactions.Add(new Transaction
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
AccountId = accountId,
|
||||
Date = date,
|
||||
Amount = amount,
|
||||
FitId = fitId,
|
||||
Fingerprint = fingerprint
|
||||
});
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
var service = new DuplicateDetectionService(db);
|
||||
var match = await service.FindDuplicateAsync(accountId, date, amount, null, fitId, null);
|
||||
|
||||
match.Should().NotBeNull();
|
||||
match!.Confidence.Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FindDuplicateAsync_NoMatch_ReturnsNull()
|
||||
{
|
||||
using var db = CreateContext();
|
||||
var service = new DuplicateDetectionService(db);
|
||||
|
||||
var match = await service.FindDuplicateAsync(Guid.NewGuid(), DateTime.Now, -10m, "TEST", null, null);
|
||||
match.Should().BeNull();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user