import { test, expect } from '@playwright/test'; // Mock Firebase Firestore data for testing const mockOrgData = { id: 'test-org-1', name: 'Test Organization', payment: { stripe: { accountId: 'acct_test_123', chargesEnabled: true, detailsSubmitted: true, businessName: 'Test Business' } } }; const mockEventData = { id: 'test-event-1', orgId: 'test-org-1', name: 'Test Concert 2024', startAt: new Date('2024-08-01T19:00:00Z'), endAt: new Date('2024-08-01T23:00:00Z'), location: 'Test Venue, Denver CO', status: 'published' }; const mockTicketTypeData = { id: 'test-ticket-type-1', orgId: 'test-org-1', eventId: 'test-event-1', name: 'General Admission', priceCents: 5000, // $50.00 currency: 'USD', inventory: 100, sold: 3 }; const mockSessionId = 'cs_test_session_123'; const mockQrCode = '550e8400-e29b-41d4-a716-446655440000'; test.describe('Stripe Checkout Connected Accounts Flow', () => { test.beforeEach(async ({ page }) => { // Mock network requests to Firebase Functions await page.route('**/createCheckout', async (route) => { const request = await route.request().postDataJSON(); if (request.qty > mockTicketTypeData.inventory - mockTicketTypeData.sold) { await route.fulfill({ status: 400, contentType: 'application/json', body: JSON.stringify({ error: `Not enough tickets available. Requested: ${request.qty}, Available: ${mockTicketTypeData.inventory - mockTicketTypeData.sold}` }) }); return; } await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ url: `https://checkout.stripe.com/c/pay/${mockSessionId}`, sessionId: mockSessionId }) }); }); await page.route('**/getOrder', async (route) => { const request = await route.request().postDataJSON(); if (request.sessionId === mockSessionId) { await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ id: mockSessionId, orgId: mockOrgData.id, eventId: mockEventData.id, ticketTypeId: mockTicketTypeData.id, qty: 2, status: 'paid', totalCents: 10000, purchaserEmail: 'test@example.com', eventName: mockEventData.name, ticketTypeName: mockTicketTypeData.name, eventDate: mockEventData.startAt.toISOString(), eventLocation: mockEventData.location, createdAt: new Date().toISOString() }) }); } else { await route.fulfill({ status: 404, contentType: 'application/json', body: JSON.stringify({ error: 'Order not found' }) }); } }); await page.route('**/verifyTicket', async (route) => { const request = await route.request().postDataJSON(); if (request.qr === mockQrCode) { await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ valid: true, ticket: { id: 'ticket-123', eventId: mockEventData.id, ticketTypeId: mockTicketTypeData.id, eventName: mockEventData.name, ticketTypeName: mockTicketTypeData.name, status: 'scanned', purchaserEmail: 'test@example.com' } }) }); } else if (request.qr === 'already-scanned-qr') { await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ valid: false, reason: 'already_scanned', scannedAt: new Date().toISOString(), ticket: { id: 'ticket-456', eventId: mockEventData.id, ticketTypeId: mockTicketTypeData.id, status: 'scanned' } }) }); } else { await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ valid: false, reason: 'Ticket not found' }) }); } }); // Mock Firebase authentication await page.addInitScript(() => { // @ts-ignore window.mockUser = { email: 'test@example.com', organization: { id: 'test-org-1', name: 'Test Organization' } }; }); }); test('should successfully create checkout session and redirect to Stripe', async ({ page }) => { // Mock the checkout page with ticket purchase component await page.setContent(`