Files
edr-platform/apps/edr-freight-api/src/contracts/contract-renderer.service.spec.ts

83 lines
2.8 KiB
TypeScript

import { ContractRendererService } from './contract-renderer.service';
import { getTemplateMeta } from './contract-template.registry';
import type { ContractViewModel } from './contract-view-model.builder';
describe('ContractRendererService', () => {
const renderer = new ContractRendererService();
renderer.onModuleInit();
function minimalView(templateKey: string): ContractViewModel {
const template = getTemplateMeta(templateKey);
return {
bookingId: 'test-id',
reference: 'BK-TEST-001',
status: 'CONTRACT_READY',
templateKey,
template,
contractDate: '1 January 2026',
contractYear: 2026,
client: {
companyName: 'Test Co',
companyAddress: 'Addis Ababa',
companyLocation: 'Ethiopia',
phone: '+251900000000',
email: 'test@example.com',
tinNumber: '1234567890',
vatNumber: 'VAT-001',
fanNumber: 'FAN-001',
businessLicense: 'BL-001',
},
provider: {
name: 'Ethio-Djibouti Standard Gauge Railway Share Company',
address: 'Addis Ababa, Ethiopia',
phone: '+251 11 872 0000',
email: 'info@edr.gov.et',
tinNumber: '—',
},
schedule: {
originLabel: 'SGTD',
destinationLabel: 'Modjo',
tradeDirection: 'IMPORT',
freightType: 'CONTAINER',
serviceType: 'Rail transport',
scheduledDate: '1 January 2026',
contractType: 'NEW',
cargoDescription: 'Container cargo',
totalWeightVgm: '24 tons',
equipmentReturn: 'RETURN',
hazardousLabel: 'No',
firstMilePickupAddress: '—',
lastMileDeliveryAddress: '—',
},
pricing: {
lineItems: [{ label: 'RAIL', description: 'Rail transport', amount: 1000, currency: 'ETB' }],
surcharges: [],
totalAmount: 1000,
currency: 'ETB',
originLabel: 'SGTD',
destinationLabel: 'Modjo',
containerLines: [{ label: '40ft', quantity: 2, vgmPerUnitTons: 12 }],
},
signatures: [],
canSignCustomer: true,
canSignStaff: false,
hasContractDocument: false,
hasCustomerSignature: false,
hasStaffSignature: false,
};
}
it('renders import flagship with Nagad and Article 5', () => {
const html = renderer.render(minimalView('IMP_CON_ETB_TRANSPORT_ONLY'));
expect(html).toContain('Djibouti Nagad');
expect(html).toContain('Article 5: Contract Price');
expect(html).toContain('Article 2: Obligations of the Client');
});
it('renders export variant without import empty-return clause', () => {
const html = renderer.render(minimalView('EXP_CON_USD_TRANSPORT_ONLY'));
expect(html).toContain('export corridors');
expect(html).not.toContain('Return empty containers from Dire Dawa');
});
});