PSA/packages/billing/tests/quote/quoteEmailTemplates.test.ts
Hermes 284313f908
Some checks are pending
Bidi Control Character Guard / bidi-control-guard (push) Waiting to run
Circular Dependency Check / Check for new circular dependencies (push) Waiting to run
Citus Migration Smoke / Combined migrations on single-node Citus (push) Waiting to run
E2E Fresh Install Tests / fresh-install-e2e (push) Waiting to run
ext-v2 guardrails / Run ext-v2 guard and ESLint (push) Waiting to run
Integration Tests / Check for relevant changes (push) Waiting to run
Integration Tests / ${{ (github.event_name == 'schedule' || github.event.inputs.suite == 'full') && 'Full integration suite' || 'Tier-1 integration subset' }} (push) Blocked by required conditions
Mobile checks / Mobile lint + typecheck (push) Waiting to run
Mobile checks / Mobile unit tests (push) Waiting to run
Mobile checks / Mobile dependency audit (report) (push) Waiting to run
Mobile checks / Mobile reproducibility checks (push) Waiting to run
Secrets guard (env backups) / Ensure no tracked env backup files (push) Waiting to run
Temporal Readiness / fast-readiness (push) Waiting to run
Temporal Readiness / docker-parity (push) Waiting to run
TypeScript Type Check / Nx affected typecheck (push) Waiting to run
Unit Tests / Skipped-test budget (push) Waiting to run
Unit Tests / Nx affected unit tests (push) Waiting to run
Unit Tests / Server unit coverage (informational) (push) Waiting to run
Validate Tenant Management Schema / Check for relevant changes (push) Waiting to run
Validate Tenant Management Schema / Validate Tenant Management Schema (push) Blocked by required conditions
EE Workflows Build Guard / ee-workflows-build-guard (push) Waiting to run
Initial import of AlgaPSA codebase from PSA server
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz

Source: /opt/alga-psa on psa.joliet.tech
2026-06-22 16:12:17 -05:00

164 lines
5.6 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest';
import type { IQuote } from '@alga-psa/types';
vi.mock('@alga-psa/core/lib/formatters', () => ({
formatCurrency: (value: number, locale: string, currency: string) =>
new Intl.NumberFormat(locale || 'en-US', { style: 'currency', currency: currency || 'USD' }).format(value),
}));
import {
buildQuoteSentEmailTemplate,
buildQuoteReminderEmailTemplate,
buildQuoteAcceptedConfirmationEmailTemplate,
} from '../../src/lib/quote-email-templates';
const baseQuote: IQuote = {
tenant: 'tenant-1',
quote_id: 'q-001',
quote_number: 'Q-0042',
client_id: 'c-1',
title: 'Test Quote',
quote_date: '2026-03-01T00:00:00.000Z',
valid_until: '2026-03-31T12:00:00.000Z',
status: 'sent',
version: 1,
subtotal: 1000000,
discount_total: 0,
tax: 0,
total_amount: 1000000, // $10,000.00 in cents
currency_code: 'USD',
is_template: false,
};
describe('quote-email-templates', () => {
describe('buildQuoteSentEmailTemplate', () => {
it('T250: includes quote number and company name in subject', () => {
const { subject } = buildQuoteSentEmailTemplate({
quote: baseQuote,
companyName: 'Acme Corp',
});
expect(subject).toBe('Quote Q-0042 from Acme Corp');
});
it('T251: includes formatted total and valid-until date in HTML', () => {
const { html } = buildQuoteSentEmailTemplate({
quote: baseQuote,
companyName: 'Acme Corp',
});
expect(html).toContain('Q-0042');
expect(html).toContain('March 31, 2026');
});
it('T252: includes custom message when provided', () => {
const { html, text } = buildQuoteSentEmailTemplate({
quote: baseQuote,
companyName: 'Acme Corp',
customMessage: 'Looking forward to working with you!',
});
expect(html).toContain('Looking forward to working with you!');
expect(text).toContain('Looking forward to working with you!');
});
it('T253: omits custom message and portal link when not provided', () => {
const { html } = buildQuoteSentEmailTemplate({
quote: baseQuote,
companyName: 'Acme Corp',
});
expect(html).not.toContain('client portal');
expect(html).not.toContain('href=');
});
it('T254: includes portal link when provided', () => {
const { html, text } = buildQuoteSentEmailTemplate({
quote: baseQuote,
companyName: 'Acme Corp',
portalLink: 'https://portal.example.com/quotes/q-001',
});
expect(html).toContain('https://portal.example.com/quotes/q-001');
expect(text).toContain('https://portal.example.com/quotes/q-001');
});
it('T255: falls back to quote_id when quote_number is absent', () => {
const quoteNoNumber = { ...baseQuote, quote_number: undefined as any };
const { subject } = buildQuoteSentEmailTemplate({
quote: quoteNoNumber,
companyName: 'Acme Corp',
});
expect(subject).toContain('q-001');
});
it('T256: generates plain text output alongside HTML', () => {
const { text } = buildQuoteSentEmailTemplate({
quote: baseQuote,
companyName: 'Acme Corp',
});
expect(text).toContain('Hello,');
expect(text).toContain('Q-0042');
expect(text).toContain('Thank you,');
expect(text).toContain('Acme Corp');
// Plain text should NOT contain HTML tags
expect(text).not.toContain('<p>');
expect(text).not.toContain('<strong>');
});
});
describe('buildQuoteReminderEmailTemplate', () => {
it('T257: reminder subject includes quote number and expiry date', () => {
const { subject } = buildQuoteReminderEmailTemplate({
quote: baseQuote,
companyName: 'Acme Corp',
});
expect(subject).toContain('Reminder');
expect(subject).toContain('Q-0042');
expect(subject).toContain('March 31, 2026');
});
it('T258: reminder HTML mentions expiration', () => {
const { html } = buildQuoteReminderEmailTemplate({
quote: baseQuote,
companyName: 'Acme Corp',
});
expect(html).toContain('reminder');
expect(html).toContain('expires');
});
it('T259: reminder includes custom message when provided', () => {
const { html } = buildQuoteReminderEmailTemplate({
quote: baseQuote,
companyName: 'Acme Corp',
customMessage: 'Please review at your earliest convenience.',
});
expect(html).toContain('Please review at your earliest convenience.');
});
});
describe('buildQuoteAcceptedConfirmationEmailTemplate', () => {
it('T260: accepted confirmation subject includes quote number', () => {
const acceptedQuote = { ...baseQuote, status: 'accepted' as const, accepted_at: '2026-03-15T10:00:00.000Z' };
const { subject } = buildQuoteAcceptedConfirmationEmailTemplate({
quote: acceptedQuote,
companyName: 'Acme Corp',
});
expect(subject).toContain('Q-0042');
expect(subject).toContain('accepted');
});
it('T261: accepted confirmation includes accepted date', () => {
const acceptedQuote = { ...baseQuote, status: 'accepted' as const, accepted_at: '2026-03-15T10:00:00.000Z' };
const { html } = buildQuoteAcceptedConfirmationEmailTemplate({
quote: acceptedQuote,
companyName: 'Acme Corp',
});
expect(html).toContain('March 15, 2026');
});
it('T262: accepted confirmation shows N/A when accepted_at is missing', () => {
const { html } = buildQuoteAcceptedConfirmationEmailTemplate({
quote: baseQuote,
companyName: 'Acme Corp',
});
expect(html).toContain('N/A');
});
});
});