88 lines
3.1 KiB
TypeScript
88 lines
3.1 KiB
TypeScript
/**
|
|
* Test script: sends a test confirmation email, a test booking notification,
|
|
* and writes a test entry into the room booking sheet.
|
|
*
|
|
* Usage: npx tsx --env-file=.env.local scripts/test-booking.ts
|
|
*/
|
|
|
|
import { sendPaymentConfirmation, sendBookingNotification } from "../lib/email"
|
|
import { assignBooking } from "../lib/booking-sheet"
|
|
|
|
const TEST_GUEST = "Test Guest (DELETE ME)"
|
|
const TEST_EMAILS = ["jeff@jeffemmett.com", "contact@cryptocommonsgather.ing"]
|
|
const TEST_ACCOMMODATION = "ch-multi" // Bed in shared room, Commons Hub
|
|
|
|
async function main() {
|
|
console.log("=== Test 1: Registration Confirmation Email (no accommodation) ===")
|
|
for (const email of TEST_EMAILS) {
|
|
try {
|
|
const sent = await sendPaymentConfirmation({
|
|
name: TEST_GUEST,
|
|
email,
|
|
amountPaid: "€100.00",
|
|
paymentMethod: "ideal",
|
|
contributions: "Testing the booking system",
|
|
dietary: "None",
|
|
})
|
|
console.log(sent ? `OK — confirmation sent to ${email}` : "SKIPPED — SMTP not configured")
|
|
} catch (err) {
|
|
console.error(`FAILED (${email}):`, err)
|
|
}
|
|
}
|
|
|
|
console.log("\n=== Test 2: Room Booking Sheet Assignment ===")
|
|
let bookingResult: Awaited<ReturnType<typeof assignBooking>> = { success: false }
|
|
try {
|
|
bookingResult = await assignBooking(TEST_GUEST, TEST_ACCOMMODATION)
|
|
if (bookingResult.success) {
|
|
console.log(`OK — assigned to ${bookingResult.venue} Room ${bookingResult.room} (${bookingResult.bedType})`)
|
|
console.log("*** IMPORTANT: Remove this test entry from the booking sheet! ***")
|
|
} else {
|
|
console.log(`NOT ASSIGNED: ${bookingResult.error}`)
|
|
}
|
|
} catch (err) {
|
|
console.error("FAILED:", err)
|
|
}
|
|
|
|
console.log("\n=== Test 3: Internal Booking Notification Email ===")
|
|
try {
|
|
const sent = await sendBookingNotification({
|
|
guestName: TEST_GUEST,
|
|
guestEmail: TEST_EMAILS[0],
|
|
accommodationType: TEST_ACCOMMODATION,
|
|
amountPaid: "€100.00",
|
|
bookingSuccess: bookingResult.success,
|
|
venue: bookingResult.venue,
|
|
room: bookingResult.room,
|
|
bedType: bookingResult.bedType,
|
|
error: bookingResult.success ? undefined : bookingResult.error,
|
|
})
|
|
console.log(sent ? "OK — notification email sent to contact@" : "SKIPPED — SMTP not configured")
|
|
} catch (err) {
|
|
console.error("FAILED:", err)
|
|
}
|
|
|
|
console.log("\n=== Test 4: Confirmation Email WITH Accommodation ===")
|
|
for (const email of TEST_EMAILS) {
|
|
try {
|
|
const sent = await sendPaymentConfirmation({
|
|
name: TEST_GUEST,
|
|
email,
|
|
amountPaid: "€379.30",
|
|
paymentMethod: "ideal",
|
|
contributions: "Testing the booking system",
|
|
dietary: "Vegetarian",
|
|
accommodationVenue: bookingResult.venue || "Commons Hub",
|
|
accommodationRoom: bookingResult.room || "7",
|
|
})
|
|
console.log(sent ? `OK — confirmation with accommodation sent to ${email}` : "SKIPPED — SMTP not configured")
|
|
} catch (err) {
|
|
console.error(`FAILED (${email}):`, err)
|
|
}
|
|
}
|
|
|
|
console.log("\nDone. Check inboxes and booking sheet.")
|
|
}
|
|
|
|
main().catch(console.error)
|