mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-10-04 20:42:09 +00:00
test(uplifts): prove board-create dispatch ownership persists relationally (SH-393)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
89376e99e4
commit
ce3b241991
1 changed files with 66 additions and 0 deletions
|
|
@ -134,6 +134,72 @@ public class WorkOrderBoardCreateRelationalTests
|
||||||
Assert.Empty(await verify.Dispatches.AsNoTracking().ToListAsync());
|
Assert.Empty(await verify.Dispatches.AsNoTracking().ToListAsync());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Create_WithVendor_PersistsPrimaryDispatchOwnershipForUpliftResolution()
|
||||||
|
{
|
||||||
|
await using var connection = new SqliteConnection("Data Source=:memory:;Foreign Keys=True");
|
||||||
|
await connection.OpenAsync();
|
||||||
|
|
||||||
|
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
|
||||||
|
.UseSqlite(connection)
|
||||||
|
.Options;
|
||||||
|
|
||||||
|
await using (var context = new SqliteBoardTestDbContext(options))
|
||||||
|
{
|
||||||
|
await context.Database.EnsureCreatedAsync();
|
||||||
|
context.Users.Add(new ApplicationUser
|
||||||
|
{
|
||||||
|
Id = "actor-1",
|
||||||
|
UserName = "actor-1",
|
||||||
|
NormalizedUserName = "ACTOR-1",
|
||||||
|
Email = "actor@test.local",
|
||||||
|
NormalizedEmail = "ACTOR@TEST.LOCAL"
|
||||||
|
});
|
||||||
|
await context.SaveChangesAsync();
|
||||||
|
await WorkOrderAccountTestHelpers.EnsureAccountAsync(context);
|
||||||
|
await WorkOrderAccountTestHelpers.EnsureLocationAsync(context);
|
||||||
|
context.Vendors.Add(new Vendor { Id = 5, CompanyName = "Acme HVAC" });
|
||||||
|
await context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
WorkOrderBoardRowDto result;
|
||||||
|
await using (var context = new SqliteBoardTestDbContext(options))
|
||||||
|
{
|
||||||
|
var boardData = new WorkOrderBoardDataService(context);
|
||||||
|
var resolver = WorkOrderAccountTestHelpers.Resolver(context);
|
||||||
|
var fieldLocks = new WorkOrderFieldLockService(new WorkOrderFieldLockDataService(context));
|
||||||
|
var service = new WorkOrderBoardCreateService(
|
||||||
|
boardData,
|
||||||
|
new WorkOrderBoardMutationDataService(context),
|
||||||
|
new WorkOrderBoardService(boardData, resolver),
|
||||||
|
new WorkOrderAuditService(new WorkOrderAuditDataService(context), fieldLocks),
|
||||||
|
new WorkOrderBoardCreateValidation(),
|
||||||
|
resolver,
|
||||||
|
new WorkOrderPocDataService(context));
|
||||||
|
|
||||||
|
result = await service.CreateAsync(new WorkOrderBoardCreateRequestDto
|
||||||
|
{
|
||||||
|
WorkOrderType = WorkOrderType.PM,
|
||||||
|
SiteCode = "BK5",
|
||||||
|
LocationId = 1,
|
||||||
|
VendorId = 5
|
||||||
|
}, WorkOrderAccountTestHelpers.AccountUser(), "actor-1");
|
||||||
|
}
|
||||||
|
|
||||||
|
// SH-393: fresh context, committed state only. The primary dispatch must be owned
|
||||||
|
// by the work order so the uplift create/read scope resolves it.
|
||||||
|
await using var verify = new SqliteBoardTestDbContext(options);
|
||||||
|
var dispatch = await verify.Dispatches.AsNoTracking().SingleAsync();
|
||||||
|
Assert.Equal(result.PrimaryDispatchId, dispatch.Id);
|
||||||
|
Assert.Equal(result.Id, dispatch.WorkOrderId);
|
||||||
|
|
||||||
|
var upliftDispatch = await new UpliftDataService(verify).GetUpliftDispatchForWorkOrderAsync(
|
||||||
|
result.Id,
|
||||||
|
result.PrimaryDispatchId,
|
||||||
|
CancellationToken.None);
|
||||||
|
Assert.Equal(dispatch.Id, upliftDispatch?.Id);
|
||||||
|
}
|
||||||
|
|
||||||
private sealed class SqliteBoardTestDbContext : ApplicationDbContext
|
private sealed class SqliteBoardTestDbContext : ApplicationDbContext
|
||||||
{
|
{
|
||||||
public SqliteBoardTestDbContext(DbContextOptions<ApplicationDbContext> options)
|
public SqliteBoardTestDbContext(DbContextOptions<ApplicationDbContext> options)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue