Files
pleno-vue/tests/unit/origin-migration.spec.js
T
Jeppe Bundgaard 0f37b0632a Add POS order booking modal and utilities with tests:
- Introduced `PosDesktopOrderBookingSelectorModal.vue` to streamline booking selection for desktop POS.
- Added `orderBookingDisplay.js` utility for handling booking display and reference value normalization.
- Created unit test `select-vehicle-form-pos.spec.js` to validate booking selection flow and registration matching.
- Implemented `run-playwright-ci-parallel.mjs` script to optimize Playwright CI with parallel testing.
- Updated styles and responsiveness for enhanced booking modal UX.
2026-04-13 21:12:34 +02:00

110 lines
3.0 KiB
JavaScript

import { afterEach, describe, expect, it, vi } from "vitest";
import {
OUTDATED_GATEWAY_ROUTE_NAME,
OUTDATED_INSTALLATION_ROUTE_NAME,
buildMigrationUrl,
resolveOriginMigrationRoute,
sanitizeRedirectPath,
startRedirectCountdown,
} from "@/middleware/originMigration";
describe("origin migration route guard", () => {
const allowedOrigins = ["https://truckwash.io", "https://www.truckwash.io"];
const route = { name: "landing", fullPath: "/user/bookings?tab=open#latest" };
it("allows navigation on allowed origins", () => {
const target = resolveOriginMigrationRoute({
to: route,
currentOrigin: "https://truckwash.io",
allowedOrigins,
standalone: false,
});
expect(target).toBeNull();
});
it("allows loopback origins on arbitrary ports", () => {
const target = resolveOriginMigrationRoute({
to: route,
currentOrigin: "http://localhost:5191",
allowedOrigins,
standalone: false,
});
expect(target).toBeNull();
});
it("routes to outdated installation for disallowed standalone context", () => {
const target = resolveOriginMigrationRoute({
to: route,
currentOrigin: "https://legacy.truckwash.io",
allowedOrigins,
standalone: true,
});
expect(target).toEqual({ name: OUTDATED_INSTALLATION_ROUTE_NAME });
});
it("routes to outdated gateway for disallowed browser context", () => {
const target = resolveOriginMigrationRoute({
to: route,
currentOrigin: "https://legacy.truckwash.io",
allowedOrigins,
standalone: false,
});
expect(target).toEqual({
name: OUTDATED_GATEWAY_ROUTE_NAME,
query: { redirect: "/user/bookings?tab=open#latest" },
});
});
it("bypasses the gate on dedicated outdated routes", () => {
const target = resolveOriginMigrationRoute({
to: { name: OUTDATED_GATEWAY_ROUTE_NAME, fullPath: "/outdated-gateway" },
currentOrigin: "https://legacy.truckwash.io",
allowedOrigins,
standalone: false,
});
expect(target).toBeNull();
});
});
describe("origin migration redirect url", () => {
it("preserves path, query, and hash on migration origin", () => {
const redirectUrl = buildMigrationUrl("https://truckwash.io", "/user/bookings?tab=open#latest");
expect(redirectUrl).toBe("https://truckwash.io/user/bookings?tab=open#latest");
});
it("sanitizes invalid redirect paths to root", () => {
expect(sanitizeRedirectPath("https://malicious.example")).toBe("/");
});
});
describe("gateway redirect countdown", () => {
afterEach(() => {
vi.useRealTimers();
});
it("ticks every second and redirects after five seconds", () => {
vi.useFakeTimers();
const onRedirect = vi.fn();
const tickValues = [];
const stop = startRedirectCountdown({
seconds: 5,
onTick: (seconds) => tickValues.push(seconds),
onRedirect,
});
vi.advanceTimersByTime(5000);
expect(tickValues).toEqual([4, 3, 2, 1, 0]);
expect(onRedirect).toHaveBeenCalledTimes(1);
stop();
});
});