Adds supabase/functions/ (deno.json, _shared/email.ts) with pure buildBookingNotificationEmail/buildInquiryNotificationEmail functions for Task 6's Edge Functions, tested via Deno's test runner. Excludes supabase/functions/** from the root Vitest config, which otherwise tried to resolve the jsr: import and failed.
50 lines
2.1 KiB
TypeScript
50 lines
2.1 KiB
TypeScript
import { assertEquals, assertStringIncludes } from 'jsr:@std/assert'
|
|
import { buildBookingNotificationEmail, buildInquiryNotificationEmail } from './email.ts'
|
|
|
|
Deno.test('buildBookingNotificationEmail includes the service, date, time, and contact details', () => {
|
|
const { subject, html } = buildBookingNotificationEmail({
|
|
serviceName: 'Knotless Braids',
|
|
date: '2026-09-01',
|
|
time: '10:00 AM',
|
|
contact: { name: 'Jane Doe', phone: '555-0100', email: 'jane@example.com', notes: 'First time client' },
|
|
})
|
|
assertEquals(subject, 'New booking: Knotless Braids on 2026-09-01')
|
|
assertStringIncludes(html, 'Jane Doe')
|
|
assertStringIncludes(html, 'Knotless Braids')
|
|
assertStringIncludes(html, '2026-09-01')
|
|
assertStringIncludes(html, '10:00 AM')
|
|
assertStringIncludes(html, '555-0100')
|
|
assertStringIncludes(html, 'jane@example.com')
|
|
assertStringIncludes(html, 'First time client')
|
|
})
|
|
|
|
Deno.test('buildBookingNotificationEmail omits the notes paragraph when notes are empty', () => {
|
|
const { html } = buildBookingNotificationEmail({
|
|
serviceName: 'Cornrows',
|
|
date: '2026-09-02',
|
|
time: '1:00 PM',
|
|
contact: { name: 'Amy', phone: '555-0101', email: 'amy@example.com', notes: '' },
|
|
})
|
|
if (html.includes('Notes:')) throw new Error('expected no Notes: paragraph')
|
|
})
|
|
|
|
Deno.test('buildInquiryNotificationEmail includes the product and contact details', () => {
|
|
const { subject, html } = buildInquiryNotificationEmail({
|
|
productName: 'Silk Edge Control',
|
|
contact: { name: 'Nadia', email: 'nadia@example.com', notes: 'Is this in stock?' },
|
|
})
|
|
assertEquals(subject, 'New inquiry: Silk Edge Control')
|
|
assertStringIncludes(html, 'Nadia')
|
|
assertStringIncludes(html, 'nadia@example.com')
|
|
assertStringIncludes(html, 'Silk Edge Control')
|
|
assertStringIncludes(html, 'Is this in stock?')
|
|
})
|
|
|
|
Deno.test('buildInquiryNotificationEmail omits the notes paragraph when notes are empty', () => {
|
|
const { html } = buildInquiryNotificationEmail({
|
|
productName: 'Braid Oil',
|
|
contact: { name: 'Kim', email: 'kim@example.com', notes: '' },
|
|
})
|
|
if (html.includes('Notes:')) throw new Error('expected no Notes: paragraph')
|
|
})
|