mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 15:25:45 +00:00
Import's customer_truck_assignments.arrived_at is set by a separate later gate action (release()'s arrival branch — the truck returning to collect already-warehoused goods). Export has no equivalent second step: the truck delivering cargo to the warehouse arrives and is received in the same act, so its arrival was never recorded anywhere. Add markCustomerTruckArrived, mirroring release()'s existing self-haul departure UPDATE (plate-matched, COALESCE(arrived_at, NOW())), and call it from receive()/bulkReceive() for EXPORT bookings
57 lines
2.0 KiB
TypeScript
57 lines
2.0 KiB
TypeScript
import { WarehouseInventoryService } from './warehouse-inventory.service';
|
|
|
|
/**
|
|
* Export self-haul has no separate "truck arrived" gate action the way import
|
|
* does (release()'s arrival branch, fired later when a truck shows up to
|
|
* COLLECT already-warehoused goods) — the truck delivering cargo TO the
|
|
* warehouse arrives and is received in the same act, so receive()/
|
|
* bulkReceive() must stamp customer_truck_assignments.arrived_at themselves.
|
|
*/
|
|
type Marker = (
|
|
manager: { query: jest.Mock },
|
|
bookingId: string,
|
|
plateNumber: string | null | undefined,
|
|
) => Promise<void>;
|
|
|
|
function makeMarker() {
|
|
const service = Object.create(WarehouseInventoryService.prototype) as Record<string, unknown>;
|
|
const marker = (
|
|
service as unknown as { markCustomerTruckArrived: Marker }
|
|
).markCustomerTruckArrived.bind(service);
|
|
return marker;
|
|
}
|
|
|
|
describe('markCustomerTruckArrived', () => {
|
|
it('stamps arrival matched by booking + plate', async () => {
|
|
const marker = makeMarker();
|
|
const manager = { query: jest.fn().mockResolvedValue(undefined) };
|
|
|
|
await marker(manager, 'b-1', 'AAA-2323');
|
|
|
|
expect(manager.query).toHaveBeenCalledTimes(1);
|
|
const [sql, params] = manager.query.mock.calls[0];
|
|
expect(sql).toMatch(/UPDATE freight\.customer_truck_assignments/);
|
|
expect(sql).toMatch(/UPPER\(a\.plate_number\) = UPPER\(\$2\)/);
|
|
expect(params).toEqual(['b-1', 'AAA-2323']);
|
|
});
|
|
|
|
it('trims the plate before matching', async () => {
|
|
const marker = makeMarker();
|
|
const manager = { query: jest.fn().mockResolvedValue(undefined) };
|
|
|
|
await marker(manager, 'b-1', ' AAA-2323 ');
|
|
|
|
expect(manager.query.mock.calls[0][1]).toEqual(['b-1', 'AAA-2323']);
|
|
});
|
|
|
|
it('no-ops on a missing/blank plate — no query, nothing to match on', async () => {
|
|
const marker = makeMarker();
|
|
const manager = { query: jest.fn() };
|
|
|
|
await marker(manager, 'b-1', undefined);
|
|
await marker(manager, 'b-1', ' ');
|
|
|
|
expect(manager.query).not.toHaveBeenCalled();
|
|
});
|
|
});
|