PPPAIMT-Crest/backend/test/agreementHtml.test.js

107 lines
4.7 KiB
JavaScript

import { describe, expect, it } from 'vitest';
import { agreementHtml, signedAtLabel } from '../src/pdf/agreementHtml.js';
const application = {
status: 'DRAFT',
agreement_date: '2026-09-30',
full_name: 'Asha <Rao>',
age: 42,
address: '12 Camp Road',
registration_no: 'MMC-999',
medical_council: 'Goa',
pan: 'ABCDE1234F',
gstin: '27ABCDE1234F1Z5',
bank_name: 'Example Bank',
account_holder: 'Asha Holder',
account_number: '998877665544',
ifsc: 'SBIN0001234',
};
describe('agreement HTML', () => {
it('merges every field, escapes values, and watermarks a draft', () => {
const html = agreementHtml({
application,
physicianSignature: { type: 'TYPED', typedName: 'Asha <Rao>' },
draft: true,
});
expect(html).toContain('is executed on this');
expect(html).not.toContain('is is executed');
expect(html).toContain('<p class="center title"><strong>CONSULTATION AGREEMENT</strong></p>');
expect(html).toContain('<p class="center"><strong>BETWEEN</strong></p>');
expect(html).toContain('<p class="center"><strong>… PARTY OF THE FIRST PART</strong></p>');
expect(html).toContain('<p><strong>1. PURPOSE</strong></p>');
expect(html).toContain(
'<strong>WHEREAS</strong>, Chest Research And Training Private Limited',
);
expect(html).toContain('Extended-Dose Pack versus Regular Pack');
expect(html).toContain('<strong>AND WHEREAS</strong>, the said study');
expect(html).not.toContain('<strong>1.1 CREST');
expect(html).toContain('.filled { font-weight: 700; text-decoration: underline;');
expect(html).toContain('this <span class="filled">30</span> day of <span class="filled">September</span> 2026');
expect(html).toContain('<span class="filled">Asha &lt;Rao&gt;</span>');
expect(html).not.toContain('Asha <Rao>');
expect(html).toContain('aged <span class="filled">42</span> years');
expect(html).toContain('<span class="filled">12 Camp Road</span>');
expect(html).toContain('<span class="filled">MMC-999</span>');
expect(html).toContain('<span class="filled">Goa</span> Medical Council');
expect(html).toContain('<span class="filled">ABCDE1234F</span>');
expect(html).toContain('<span class="filled">27ABCDE1234F1Z5</span>');
expect(html).toContain('<span class="filled">Example Bank</span>');
expect(html).toContain('<span class="filled">Asha Holder</span>');
expect(html).toContain('<span class="filled">998877665544</span>');
expect(html).toContain('<span class="filled">SBIN0001234</span>');
expect(html).toContain('class="typed-signature filled"');
expect(html).toContain('Pending approval');
expect(html).toContain('DRAFT - NOT SIGNED');
});
it('shows the CREST signatory only after approval', () => {
const html = agreementHtml({
application: { ...application, status: 'APPROVED' },
signatory: {
name: 'Dr Sudeep Salvi',
designation: 'Medical Director',
signatureDataUrl: 'data:image/png;base64,AAAA',
},
draft: false,
});
expect(html).toContain('<span class="filled">Dr Sudeep Salvi</span>');
expect(html).toContain('<span class="filled">Medical Director</span>');
expect(html).toContain('data:image/png;base64,AAAA');
expect(html).toContain('alt="CREST signature"');
expect(html).not.toContain('alt="CREST"');
expect(html).not.toContain('Pending approval');
expect(html).not.toContain('DRAFT - NOT SIGNED');
});
it('dates the physician signature with the signing time in IST', () => {
const html = agreementHtml({
application: { ...application, status: 'APPROVED' },
signatory: { name: 'Dr Sudeep Salvi', designation: 'Medical Director' },
physicianSignature: { type: 'TYPED', typedName: 'Asha', signedAt: '2026-10-29 03:50:00' },
draft: false,
crestDate: '2026-10-30',
});
expect(html).toContain('Date: <span class="filled">29 October 2026, 09:20 AM IST</span>');
expect(html).toContain('Date: <span class="filled">30 October 2026</span>');
});
it('keeps the agreement date when there is no signing time yet', () => {
const html = agreementHtml({ application, physicianSignature: null, draft: true });
expect(html).toContain('Date: <span class="filled">30 September 2026</span>');
expect(html).not.toContain(' IST');
});
it('formats UTC database times and Dates in 12-hour India time', () => {
expect(signedAtLabel('2026-10-28 20:00:00')).toBe('29 October 2026, 01:30 AM IST');
expect(signedAtLabel('2026-10-29 09:00:00')).toBe('29 October 2026, 02:30 PM IST');
expect(signedAtLabel(new Date('2026-10-29T06:30:00Z'))).toBe('29 October 2026, 12:00 PM IST');
expect(signedAtLabel(null)).toBe('');
expect(signedAtLabel('not a date')).toBe('');
});
});