- Implemented tests for debugging browser cache vs server response. - Verified calendar displays correct dates for November 2025. - Added visual inspection screenshot for calendar layout. - Created tests to ensure calendar fits within its container. - Checked for correct styling of available and blocked dates. - Debugged login form behavior and cookie handling. - Added tests for forced browser refresh and cache verification. - Conducted visual tests to compare actual calendar layout with expected. - Enhanced logging for better traceability during test execution.
140 lines
4.9 KiB
JavaScript
Executable File
140 lines
4.9 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
||
import dotenv from 'dotenv'
|
||
dotenv.config()
|
||
|
||
const BASE = process.env.TEST_BASE_URL || 'http://localhost:3000'
|
||
|
||
console.log('=== Full Booking Flow Test ===\n')
|
||
|
||
// Test 1: Fetch menus from API
|
||
console.log('1️⃣ Testing GET /api/menus')
|
||
const menusRes = await fetch(`${BASE}/api/menus`)
|
||
if (!menusRes.ok) {
|
||
console.error('❌ Failed to fetch menus:', menusRes.status)
|
||
process.exit(1)
|
||
}
|
||
const menus = await menusRes.json()
|
||
console.log(`✅ Fetched ${menus.length} menus`)
|
||
if (menus.length === 0) {
|
||
console.error('❌ No menus found in database')
|
||
process.exit(1)
|
||
}
|
||
const testMenu = menus[0]
|
||
console.log(` Using test menu: "${testMenu.title}" (${testMenu.id})`)
|
||
console.log(` Base price per cover: ${testMenu.basePricePerCover} kr`)
|
||
console.log(` Ingredients count: ${testMenu.ingredients?.length || 0}\n`)
|
||
|
||
// Test 2: Fetch packages from API
|
||
console.log('2️⃣ Testing GET /api/packages')
|
||
const packagesRes = await fetch(`${BASE}/api/packages`)
|
||
if (!packagesRes.ok) {
|
||
console.error('❌ Failed to fetch packages:', packagesRes.status)
|
||
process.exit(1)
|
||
}
|
||
const packages = await packagesRes.json()
|
||
console.log(`✅ Fetched ${packages.length} packages\n`)
|
||
|
||
// Test 3: Create a booking with menu and service
|
||
console.log('3️⃣ Testing POST /api/bookings with menu')
|
||
const testDate = new Date(Date.now() + 14*24*60*60*1000)
|
||
const dateStr = testDate.toISOString().split('T')[0]
|
||
const partySize = 8
|
||
|
||
const bookingPayload = {
|
||
name: 'Test Booking',
|
||
email: 'test@warme.dk',
|
||
phone: '12345678',
|
||
address: 'Test Address 123',
|
||
party_size: partySize,
|
||
date: dateStr,
|
||
start_time: '18:00',
|
||
duration_hours: 4,
|
||
menu_id: testMenu.id,
|
||
include_service: true,
|
||
include_cleanup: true,
|
||
message: 'Full flow test booking'
|
||
}
|
||
|
||
// Calculate expected price
|
||
const expectedMenuPrice = testMenu.basePricePerCover * partySize
|
||
const expectedServicePrice = 100 * partySize
|
||
const expectedCleanupPrice = 500
|
||
const expectedReservationFee = 500
|
||
const expectedTotal = expectedMenuPrice + expectedServicePrice + expectedCleanupPrice + expectedReservationFee
|
||
|
||
console.log(' Booking details:')
|
||
console.log(` - Date: ${dateStr}`)
|
||
console.log(` - Party size: ${partySize}`)
|
||
console.log(` - Menu: ${testMenu.title}`)
|
||
console.log(` - Include service: Yes`)
|
||
console.log(` - Include cleanup: Yes`)
|
||
console.log(' Expected price calculation:')
|
||
console.log(` - Menu: ${testMenu.basePricePerCover} kr × ${partySize} = ${expectedMenuPrice} kr`)
|
||
console.log(` - Service: 100 kr × ${partySize} = ${expectedServicePrice} kr`)
|
||
console.log(` - Cleanup: ${expectedCleanupPrice} kr`)
|
||
console.log(` - Reservation fee: ${expectedReservationFee} kr`)
|
||
console.log(` - TOTAL: ${expectedTotal} kr\n`)
|
||
|
||
const bookingRes = await fetch(`${BASE}/api/bookings`, {
|
||
method: 'POST',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify(bookingPayload)
|
||
})
|
||
|
||
if (!bookingRes.ok) {
|
||
const error = await bookingRes.text()
|
||
console.error('❌ Failed to create booking:', bookingRes.status, error)
|
||
process.exit(1)
|
||
}
|
||
|
||
const bookingResult = await bookingRes.json()
|
||
console.log('✅ Booking created successfully')
|
||
console.log(` Booking ID: ${bookingResult.id}`)
|
||
console.log(` Total price: ${bookingResult.total_price} kr`)
|
||
|
||
if (bookingResult.total_price !== expectedTotal) {
|
||
console.error(`❌ Price mismatch! Expected ${expectedTotal} kr, got ${bookingResult.total_price} kr`)
|
||
process.exit(1)
|
||
}
|
||
console.log(`✅ Price calculation correct!\n`)
|
||
|
||
// Test 4: Verify booking appears in admin view
|
||
console.log('4️⃣ Testing GET /api/bookings')
|
||
const allBookingsRes = await fetch(`${BASE}/api/bookings`)
|
||
if (!allBookingsRes.ok) {
|
||
console.error('❌ Failed to fetch bookings:', allBookingsRes.status)
|
||
process.exit(1)
|
||
}
|
||
const allBookings = await allBookingsRes.json()
|
||
const ourBooking = allBookings.find(b => b.id === bookingResult.id)
|
||
if (!ourBooking) {
|
||
console.error('❌ Created booking not found in list')
|
||
process.exit(1)
|
||
}
|
||
console.log('✅ Booking appears in admin list')
|
||
console.log(` Name: ${ourBooking.name}`)
|
||
console.log(` Menu ID: ${ourBooking.menu_id}`)
|
||
console.log(` Total: ${ourBooking.total_price} kr\n`)
|
||
|
||
// Test 5: Clean up - delete the test booking
|
||
console.log('5️⃣ Cleaning up - deleting test booking')
|
||
const deleteRes = await fetch(`${BASE}/api/bookings`, {
|
||
method: 'DELETE',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({ id: bookingResult.id })
|
||
})
|
||
|
||
if (!deleteRes.ok) {
|
||
console.error('❌ Failed to delete booking:', deleteRes.status)
|
||
process.exit(1)
|
||
}
|
||
console.log('✅ Test booking deleted\n')
|
||
|
||
console.log('🎉 All tests passed! Database integration is working correctly.')
|
||
console.log('\nSummary:')
|
||
console.log(`✅ Menus API working (${menus.length} menus)`)
|
||
console.log(`✅ Packages API working (${packages.length} packages)`)
|
||
console.log(`✅ Booking creation with correct price calculation`)
|
||
console.log(`✅ Booking retrieval and verification`)
|
||
console.log(`✅ Booking deletion`)
|