mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 07:13:12 +00:00
Editing a work order's POC never reached the backend: no update path wrote
PocName/PocPhone/PocNotes, so the optimistic UI edit was lost on refetch and
the completion freeze captured the Site contact instead of the manual value,
and nothing was audited.
- Add tenant-scoped PATCH api/workorders/{id}/poc via new WorkOrderPocService
+ WorkOrderPocDataService: persists the override, stages FieldChanged audit
entries (which also write field locks so sync never overwrites a manual POC),
and enforces row-version concurrency and terminal-status read-only rules.
- Lock semantics (SH-190): a manual POC away from the Site's live contacts is
stored WO-level; an edit equal to a live Site contact (or blanking name+phone)
stores nothing so the WO follows the Site. PocCustomized exposes the state.
- Board projection, completion freeze and create now share one Site-contact
fallback (first non-deleted contact by SiteContactOrder) so a never-overridden
WO keeps following the Site, including at create when the wizard prefills it.
- Route contract baseline gains PATCH {id:int}/poc.
79 lines
2.8 KiB
C#
79 lines
2.8 KiB
C#
using Api.SeaHavenIndustries.Controllers;
|
|
using Data.SeaHavenIndustries;
|
|
using FluentAssertions;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Moq;
|
|
using SeaHaven.DataServices.Implementation;
|
|
using SeaHaven.DataServices.Interfaces;
|
|
using SeaHaven.Services.DTOs;
|
|
using SeaHaven.Services.Helpers;
|
|
using SeaHaven.Services.Implementation;
|
|
using SeaHaven.Services.Interfaces;
|
|
using Xunit;
|
|
|
|
namespace Api.SeaHavenIndustries.Tests;
|
|
|
|
public class WorkOrderControllerSearchTests
|
|
{
|
|
private static WorkOrderBoardController NewController(IWorkOrderAdvancedSearchService advancedSearch)
|
|
{
|
|
var controller = new WorkOrderBoardController(
|
|
Mock.Of<IWorkOrderBoardService>(),
|
|
Mock.Of<IWorkOrderBoardUpdateService>(),
|
|
Mock.Of<IWorkOrderBoardCreateService>(),
|
|
Mock.Of<IWorkOrderBoardCancelService>(),
|
|
Mock.Of<IWorkOrderPocService>(),
|
|
advancedSearch);
|
|
|
|
controller.ControllerContext = new ControllerContext
|
|
{
|
|
HttpContext = new DefaultHttpContext
|
|
{
|
|
User = new System.Security.Claims.ClaimsPrincipal(
|
|
new System.Security.Claims.ClaimsIdentity(
|
|
new[]
|
|
{
|
|
new System.Security.Claims.Claim(
|
|
System.Security.Claims.ClaimTypes.NameIdentifier,
|
|
"test-user")
|
|
},
|
|
"Test"))
|
|
}
|
|
};
|
|
|
|
return controller;
|
|
}
|
|
|
|
[Fact]
|
|
public async Task SearchBoard_WhenCustomPresetMissingDates_ReturnsBadRequest()
|
|
{
|
|
var advancedSearch = new WorkOrderAdvancedSearchService(
|
|
Mock.Of<IWorkOrderAdvancedSearchDataService>(),
|
|
Mock.Of<IWorkOrderAccountResolver>());
|
|
var controller = NewController(advancedSearch);
|
|
|
|
var result = await controller.SearchBoard(new WorkOrderAdvancedSearchQueryDto
|
|
{
|
|
DatePreset = WorkOrderAdvancedSearchDatePreset.Custom
|
|
});
|
|
|
|
var badRequest = result.Should().BeOfType<BadRequestObjectResult>().Subject;
|
|
var body = badRequest.Value.Should().BeOfType<Response>().Subject;
|
|
body.Status.Should().Be("Error");
|
|
body.Message.Should().Contain("dateFrom");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetBoard_WhenWeekEndBeforeWeekStart_ReturnsBadRequest()
|
|
{
|
|
var controller = NewController(Mock.Of<IWorkOrderAdvancedSearchService>());
|
|
|
|
var result = await controller.GetBoard(
|
|
new DateOnly(2026, 6, 22),
|
|
new DateOnly(2026, 6, 15));
|
|
|
|
var badRequest = result.Should().BeOfType<BadRequestObjectResult>().Subject;
|
|
badRequest.Value.Should().BeOfType<string>().Which.Should().Contain("weekEnd");
|
|
}
|
|
}
|