Files
pleno-vue/tests/unit/self-serve-tasks-payload-contract.spec.js
T

42 lines
2.1 KiB
JavaScript

import { readFileSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
const readSource = (relativePath) => readFileSync(join(process.cwd(), relativePath), "utf8");
describe("self-serve tasks payload contract", () => {
it("maps task form condition gating to gate_type, gate_ref_id and condition_id", () => {
const formSource = readSource("src/components/session/token/SessionUser/Objects/selfServeObjectForms.js");
expect(formSource).toContain(
'const selectedConditionId = parseNullablePositiveInt(getFieldValue("condition_id"));'
);
expect(formSource).toContain("condition_id: selectedConditionId");
expect(formSource).toContain('gate_type: selectedConditionId ? "CONDITION" : "ALWAYS"');
expect(formSource).toContain("gate_ref_id: selectedConditionId");
});
it("normalizes task payloads with explicit gate and nullable fields", () => {
const tasksSource = readSource("src/components/session/token/SessionUser/Objects/SelfServeTasks.vue");
expect(tasksSource).toContain("const normalizePayload = (payload = {}) => {");
expect(tasksSource).toContain("normalizeSelfServeTaskButtons(payload.buttons)");
expect(tasksSource).toContain("condition_id: normalizedGateRefId");
expect(tasksSource).toContain("gate_type: normalizedGateType");
expect(tasksSource).toContain("gate_ref_id: normalizedGateRefId");
expect(tasksSource).toContain(
"dynamic_images_vehicle_type: parseNullablePositiveInt(payload.dynamic_images_vehicle_type)"
);
});
it("maps reset/start task buttons through shared checkboxes", () => {
const formSource = readSource("src/components/session/token/SessionUser/Objects/selfServeObjectForms.js");
const helperSource = readSource("src/components/session/token/SessionUser/Objects/selfServeTaskButtons.js");
expect(formSource).toContain("SELF_SERVE_TASK_BUTTON_OPTIONS");
expect(formSource).toContain('normalizeSelfServeTaskButtons(getCheckedValues("buttons"))');
expect(helperSource).toContain('SELF_SERVE_TASK_BUTTON_RESET = "reset"');
expect(helperSource).toContain('SELF_SERVE_TASK_BUTTON_START = "start"');
});
});