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 ', 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 ' }, draft: true, }); expect(html).toContain('is executed on this'); expect(html).not.toContain('is is executed'); expect(html).toContain('

CONSULTATION AGREEMENT

'); expect(html).toContain('

BETWEEN

'); expect(html).toContain('

… PARTY OF THE FIRST PART

'); expect(html).toContain('

1. PURPOSE

'); expect(html).toContain( 'WHEREAS, Chest Research And Training Private Limited', ); expect(html).toContain('Extended-Dose Pack versus Regular Pack'); expect(html).toContain('AND WHEREAS, the said study'); expect(html).not.toContain('1.1 CREST'); expect(html).toContain('.filled { font-weight: 700; text-decoration: underline;'); expect(html).toContain('this 30 day of September 2026'); expect(html).toContain('Asha <Rao>'); expect(html).not.toContain('Asha '); expect(html).toContain('aged 42 years'); expect(html).toContain('12 Camp Road'); expect(html).toContain('MMC-999'); expect(html).toContain('Goa Medical Council'); expect(html).toContain('ABCDE1234F'); expect(html).toContain('27ABCDE1234F1Z5'); expect(html).toContain('Example Bank'); expect(html).toContain('Asha Holder'); expect(html).toContain('998877665544'); expect(html).toContain('SBIN0001234'); 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('Dr Sudeep Salvi'); expect(html).toContain('Medical Director'); 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: 29 October 2026, 09:20 AM IST'); expect(html).toContain('Date: 30 October 2026'); }); it('keeps the agreement date when there is no signing time yet', () => { const html = agreementHtml({ application, physicianSignature: null, draft: true }); expect(html).toContain('Date: 30 September 2026'); 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(''); }); });