mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-10-04 19:32:10 +00:00
fix(uplifts): attribute audit to requested work order
Use the operation work order when staging uplift audit logs so a dispatch linked through DispatchWorkOrders cannot write the event to its primary work order. Add coverage for the cross-work-order fallback case.
This commit is contained in:
parent
adb192cad7
commit
5c5c01b2e8
2 changed files with 32 additions and 1 deletions
|
|
@ -437,7 +437,7 @@ namespace SeaHaven.Services.Implementation
|
||||||
{
|
{
|
||||||
await _dispatchData.StageAuditLogAsync(new WorkOrderAuditLog
|
await _dispatchData.StageAuditLogAsync(new WorkOrderAuditLog
|
||||||
{
|
{
|
||||||
WorkOrderId = dispatch.WorkOrderId ?? workOrderId,
|
WorkOrderId = workOrderId,
|
||||||
UserId = userId,
|
UserId = userId,
|
||||||
FieldName = $"Dispatch {dispatch.DispatchNumber} Uplift",
|
FieldName = $"Dispatch {dispatch.DispatchNumber} Uplift",
|
||||||
OldValue = isStatusTransition ? oldValue.ToString() : $"${Convert.ToDecimal(oldValue):F2}",
|
OldValue = isStatusTransition ? oldValue.ToString() : $"${Convert.ToDecimal(oldValue):F2}",
|
||||||
|
|
|
||||||
|
|
@ -143,6 +143,37 @@ public sealed class WorkOrderUpliftServiceTests
|
||||||
Assert.Equal(1, await context.DispatchUpliftRequests.CountAsync());
|
Assert.Equal(1, await context.DispatchUpliftRequests.CountAsync());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task CreateAsync_WithoutPrimaryDispatch_AuditsRequestedWorkOrderWhenDispatchBelongsToAnother()
|
||||||
|
{
|
||||||
|
await using var context = CreateContext();
|
||||||
|
var (workOrder, dispatch) = await SeedWorkOrderAsync(context, primaryDispatchId: null);
|
||||||
|
context.workOrders.Add(new WorkOrder
|
||||||
|
{
|
||||||
|
Id = 2,
|
||||||
|
InternalWONumber = "10000000002",
|
||||||
|
AccountId = 1,
|
||||||
|
WorkOrderType = WorkOrderType.PM,
|
||||||
|
});
|
||||||
|
dispatch.WorkOrderId = 2;
|
||||||
|
context.DispatchWorkOrders.Add(new DispatchWorkOrder
|
||||||
|
{
|
||||||
|
DispatchId = dispatch.Id,
|
||||||
|
WorkOrderId = workOrder.Id,
|
||||||
|
});
|
||||||
|
await context.SaveChangesAsync();
|
||||||
|
|
||||||
|
var service = NewService(context);
|
||||||
|
await service.CreateAsync(
|
||||||
|
workOrder.Id,
|
||||||
|
new CreateWorkOrderUpliftRequestDto { Amount = 400m, Notes = "Associated dispatch" },
|
||||||
|
Dispatcher(),
|
||||||
|
CancellationToken.None);
|
||||||
|
|
||||||
|
var audit = Assert.Single(context.WorkOrderAuditLogs);
|
||||||
|
Assert.Equal(workOrder.Id, audit.WorkOrderId);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task CreateAsync_PmAmountAboveCap_CreatesPendingRequest()
|
public async Task CreateAsync_PmAmountAboveCap_CreatesPendingRequest()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue