updates on the changes
This commit is contained in:
@@ -428,6 +428,75 @@ describe('deliveries data layer', () => {
|
||||
endpoints.cancelBooking.mockRejectedValue({ message: 'already cancelled', httpStatus: 409 });
|
||||
await expect(cancelDeliveryAPI({ orderheaderid: 4021 }, 'x')).rejects.toMatchObject({ httpStatus: 409 });
|
||||
});
|
||||
|
||||
describe('a row that has already converted to a consignment', () => {
|
||||
const converted = { bookingid: 41, deliveryid: 41, orderheaderid: 41, consignmentid: 61 };
|
||||
|
||||
it('should cancel on the consignment, where the lifecycle now lives', async () => {
|
||||
// A booking freezes the moment the parcel is picked up; the booking-level
|
||||
// cancel route is refused for it.
|
||||
endpoints.updateConsignmentStatus.mockResolvedValue({ success: true });
|
||||
|
||||
await cancelDeliveryAPI(converted, 'customer unreachable');
|
||||
|
||||
expect(endpoints.updateConsignmentStatus).toHaveBeenCalledWith(61, { status: 'Cancelled' });
|
||||
});
|
||||
|
||||
it('should NOT also call the booking cancel route', async () => {
|
||||
endpoints.updateConsignmentStatus.mockResolvedValue({ success: true });
|
||||
await cancelDeliveryAPI(converted, 'x');
|
||||
expect(endpoints.cancelBooking).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should surface the consignment failure instead of retrying on the booking', async () => {
|
||||
// The reported bug: PUT /admin/consignments/61/status returned 500, the
|
||||
// code silently fell back to POST /admin/bookings/41/cancel, and the
|
||||
// operator was shown that route's 400 — an error about the wrong
|
||||
// endpoint entirely, which is why the real fault was invisible.
|
||||
endpoints.updateConsignmentStatus.mockRejectedValue({
|
||||
message: 'failed to update consignment status',
|
||||
httpStatus: 500
|
||||
});
|
||||
endpoints.cancelBooking.mockRejectedValue({ message: 'booking cannot be cancelled', httpStatus: 400 });
|
||||
|
||||
await expect(cancelDeliveryAPI(converted, 'x')).rejects.toMatchObject({
|
||||
message: 'failed to update consignment status',
|
||||
httpStatus: 500
|
||||
});
|
||||
expect(endpoints.cancelBooking).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should surface a refusal envelope from the consignment route unchanged', async () => {
|
||||
endpoints.updateConsignmentStatus.mockResolvedValue({ success: false, message: 'already delivered' });
|
||||
|
||||
await expect(cancelDeliveryAPI(converted, 'x')).resolves.toEqual({
|
||||
success: false,
|
||||
message: 'already delivered'
|
||||
});
|
||||
expect(endpoints.cancelBooking).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should never cancel a booking whose consignment is still live', async () => {
|
||||
// The integrity hazard behind the removed fallback: a cancelled booking
|
||||
// sitting against a consignment that is still out for delivery.
|
||||
endpoints.updateConsignmentStatus.mockRejectedValue({ httpStatus: 500, message: 'boom' });
|
||||
await cancelDeliveryAPI(converted, 'x').catch(() => {});
|
||||
expect(endpoints.cancelBooking).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('should still use the booking route for a row that has not converted', async () => {
|
||||
endpoints.cancelBooking.mockResolvedValue({ success: true });
|
||||
await cancelDeliveryAPI({ bookingid: 41, consignmentid: null }, 'duplicate');
|
||||
expect(endpoints.cancelBooking).toHaveBeenCalledWith(41, { reason: 'duplicate' });
|
||||
expect(endpoints.updateConsignmentStatus).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should refuse a row carrying neither id rather than calling an endpoint with undefined', async () => {
|
||||
await expect(cancelDeliveryAPI({}, 'x')).rejects.toThrow(/nothing to cancel/i);
|
||||
expect(endpoints.cancelBooking).not.toHaveBeenCalled();
|
||||
expect(endpoints.updateConsignmentStatus).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('changeRiderAPI', () => {
|
||||
|
||||
Reference in New Issue
Block a user