Update PayPal references and tests
This commit is contained in:
@@ -2,15 +2,12 @@ import { test, expectFixture as expect } from '../helpers/test-fixtures';
|
||||
|
||||
const shouldRun = process.env.E2E_TESTING_API === '1';
|
||||
|
||||
test.describe('Classic package checkout with Lemon Squeezy completion', () => {
|
||||
test.describe('Classic package checkout with PayPal completion', () => {
|
||||
test.skip(!shouldRun, 'Set E2E_TESTING_API=1 to enable checkout tests that use /api/_testing endpoints.');
|
||||
test('registers, applies coupon, and reaches confirmation', async ({
|
||||
page,
|
||||
clearTestMailbox,
|
||||
seedTestCoupons,
|
||||
getLatestCheckoutSession,
|
||||
simulateLemonSqueezyCompletion,
|
||||
getTestMailbox,
|
||||
}) => {
|
||||
await clearTestMailbox();
|
||||
await seedTestCoupons();
|
||||
@@ -18,44 +15,43 @@ test.describe('Classic package checkout with Lemon Squeezy completion', () => {
|
||||
const unique = Date.now();
|
||||
const email = `checkout+${unique}@example.test`;
|
||||
const password = 'Password123!';
|
||||
await page.addInitScript(() => {
|
||||
window.__openedWindows = [];
|
||||
const originalOpen = window.open;
|
||||
window.open = function (...args) {
|
||||
window.__openedWindows.push(args);
|
||||
return originalOpen?.apply(this, args) ?? null;
|
||||
};
|
||||
});
|
||||
|
||||
await page.route('https://app.lemonsqueezy.com/js/lemon.js', async (route) => {
|
||||
await page.route('https://www.paypal.com/sdk/js**', async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/javascript',
|
||||
body: `
|
||||
window.__lemonEventHandler = null;
|
||||
window.__lemonOpenedUrl = null;
|
||||
window.LemonSqueezy = {
|
||||
Setup(options) {
|
||||
window.__lemonEventHandler = options?.eventHandler || null;
|
||||
},
|
||||
Url: {
|
||||
Open(url) {
|
||||
window.__lemonOpenedUrl = url;
|
||||
},
|
||||
window.paypal = {
|
||||
Buttons: function(options) {
|
||||
window.__paypalOptions = options;
|
||||
return {
|
||||
render: function() { return Promise.resolve(); },
|
||||
};
|
||||
},
|
||||
};
|
||||
`,
|
||||
});
|
||||
});
|
||||
|
||||
let lemonsqueezyRequestPayload: Record<string, unknown> | null = null;
|
||||
await page.route('**/lemonsqueezy/create-checkout', async (route) => {
|
||||
lemonsqueezyRequestPayload = route.request().postDataJSON() as Record<string, unknown>;
|
||||
let paypalRequestPayload: Record<string, unknown> | null = null;
|
||||
await page.route('**/paypal/create-order', async (route) => {
|
||||
paypalRequestPayload = route.request().postDataJSON() as Record<string, unknown>;
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
checkout_url: 'https://fotospiel.lemonsqueezy.com/checkout/abc123',
|
||||
order_id: 'order_test_123',
|
||||
checkout_session_id: 'session_test_123',
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
await page.route('**/paypal/capture-order', async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
status: 'completed',
|
||||
}),
|
||||
});
|
||||
});
|
||||
@@ -113,85 +109,36 @@ test.describe('Classic package checkout with Lemon Squeezy completion', () => {
|
||||
await expect(termsCheckbox).toBeVisible();
|
||||
await termsCheckbox.click();
|
||||
|
||||
await page.getByRole('button', { name: /Weiter mit Lemon Squeezy|Continue with Lemon Squeezy/i }).first().click();
|
||||
await expect.poll(async () => {
|
||||
return page.evaluate(() => Boolean(window.__paypalOptions));
|
||||
}).toBe(true);
|
||||
|
||||
let checkoutMode: 'inline' | 'hosted' | null = null;
|
||||
for (let i = 0; i < 8; i++) {
|
||||
const state = await page.evaluate(() => ({
|
||||
inline: Boolean(window.__lemonOpenedUrl),
|
||||
opened: window.__openedWindows?.length ?? 0,
|
||||
}));
|
||||
|
||||
if (state.inline) {
|
||||
checkoutMode = 'inline';
|
||||
break;
|
||||
}
|
||||
|
||||
if (state.opened > 0) {
|
||||
checkoutMode = 'hosted';
|
||||
break;
|
||||
}
|
||||
|
||||
await page.waitForTimeout(300);
|
||||
}
|
||||
|
||||
expect(checkoutMode).not.toBeNull();
|
||||
|
||||
if (checkoutMode === 'hosted') {
|
||||
await expect.poll(async () => {
|
||||
return page.evaluate(() => window.__openedWindows?.[0]?.[0] ?? null);
|
||||
}).toContain('https://fotospiel.lemonsqueezy.com/checkout/abc123');
|
||||
}
|
||||
|
||||
await page.evaluate(() => {
|
||||
window.__lemonEventHandler?.({
|
||||
event: 'Checkout.Success',
|
||||
data: { id: 'ord_test', attributes: { checkout_id: 'chk_123' } },
|
||||
});
|
||||
const orderId = await page.evaluate(async () => {
|
||||
return window.__paypalOptions?.createOrder?.();
|
||||
});
|
||||
|
||||
let session = null;
|
||||
for (let i = 0; i < 6; i++) {
|
||||
session = await getLatestCheckoutSession({ email });
|
||||
if (session) {
|
||||
break;
|
||||
}
|
||||
await page.waitForTimeout(500);
|
||||
}
|
||||
expect(orderId).toBe('order_test_123');
|
||||
|
||||
if (session) {
|
||||
await simulateLemonSqueezyCompletion(session.id);
|
||||
|
||||
for (let i = 0; i < 6; i++) {
|
||||
const refreshed = await getLatestCheckoutSession({ email });
|
||||
if (refreshed?.status === 'completed') {
|
||||
session = refreshed;
|
||||
break;
|
||||
}
|
||||
await page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
expect(session?.status).toBe('completed');
|
||||
}
|
||||
await page.evaluate(async () => {
|
||||
await window.__paypalOptions?.onApprove?.({ orderID: 'order_test_123' });
|
||||
});
|
||||
|
||||
await expect(page.getByText(/Marketing-Dashboard/)).toBeVisible();
|
||||
await expect(
|
||||
page.getByRole('button', { name: /Zum Admin-Bereich|To Admin Area/i })
|
||||
).toBeVisible();
|
||||
|
||||
if (lemonsqueezyRequestPayload) {
|
||||
expect(lemonsqueezyRequestPayload['coupon_code']).toBe('PERCENT10');
|
||||
if (paypalRequestPayload) {
|
||||
expect(paypalRequestPayload['coupon_code']).toBe('PERCENT10');
|
||||
}
|
||||
|
||||
const messages = await getTestMailbox();
|
||||
expect(messages.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
__openedWindows?: unknown[];
|
||||
__lemonEventHandler?: ((event: { event: string; data?: unknown }) => void) | null;
|
||||
__lemonOpenedUrl?: string | null;
|
||||
__paypalOptions?: {
|
||||
createOrder?: () => Promise<string>;
|
||||
onApprove?: (data: { orderID: string }) => Promise<void>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user