mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 03:10:54 +00:00
- Implement full train import journey with six container bookings filling a 54-wagon train. - Create tests for split offer and rebooking scenarios, handling payment expiry and waiting list promotions. - Add tests for handling waiting bookings expiration when the train is full. - Implement tests for reopening booking windows after expired reservations. - Seed database with necessary corridor data for import flows, including yards, container types, locomotives, and rates.
59 lines
2.1 KiB
TypeScript
59 lines
2.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import type { AuthUser } from "@/auth/types";
|
|
import { canApproveContractStep } from "./permissions";
|
|
|
|
const withPositionType = (typeKey: string): AuthUser => ({
|
|
employee: [{ positions: [{ positionType: { key: typeKey } }] }],
|
|
});
|
|
|
|
const withRole = (roleKey: string): AuthUser => ({ roles: [{ key: roleKey }] });
|
|
|
|
const withPermission = (permKey: string): AuthUser => ({
|
|
permissionKeys: [permKey],
|
|
});
|
|
|
|
describe("canApproveContractStep", () => {
|
|
it("shows to the matching position type only", () => {
|
|
const chief = withPositionType("-marketing-chief");
|
|
expect(canApproveContractStep(chief, "-marketing-chief")).toBe(true);
|
|
// a marketing officer must NOT see the chief step's buttons
|
|
expect(canApproveContractStep(chief, "-marketing-director-")).toBe(false);
|
|
});
|
|
|
|
it("lets super/org admins action any step", () => {
|
|
expect(canApproveContractStep(withRole("super_admin"), "anything")).toBe(
|
|
true,
|
|
);
|
|
expect(
|
|
canApproveContractStep(withRole("organization_admin"), "-marketing-chief"),
|
|
).toBe(true);
|
|
});
|
|
|
|
it("resolves legacy chain roles via their position-type aliases", () => {
|
|
const director = withPositionType("operation-director");
|
|
expect(canApproveContractStep(director, "DIRECTOR")).toBe(true);
|
|
expect(canApproveContractStep(director, "CEO")).toBe(false);
|
|
});
|
|
|
|
it("honours the role's own legacy approve permission", () => {
|
|
const staff = withPermission(
|
|
"edr_freight_app:contracts:approve_director",
|
|
);
|
|
expect(canApproveContractStep(staff, "DIRECTOR")).toBe(true);
|
|
});
|
|
|
|
it("does NOT show to holders of an unrelated approve permission", () => {
|
|
// the dropped blanket fallback: a line-staff approver is not a chief
|
|
const lineStaff = withPermission(
|
|
"edr_freight_app:contracts:approve_line_staff",
|
|
);
|
|
expect(canApproveContractStep(lineStaff, "-marketing-chief")).toBe(false);
|
|
});
|
|
|
|
it("returns false without a user or role", () => {
|
|
expect(canApproveContractStep(null, "-marketing-chief")).toBe(false);
|
|
expect(canApproveContractStep(withPositionType("x"), null)).toBe(false);
|
|
});
|
|
});
|