mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 15:48:11 +00:00
62 lines
2.1 KiB
TypeScript
62 lines
2.1 KiB
TypeScript
/**
|
|
* Shared helper for the PER_ITEM break-bulk specs (bulk_b2 / bulk_b3).
|
|
* Cargo types come from fixtures/seed-bulk-items.sql.
|
|
*/
|
|
|
|
import { apiPost, customer, db } from "./import-utils";
|
|
|
|
/** Book a PER_ITEM break-bulk line under the suffix's seeded contract. */
|
|
export function bookBulkItems(opts: {
|
|
suffix: string;
|
|
cargoCode: "E2E_IMP_AUTO" | "E2E_IMP_MACHINE";
|
|
items: number;
|
|
tons: number;
|
|
scheduledDate?: string;
|
|
hazardousQuantity?: number;
|
|
reeferQuantity?: number;
|
|
expectFailure?: string | RegExp;
|
|
}) {
|
|
db<{ id: string; cargo_type_id: string }>(
|
|
`SELECT ct.id,
|
|
(SELECT t.id FROM freight.cargo_types t WHERE t.code = $2) AS cargo_type_id
|
|
FROM freight.contracts ct
|
|
WHERE ct.reference LIKE 'CTR-IMP-%-' || $1
|
|
ORDER BY ct.created_at DESC LIMIT 1`,
|
|
[opts.suffix, opts.cargoCode],
|
|
).then(({ rows }) => {
|
|
expect(rows, `seeded contract *-${opts.suffix}`).to.have.length(1);
|
|
expect(rows[0].cargo_type_id, `${opts.cargoCode} seeded`).to.be.a("string");
|
|
apiPost(
|
|
customer,
|
|
`/api/contracts/${rows[0].id}/bookings`,
|
|
{
|
|
...(opts.scheduledDate ? { scheduledDate: opts.scheduledDate } : {}),
|
|
bulkLines: [
|
|
{
|
|
cargoTypeId: rows[0].cargo_type_id,
|
|
itemCount: opts.items,
|
|
cargoWeightTons: opts.tons,
|
|
...(opts.hazardousQuantity != null
|
|
? { hazardousQuantity: opts.hazardousQuantity }
|
|
: {}),
|
|
...(opts.reeferQuantity != null ? { reeferQuantity: opts.reeferQuantity } : {}),
|
|
},
|
|
],
|
|
cargoFreeText: `E2E break-bulk ${opts.cargoCode}`,
|
|
},
|
|
!opts.expectFailure,
|
|
).then((res) => {
|
|
if (opts.expectFailure) {
|
|
expect(res.status, `${opts.suffix} booking rejected`).to.be.within(400, 422);
|
|
if (opts.expectFailure instanceof RegExp) {
|
|
expect(JSON.stringify(res.body)).to.match(opts.expectFailure);
|
|
} else {
|
|
expect(JSON.stringify(res.body)).to.include(opts.expectFailure);
|
|
}
|
|
} else {
|
|
expect(res.status, `${opts.suffix} booking created`).to.be.oneOf([200, 201]);
|
|
}
|
|
});
|
|
});
|
|
}
|