When running Cypress tests, which call a cleanup function to remove users in Stripe, I get the following error:
Body: { “status”: 500, “message”: “Error while cleaning the stripe
test data”, “error”: “stripe.customers.cancel is not a function” }
In this issue on Github it says I need to be on version 9.x or above. However when running npm list
in the directory where this package is installed, I can see I am using v14.18.0. I double-checked to see if there was a conflicting global package, but there does not seem to be. This is blocking me from testing at the moment, has anyone else experienced this or have any idea of where to look?
For the curious, this is the function called by Cypress for cleaning the test data:
const cleanAllCustomersExcept = async function cleanAllCustomersExcept(customersToKeep) {
// Delete customers
const customers = await stripe.customers.list();
console.log(stripe.customers);
const customersList = customers.data;
await Promise.all(
customersList.map(
async (customer) => (customersToKeep.includes(customer.id)
? null
: stripe.customers.cancel(customer.id)
.then(() => {
console.log(`Deleting customer ${customer.id}`);
})),
),
);
if (customers.has_more) {
return cleanAllCustomersExcept(customersToKeep);
}
console.log('Done removing all customers');
return null;
}