bde148f286
* wip * some extra fixes * stuff kinda works? * need to figure out mocks * need to figure out mocks * fix db listener * gqlgen fix * minor gqlgen watch adjustment * lint fixes * delete old codegen file * converting migrations to ESM * getModuleDIrectory * vitest sort of works * added back ts-vitest * resolve gql double load * fixing test timeout configs * TSC lint fix * fix automate tests * moar debugging * debugging * more debugging * codegen update * server works * yargs migrated * chore(server): getting rid of global mocks for Server ESM (#5046) * got rid of email mock * got rid of comment mocks * got rid of multi region mocks * got rid of stripe mock * admin override mock updated * removed final mock * fixing import.meta.resolve calls * another import.meta.resolve fix * added requested test * nyc ESM fix * removed unneeded deps + linting * yarn lock forgot to commit * tryna fix flakyness * email capture util fix * sendEmail fix * fix TSX check * sender transporter fix + CR comments * merge main fix * test fixx * circleci fix * gqlgen bigint fix * error formatter fix * more error formatting improvements * esmloader added to Dockerfile * more dockerfile fixes * bg jobs fix
142 lines
4.5 KiB
TypeScript
142 lines
4.5 KiB
TypeScript
import { buildFakeStripe } from '@/modules/gatekeeper/tests/helpers/stripe'
|
|
import cryptoRandomString from 'crypto-random-string'
|
|
import {
|
|
buildTestSubscriptionData,
|
|
buildTestSubscriptionProduct
|
|
} from '@/modules/gatekeeper/tests/helpers/workspacePlan'
|
|
import { reconcileWorkspaceSubscriptionFactory } from '@/modules/gatekeeper/clients/stripe'
|
|
import { expect } from 'chai'
|
|
|
|
describe('Stripe integration', () => {
|
|
describe('Reconciliation', () => {
|
|
it('does not send any delete or create anything in Stripe when existing subscription equals to the new one', async () => {
|
|
const updates = {}
|
|
const subscriptionId = cryptoRandomString({ length: 10 })
|
|
const subscriptionItemId = cryptoRandomString({ length: 10 })
|
|
const fakeStripe = buildFakeStripe(updates)
|
|
const subscriptionData = buildTestSubscriptionData({
|
|
subscriptionId,
|
|
products: [
|
|
buildTestSubscriptionProduct({
|
|
subscriptionItemId,
|
|
quantity: 2
|
|
})
|
|
]
|
|
})
|
|
const reconcileWorkspaceSubscription = reconcileWorkspaceSubscriptionFactory({
|
|
getStripeClient: () => fakeStripe,
|
|
getStripeSubscriptionData: async () => subscriptionData
|
|
})
|
|
|
|
await reconcileWorkspaceSubscription({
|
|
subscriptionData,
|
|
prorationBehavior: 'none'
|
|
})
|
|
|
|
expect(updates).to.be.deep.equal({
|
|
[subscriptionId]: {
|
|
items: [{ quantity: 2, id: subscriptionItemId }],
|
|
// eslint-disable-next-line camelcase
|
|
proration_behavior: 'none'
|
|
}
|
|
})
|
|
})
|
|
|
|
it('deletes the current products and adds only the needed when stripe has more products than we provided', async () => {
|
|
const updates = {}
|
|
const subscriptionId = cryptoRandomString({ length: 10 })
|
|
const priceId = cryptoRandomString({ length: 10 })
|
|
const subscriptionItemId = cryptoRandomString({ length: 10 })
|
|
const fakeStripe = buildFakeStripe(updates)
|
|
const subscriptionData = buildTestSubscriptionData({
|
|
subscriptionId,
|
|
products: [
|
|
buildTestSubscriptionProduct({
|
|
priceId,
|
|
subscriptionItemId,
|
|
quantity: 1
|
|
})
|
|
]
|
|
})
|
|
const reconcileWorkspaceSubscription = reconcileWorkspaceSubscriptionFactory({
|
|
getStripeClient: () => fakeStripe,
|
|
getStripeSubscriptionData: async () =>
|
|
buildTestSubscriptionData({
|
|
subscriptionId,
|
|
products: [
|
|
buildTestSubscriptionProduct({
|
|
priceId,
|
|
subscriptionItemId,
|
|
quantity: 2
|
|
})
|
|
]
|
|
})
|
|
})
|
|
|
|
await reconcileWorkspaceSubscription({
|
|
subscriptionData,
|
|
prorationBehavior: 'none'
|
|
})
|
|
|
|
expect(updates).to.be.deep.equal({
|
|
[subscriptionId]: {
|
|
items: [
|
|
{ quantity: 1, price: priceId },
|
|
{ deleted: true, id: subscriptionItemId }
|
|
],
|
|
// eslint-disable-next-line camelcase
|
|
proration_behavior: 'none'
|
|
}
|
|
})
|
|
})
|
|
|
|
it('deletes the current products and ads new ones when stripe has less products than we provided', async () => {
|
|
const updates = {}
|
|
const subscriptionId = cryptoRandomString({ length: 10 })
|
|
const priceId = cryptoRandomString({ length: 10 })
|
|
const subscriptionItemId = cryptoRandomString({ length: 10 })
|
|
const fakeStripe = buildFakeStripe(updates)
|
|
const subscriptionData = buildTestSubscriptionData({
|
|
subscriptionId,
|
|
products: [
|
|
buildTestSubscriptionProduct({
|
|
priceId,
|
|
subscriptionItemId,
|
|
quantity: 3
|
|
})
|
|
]
|
|
})
|
|
const reconcileWorkspaceSubscription = reconcileWorkspaceSubscriptionFactory({
|
|
getStripeClient: () => fakeStripe,
|
|
getStripeSubscriptionData: async () =>
|
|
buildTestSubscriptionData({
|
|
subscriptionId,
|
|
products: [
|
|
buildTestSubscriptionProduct({
|
|
priceId,
|
|
subscriptionItemId,
|
|
quantity: 2
|
|
})
|
|
]
|
|
})
|
|
})
|
|
|
|
await reconcileWorkspaceSubscription({
|
|
subscriptionData,
|
|
prorationBehavior: 'none'
|
|
})
|
|
|
|
expect(updates).to.be.deep.equal({
|
|
[subscriptionId]: {
|
|
items: [
|
|
{ quantity: 3, price: priceId },
|
|
{ deleted: true, id: subscriptionItemId }
|
|
],
|
|
// eslint-disable-next-line camelcase
|
|
proration_behavior: 'none'
|
|
}
|
|
})
|
|
})
|
|
})
|
|
})
|