mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 00:52:50 +00:00
add custom contrat templates
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import {
|
||||
CONTRACT_TEMPLATE_CODES,
|
||||
contractTemplateCodeFor,
|
||||
} from './entities/contract-template.entity';
|
||||
import { CONTRACT_TEMPLATE_DEFAULTS } from '../../seed/data/contract-template-defaults';
|
||||
|
||||
describe('contractTemplateCodeFor', () => {
|
||||
it('splits import and export by the customs flag', () => {
|
||||
expect(contractTemplateCodeFor('IMPORT', 'BULK', true)).toBe('IMPORT_BULK_CUSTOMS');
|
||||
expect(contractTemplateCodeFor('IMPORT', 'BULK', false)).toBe('IMPORT_BULK_NO_CUSTOMS');
|
||||
expect(contractTemplateCodeFor('EXPORT', 'CONTAINER', true)).toBe(
|
||||
'EXPORT_CONTAINER_CUSTOMS',
|
||||
);
|
||||
expect(contractTemplateCodeFor('EXPORT', 'CONTAINER', false)).toBe(
|
||||
'EXPORT_CONTAINER_NO_CUSTOMS',
|
||||
);
|
||||
});
|
||||
|
||||
it('never gives intercity a customs variant — it crosses no border', () => {
|
||||
for (const flag of [true, false, null, undefined]) {
|
||||
expect(contractTemplateCodeFor('DOMESTIC', 'BULK', flag)).toBe('INTERCITY_BULK');
|
||||
expect(contractTemplateCodeFor('DOMESTIC', 'CONTAINER', flag)).toBe(
|
||||
'INTERCITY_CONTAINER',
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it('treats a missing customs flag as no customs on cross-border contracts', () => {
|
||||
expect(contractTemplateCodeFor('IMPORT', 'CONTAINER', null)).toBe(
|
||||
'IMPORT_CONTAINER_NO_CUSTOMS',
|
||||
);
|
||||
expect(contractTemplateCodeFor('IMPORT', 'CONTAINER', undefined)).toBe(
|
||||
'IMPORT_CONTAINER_NO_CUSTOMS',
|
||||
);
|
||||
});
|
||||
|
||||
it('only ever resolves to a code that exists', () => {
|
||||
const directions = ['IMPORT', 'EXPORT', 'DOMESTIC', null];
|
||||
const freights = ['BULK', 'CONTAINER', 'BREAK_BULK', null];
|
||||
for (const d of directions) {
|
||||
for (const f of freights) {
|
||||
for (const c of [true, false]) {
|
||||
expect(CONTRACT_TEMPLATE_CODES).toContain(contractTemplateCodeFor(d, f, c));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('CONTRACT_TEMPLATE_DEFAULTS', () => {
|
||||
it('seeds exactly the ten declared codes, once each', () => {
|
||||
const seeded = CONTRACT_TEMPLATE_DEFAULTS.map((t) => t.code).sort();
|
||||
expect(seeded).toHaveLength(10);
|
||||
expect(seeded).toEqual([...CONTRACT_TEMPLATE_CODES].sort());
|
||||
});
|
||||
|
||||
it('gives every _CUSTOMS template the customs articles and no other one', () => {
|
||||
for (const seed of CONTRACT_TEMPLATE_DEFAULTS) {
|
||||
const hasCustomsArticle = seed.articles.some((a) => a.id === 'customs-clearing');
|
||||
// Note "_NO_CUSTOMS" also ends with "_CUSTOMS" — exclude it explicitly.
|
||||
const isCustomsVariant =
|
||||
seed.code.endsWith('_CUSTOMS') && !seed.code.endsWith('_NO_CUSTOMS');
|
||||
expect(hasCustomsArticle).toBe(isCustomsVariant);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user