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:
parent
4911a73979
commit
7f67e98e28
1 changed files with 17 additions and 13 deletions
|
@ -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) => {
|
||||
|
|
Loading…
Add table
Reference in a new issue