From b0f561a935ca179cc6c996d483c536012a9d3de7 Mon Sep 17 00:00:00 2001 From: Marshal Date: Wed, 22 Jul 2026 21:02:17 +0000 Subject: [PATCH] Add end-to-end tests for import corridor flows - 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. --- .../src/seed/freight-permissions.registry.ts | 8 - apps/edr-freight-web/backoffice/src/App.tsx | 9 +- .../contracts/ContractApprovalStepsCard.tsx | 35 +- .../src/lib/canApproveContractStep.test.ts | 58 ++ .../backoffice/src/lib/permissions.ts | 53 +- e2e/freight/cypress.config.ts | 46 ++ e2e/freight/cypress/e2e/flows/import-utils.ts | 778 ++++++++++++++++++ .../e2e/flows/import_critical_matrix.cy.ts | 299 +++++++ .../cypress/e2e/flows/import_full_train.cy.ts | 332 ++++++++ .../e2e/flows/import_split_promote.cy.ts | 224 +++++ .../e2e/flows/import_waiting_expiry.cy.ts | 143 ++++ .../e2e/flows/import_window_reopen.cy.ts | 126 +++ .../cypress/fixtures/seed-import-corridor.sql | 152 ++++ 13 files changed, 2231 insertions(+), 32 deletions(-) create mode 100644 apps/edr-freight-web/backoffice/src/lib/canApproveContractStep.test.ts create mode 100644 e2e/freight/cypress/e2e/flows/import-utils.ts create mode 100644 e2e/freight/cypress/e2e/flows/import_critical_matrix.cy.ts create mode 100644 e2e/freight/cypress/e2e/flows/import_full_train.cy.ts create mode 100644 e2e/freight/cypress/e2e/flows/import_split_promote.cy.ts create mode 100644 e2e/freight/cypress/e2e/flows/import_waiting_expiry.cy.ts create mode 100644 e2e/freight/cypress/e2e/flows/import_window_reopen.cy.ts create mode 100644 e2e/freight/cypress/fixtures/seed-import-corridor.sql diff --git a/apps/edr-freight-api/src/seed/freight-permissions.registry.ts b/apps/edr-freight-api/src/seed/freight-permissions.registry.ts index 1f82f6e93..d8fedcd6e 100644 --- a/apps/edr-freight-api/src/seed/freight-permissions.registry.ts +++ b/apps/edr-freight-api/src/seed/freight-permissions.registry.ts @@ -302,8 +302,6 @@ export const SCHEDULING_EXTRA_PERMISSIONS: FreightPermissionSeed[] = [ // L. Administration & settings (split from the coarse admin umbrella) export const CONFIG_SETTINGS_PERMISSIONS: FreightPermissionSeed[] = [ - perm('b3a00001-0001-4000-8000-000000000001', 'edr_freight_app:config:contract_validity:view', 'View contract validity periods'), - perm('b3a00001-0001-4000-8000-000000000002', 'edr_freight_app:config:contract_validity:manage', 'Manage contract validity periods'), perm('b4a00001-0001-4000-8000-000000000001', 'edr_freight_app:settings:file_upload:view', 'View file-upload settings'), perm('b4a00001-0001-4000-8000-000000000002', 'edr_freight_app:settings:file_upload:manage', 'Manage file-upload settings'), perm('b4b00001-0001-4000-8000-000000000001', 'edr_freight_app:settings:dropdown:view', 'View dropdown settings'), @@ -594,12 +592,6 @@ export const FREIGHT_PERMS = { cancel: 'edr_freight_app:warehouse_fee_invoices:cancel', pay: 'edr_freight_app:warehouse_fee_invoices:pay', }, - config: { - contractValidity: { - view: 'edr_freight_app:config:contract_validity:view', - manage: 'edr_freight_app:config:contract_validity:manage', - }, - }, settings: { fileUpload: { view: 'edr_freight_app:settings:file_upload:view', diff --git a/apps/edr-freight-web/backoffice/src/App.tsx b/apps/edr-freight-web/backoffice/src/App.tsx index d216447f3..77ff95c2d 100644 --- a/apps/edr-freight-web/backoffice/src/App.tsx +++ b/apps/edr-freight-web/backoffice/src/App.tsx @@ -548,11 +548,6 @@ const buildSidebarSections = (demoItems: SidebarItem[]): SidebarSection[] => [ icon: , children: [ ...getCategorySidebarChildren("configuration"), - { - label: "Contract validity", - href: "/dashboard/configuration/contract-validity-periods", - permission: FREIGHT_PERMS.config.contractValidity.view, - }, { label: "Train scheduling rules", href: "/dashboard/configuration/train-scheduling-rules", @@ -1463,14 +1458,14 @@ const App = () => { } /> - } - /> + /> */} } /> ; @@ -29,6 +31,7 @@ export function ContractApprovalStepsCard({ contract, mutations, }: ContractApprovalStepsCardProps) { + const { user } = useAuth(); const [confirmOpen, setConfirmOpen] = useState(false); const [pendingStep, setPendingStep] = useState(null); @@ -166,6 +169,10 @@ export function ContractApprovalStepsCard({ key={step.id} step={step} isNext={actionable && nextPending?.id === step.id} + // Buttons show only to the step's actual approver (matching + // position type): a chief step never offers Approve/Reject to a + // marketing officer. Everyone still sees the "next" highlight. + canAct={canApproveContractStep(user, step.requiredRole)} isPending={ mutations.approveStep.isPending || mutations.rejectStep.isPending @@ -306,12 +313,14 @@ export function ContractApprovalStepsCard({ function StepRow({ step, isNext, + canAct, isPending, onApprove, onReject, }: { step: Freight.IContractApprovalStep; isNext: boolean; + canAct: boolean; isPending: boolean; onApprove: () => void; onReject: () => void; @@ -372,8 +381,11 @@ function StepRow({ )} - - {isNext && step.status === "PENDING" && ( + {/* One element type per row: action buttons on the active step (they + already imply "pending & actionable"), a status badge otherwise. + Mixing compact buttons + a badge here made them read as misaligned. */} + + {isNext && canAct && step.status === "PENDING" ? ( <>