42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
// Local smoke test for Postal client without real network
|
|
// Mocks fetch to capture the request and return success
|
|
import { sendPostalEmail } from '../postal.js'
|
|
|
|
// Minimal env to pass config checks
|
|
process.env.POSTAL_URL = 'https://postal.example.com'
|
|
process.env.POSTAL_API_KEY = 'test_api_key'
|
|
process.env.POSTAL_FROM = 'no-reply@example.com'
|
|
process.env.POSTAL_FROM_NAME = 'AGEP Cargobike'
|
|
process.env.POSTAL_REPLY_TO = 'contact@example.com'
|
|
|
|
// Mock global fetch
|
|
globalThis.fetch = async (url, init) => {
|
|
console.log('FETCH URL:', url)
|
|
const body = JSON.parse(init.body)
|
|
console.log('FETCH PAYLOAD:', body)
|
|
return {
|
|
ok: true,
|
|
status: 200,
|
|
async json() {
|
|
return { status: 'success', data: { message_id: 'fake-123' } }
|
|
},
|
|
}
|
|
}
|
|
|
|
async function main() {
|
|
const res = await sendPostalEmail({
|
|
to: ['recipient1@example.com', 'recipient2@example.com'],
|
|
subject: 'Test subject',
|
|
text: 'Plain text body',
|
|
html: '<p>HTML body</p>',
|
|
cc: 'cc1@example.com; cc2@example.com',
|
|
bcc: 'bcc@example.com',
|
|
})
|
|
console.log('Postal client returned:', res)
|
|
}
|
|
|
|
main().catch((e) => {
|
|
console.error('Test failed:', e)
|
|
process.exit(1)
|
|
})
|
|
|