mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
90 lines
3.7 KiB
TypeScript
90 lines
3.7 KiB
TypeScript
|
import {expect, test} from '@playwright/test';
|
||
|
import {globalDataRequests, mockApi, responseFixtures, updatedSettingsResponse} from '../../utils/e2e';
|
||
|
|
||
|
test.describe('Stripe settings', async () => {
|
||
|
test('Supports the Stripe Connect flow', async ({page}) => {
|
||
|
const {lastApiRequests} = await mockApi({page, requests: {
|
||
|
...globalDataRequests,
|
||
|
editSettings: {method: 'PUT', path: '/settings/', response: updatedSettingsResponse([
|
||
|
{key: 'stripe_connect_account_name', value: 'Dummy'},
|
||
|
{key: 'stripe_connect_livemode', value: false},
|
||
|
{key: 'stripe_connect_account_id', value: 'acct_123'},
|
||
|
{key: 'stripe_connect_publishable_key', value: 'pk_test_123'},
|
||
|
{key: 'stripe_connect_secret_key', value: 'sk_test_123'}
|
||
|
])}
|
||
|
}});
|
||
|
|
||
|
await page.goto('/');
|
||
|
|
||
|
const section = page.getByTestId('tiers');
|
||
|
|
||
|
await section.getByRole('button', {name: 'Connect with Stripe'}).click();
|
||
|
|
||
|
const modal = page.getByTestId('stripe-modal');
|
||
|
await modal.getByRole('button', {name: /I have a Stripe account/}).click();
|
||
|
|
||
|
await expect(modal.locator('a', {hasText: 'Connect with Stripe'})).toHaveAttribute('href', '/ghost/api/admin/members/stripe_connect?mode=live');
|
||
|
await modal.getByLabel('Test mode').check();
|
||
|
await expect(modal.locator('a', {hasText: 'Connect with Stripe'})).toHaveAttribute('href', '/ghost/api/admin/members/stripe_connect?mode=test');
|
||
|
|
||
|
await modal.getByPlaceholder('Paste your secure key here').fill('token_test');
|
||
|
await modal.getByRole('button', {name: 'Save Stripe settings'}).click();
|
||
|
|
||
|
await expect(modal.getByText('You are connected with Stripe!')).toHaveCount(1);
|
||
|
await modal.getByRole('button', {name: 'Close'}).click();
|
||
|
|
||
|
await expect(modal).toHaveCount(0);
|
||
|
|
||
|
await expect(section.getByText('Connected to Stripe')).toHaveCount(1);
|
||
|
|
||
|
// We actually do two settings update requests here, this just checks the last one
|
||
|
expect(lastApiRequests.editSettings?.body).toEqual({
|
||
|
settings: [{
|
||
|
key: 'portal_plans',
|
||
|
value: '["free","monthly","yearly"]'
|
||
|
}]
|
||
|
});
|
||
|
});
|
||
|
|
||
|
test('Supports updating Stripe Direct settings', async ({page}) => {
|
||
|
const {lastApiRequests} = await mockApi({page, requests: {
|
||
|
...globalDataRequests,
|
||
|
browseConfig: {method: 'GET', path: '/config/', response: {
|
||
|
config: {
|
||
|
...responseFixtures.config,
|
||
|
stripeDirect: true
|
||
|
}
|
||
|
}},
|
||
|
editSettings: {method: 'PUT', path: '/settings/', response: updatedSettingsResponse([
|
||
|
{key: 'stripe_publishable_key', value: 'pk_test_123'},
|
||
|
{key: 'stripe_secret_key', value: 'sk_test_123'}
|
||
|
])}
|
||
|
}});
|
||
|
|
||
|
await page.goto('/');
|
||
|
|
||
|
const section = page.getByTestId('tiers');
|
||
|
|
||
|
await section.getByRole('button', {name: 'Connect with Stripe'}).click();
|
||
|
|
||
|
const modal = page.getByTestId('stripe-modal');
|
||
|
await modal.getByLabel('Publishable key').fill('pk_test_123');
|
||
|
await modal.getByLabel('Secure key').fill('sk_test_123');
|
||
|
await modal.getByRole('button', {name: 'Save Stripe settings'}).click();
|
||
|
|
||
|
await expect(modal).toHaveCount(0);
|
||
|
|
||
|
await expect(section.getByText('Connected to Stripe')).toHaveCount(1);
|
||
|
|
||
|
expect(lastApiRequests.editSettings?.body).toEqual({
|
||
|
settings: [{
|
||
|
key: 'stripe_secret_key',
|
||
|
value: 'sk_test_123'
|
||
|
}, {
|
||
|
key: 'stripe_publishable_key',
|
||
|
value: 'pk_test_123'
|
||
|
}]
|
||
|
});
|
||
|
});
|
||
|
});
|