0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Memoized the getStripeAccountId function

no issue

Some flaky tests found, and it seems as though they're being caused by an invalid Stripe account id.

It's possible that by re-using the worker after a test which calls `setupStripe` could cause some Stripe functionality to not work.
This commit is contained in:
Sam Lord 2023-10-16 22:03:11 +01:00 committed by Sam Lord
parent 4911a73979
commit 7f67e98e28

View file

@ -463,13 +463,18 @@ const openTierModal = async (page, {slug}) => {
});
};
// Memoized function to get the Stripe account ID
let stripeAccountId;
const getStripeAccountId = async () => {
if (stripeAccountId) {
return stripeAccountId;
}
if (!('STRIPE_PUBLISHABLE_KEY' in process.env) || !('STRIPE_SECRET_KEY' in process.env)) {
throw new Error('Missing STRIPE_PUBLISHABLE_KEY or STRIPE_SECRET_KEY environment variables');
}
const parallelIndex = process.env.TEST_PARALLEL_INDEX;
let accountId;
const accountEmail = `test${parallelIndex}@example.com`;
const secretKey = process.env.STRIPE_SECRET_KEY;
@ -483,19 +488,18 @@ const getStripeAccountId = async () => {
await stripe.accounts.del(account.id);
}
}
if (!accountId) {
const account = await stripe.accounts.create({
type: 'standard',
email: accountEmail,
business_type: 'company',
company: {
name: `Test Company ${parallelIndex}`
}
});
accountId = account.id;
}
return accountId;
const account = await stripe.accounts.create({
type: 'standard',
email: accountEmail,
business_type: 'company',
company: {
name: `Test Company ${parallelIndex}`
}
});
stripeAccountId = account.id;
return stripeAccountId;
};
const generateStripeIntegrationToken = async (accountId) => {