Rollback wash start when relay activation fails
This commit is contained in:
@@ -170,10 +170,15 @@ export function useWashSessionActions(options) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return await executeSelfServeCommand(resolvedLaneId, command, {
|
||||
customer_number: null,
|
||||
license_plate: null,
|
||||
}, options);
|
||||
return await executeSelfServeCommand(
|
||||
resolvedLaneId,
|
||||
command,
|
||||
{
|
||||
customer_number: null,
|
||||
license_plate: null,
|
||||
},
|
||||
options
|
||||
);
|
||||
} finally {
|
||||
loadingRef.value = false;
|
||||
}
|
||||
@@ -185,6 +190,24 @@ export function useWashSessionActions(options) {
|
||||
const openPropertyExitGate = async (laneId = null, options = {}) =>
|
||||
executePropertyGateCommand("OPEN_PROPERTY_EXIT_GATE", laneId, openingPropertyExitGate, options);
|
||||
|
||||
const rollbackStartedWash = async (laneId) => {
|
||||
const stopResponse = await executeSelfServeCommand(
|
||||
laneId,
|
||||
"STOP",
|
||||
{
|
||||
customer_number: null,
|
||||
license_plate: null,
|
||||
},
|
||||
{ suppressAlert: true }
|
||||
);
|
||||
|
||||
if (!stopResponse) {
|
||||
console.error(`Failed to roll back started wash on lane ${laneId}:`, lastCommandErrorMessage.value);
|
||||
}
|
||||
|
||||
return stopResponse;
|
||||
};
|
||||
|
||||
const onStartWash = async (laneId, licensePlate, customerNumber, targetStep = steps.WASH_IN_PROGRESS) => {
|
||||
if (isStartingWash.value) {
|
||||
return false;
|
||||
@@ -239,12 +262,14 @@ export function useWashSessionActions(options) {
|
||||
machineRelayResponse = await enableMachineRelay(laneId);
|
||||
} catch (error) {
|
||||
console.error("Error enabling machine relay after wash start:", error);
|
||||
await rollbackStartedWash(laneId);
|
||||
alertFn(extractCommandErrorMessage(error, "Kunne ikke starte maskinen. Prøv igen."));
|
||||
return false;
|
||||
}
|
||||
|
||||
const machineRelaySuccessValue = machineRelayResponse?.data?.success ?? machineRelayResponse?.success;
|
||||
if (machineRelaySuccessValue === false) {
|
||||
await rollbackStartedWash(laneId);
|
||||
alertFn(extractCommandErrorMessage(machineRelayResponse, "Kunne ikke starte maskinen. Prøv igen."));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ describe("useWashSessionActions property gate commands", () => {
|
||||
consoleErrorSpy.mockRestore();
|
||||
});
|
||||
|
||||
it("keeps the wash retryable when required post-start machine relay activation fails", async () => {
|
||||
it("rolls back the started wash when required post-start machine relay activation throws", async () => {
|
||||
const consoleErrorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
const washInProgress = ref(false);
|
||||
const washLaneId = ref(null);
|
||||
@@ -288,6 +288,72 @@ describe("useWashSessionActions property gate commands", () => {
|
||||
license_plate: "AB12345",
|
||||
defer_relay_side_effects: true,
|
||||
});
|
||||
expect(request).toHaveBeenCalledWith("/modules/self-serve/lane/command", "post", {
|
||||
lane_id: 7,
|
||||
command: "STOP",
|
||||
customer_number: null,
|
||||
license_plate: null,
|
||||
});
|
||||
|
||||
consoleErrorSpy.mockRestore();
|
||||
});
|
||||
|
||||
it("rolls back the started wash when required post-start machine relay activation is rejected", async () => {
|
||||
const consoleErrorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
const washInProgress = ref(false);
|
||||
const washLaneId = ref(null);
|
||||
const washStartTime = ref(null);
|
||||
const currentStep = ref(2);
|
||||
const saveProgress = vi.fn();
|
||||
const startElapsedTimer = vi.fn();
|
||||
const fetchWashSummary = vi.fn();
|
||||
const enableMachineRelay = vi.fn(async () => ({
|
||||
data: {
|
||||
success: false,
|
||||
data: {
|
||||
message: "Machine relay unavailable",
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
const { actions, request, alertFn } = createActions({
|
||||
washInProgress,
|
||||
washLaneId,
|
||||
washStartTime,
|
||||
currentStep,
|
||||
saveProgress,
|
||||
startElapsedTimer,
|
||||
fetchWashSummary,
|
||||
radioWashType: ref("Machine"),
|
||||
enableMachineRelay,
|
||||
isServiceAllowed: vi.fn(() => true),
|
||||
});
|
||||
|
||||
const result = await actions.onStartWash(7, "ab12345", 12345679, 4);
|
||||
|
||||
expect(result).toBe(false);
|
||||
expect(washInProgress.value).toBe(false);
|
||||
expect(washLaneId.value).toBeNull();
|
||||
expect(washStartTime.value).toBeNull();
|
||||
expect(currentStep.value).toBe(2);
|
||||
expect(saveProgress).not.toHaveBeenCalled();
|
||||
expect(startElapsedTimer).not.toHaveBeenCalled();
|
||||
expect(fetchWashSummary).not.toHaveBeenCalled();
|
||||
expect(enableMachineRelay).toHaveBeenCalledWith(7);
|
||||
expect(alertFn).toHaveBeenCalledWith("Machine relay unavailable");
|
||||
expect(request).toHaveBeenCalledWith("/modules/self-serve/lane/command", "post", {
|
||||
lane_id: 7,
|
||||
command: "START",
|
||||
customer_number: 12345679,
|
||||
license_plate: "AB12345",
|
||||
defer_relay_side_effects: true,
|
||||
});
|
||||
expect(request).toHaveBeenCalledWith("/modules/self-serve/lane/command", "post", {
|
||||
lane_id: 7,
|
||||
command: "STOP",
|
||||
customer_number: null,
|
||||
license_plate: null,
|
||||
});
|
||||
|
||||
consoleErrorSpy.mockRestore();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user