Files
fotospiel-app/tests/e2e/marketing-package-flow.test.ts
2025-10-04 16:38:42 +02:00

154 lines
5.6 KiB
TypeScript

import { test, expect } from '@playwright/test';
import { execSync } from 'child_process';
const BASE_URL = process.env.PLAYWRIGHT_BASE_URL || 'http://localhost:8000';
function seedTestUser() {
execSync('php artisan tenant:add-dummy --email=test@example.com --password=password123 --first_name=Test --last_name=User --address="Teststr. 1" --phone="+49123"', { stdio: 'ignore' });
execSync('php artisan tinker --execute="App\\Models\\User::where(\'email\', \'test@example.com\')->update([\'email_verified_at\' => now()]);"', { stdio: 'ignore' });
}
test.describe('Marketing Purchase Wizard', () => {
test.beforeAll(() => {
seedTestUser();
});
test('guest users see registration step after package selection', async ({ page }) => {
await page.goto(`${BASE_URL}/purchase-wizard/1`);
await page.getByRole('button', { name: /Weiter/i }).click();
await expect(page.getByText(/Registrieren/i)).toBeVisible();
await expect(page.getByText(/Anmelden/i)).toBeVisible();
});
test('authenticated users skip auth and can finish PayPal flow', async ({ page }) => {
await page.route('https://js.stripe.com/v3', async (route) => {
await route.fulfill({
status: 200,
contentType: 'application/javascript',
body: `window.Stripe = function(){
return {
elements: function(){
return {
create: function(){
return {
mount: function(){},
destroy: function(){},
on: function(){},
update: function(){},
unmount: function(){},
};
},
getElement: function(){
return {
clear: function(){},
};
}
};
},
confirmCardPayment: async function(){
return { paymentIntent: { id: 'pi_test', status: 'succeeded' } };
}
};
};`
});
});
await page.route('https://www.paypal.com/sdk/js?**', async (route) => {
await route.fulfill({
status: 200,
contentType: 'application/javascript',
body: `window.paypal = {
Buttons: function(options){
return {
render: function(container){
const target = typeof container === 'string' ? document.querySelector(container) : container;
if (!target) return;
const btn = document.createElement('button');
btn.type = 'button';
btn.textContent = 'PayPal Test Button';
btn.addEventListener('click', async () => {
try {
const orderId = await options.createOrder();
await options.onApprove({ orderID: orderId });
} catch (error) {
if (options.onError) options.onError(error);
}
});
target.innerHTML = '';
target.appendChild(btn);
},
close: function(){}
};
}
};`
});
});
await page.route('**/purchase/auth/login', (route) => route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
status: 'authenticated',
user: { id: 1, email: 'test@example.com', name: 'Test User', pending_purchase: false, email_verified: true },
next_step: 'payment',
needs_verification: false,
}),
}));
await page.route('**/purchase/auth/register', (route) => route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
status: 'registered',
user: { id: 2, email: 'new@example.com', name: 'New User', pending_purchase: true, email_verified: false },
next_step: 'payment',
}),
}));
await page.route('**/purchase/stripe/intent', (route) => route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({ client_secret: 'pi_secret', payment_intent_id: 'pi_test' }),
}));
await page.route('**/purchase/stripe/complete', (route) => route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({ status: 'completed' }),
}));
await page.route('**/purchase/paypal/order', (route) => route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({ order_id: 'ORDER-TEST', status: 'CREATED' }),
}));
await page.route('**/purchase/paypal/capture', (route) => route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({ status: 'captured' }),
}));
await page.goto(`${BASE_URL}/de/login`);
await page.fill('input[name="login"]', 'test@example.com');
await page.fill('input[name="password"]', 'password123');
await page.getByRole('button', { name: /Anmelden/i }).click();
await expect(page).toHaveURL(/dashboard|admin/i, { timeout: 10000 });
await page.goto(`${BASE_URL}/purchase-wizard/2`);
await page.getByRole('button', { name: /Weiter/i }).click();
await expect(page.getByRole('button', { name: 'Stripe' })).toBeVisible();
await expect(page.getByRole('button', { name: 'PayPal' })).toBeVisible();
await page.getByRole('button', { name: 'PayPal' }).click();
await page.getByRole('button', { name: 'PayPal Test Button' }).click();
await expect(page.getByText(/Willkommen/i)).toBeVisible();
await expect(page.getByRole('button', { name: /Dashboard/i })).toBeVisible();
});
});