Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Moved stripe tests to folder * Abstracted stripe payments logic to lib * Added initial unit test for stripe payment * Added subscription tests * Added tests for regulare purchases * Added tests for edit subscription * Added cancel tests * Added integration tests * Fixed lint issues * Fixed lint issue
- Loading branch information
1 parent
2c37ba3
commit 638525f
Showing
11 changed files
with
1,120 additions
and
376 deletions.
There are no files selected for viewing
21 changes: 0 additions & 21 deletions
21
test/api/v3/integration/payments/GET-payments_stripe_subscribe_cancel.test.js
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
test/api/v3/integration/payments/POST-payments_stripe_checkout.test.js
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
test/api/v3/integration/payments/POST-payments_stripe_subscribe_edit.test.js
This file was deleted.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
test/api/v3/integration/payments/stripe/GET-payments_stripe_subscribe_cancel.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { | ||
generateUser, | ||
generateGroup, | ||
translate as t, | ||
} from '../../../../../helpers/api-integration/v3'; | ||
import stripePayments from '../../../../../../website/server/libs/stripePayments'; | ||
|
||
describe('payments - stripe - #subscribeCancel', () => { | ||
let endpoint = '/stripe/subscribe/cancel'; | ||
let user, group, stripeCancelSubscriptionStub; | ||
|
||
beforeEach(async () => { | ||
user = await generateUser(); | ||
}); | ||
|
||
it('verifies credentials', async () => { | ||
await expect(user.get(endpoint)).to.eventually.be.rejected.and.eql({ | ||
code: 401, | ||
error: 'NotAuthorized', | ||
message: t('missingSubscription'), | ||
}); | ||
}); | ||
|
||
describe('success', () => { | ||
beforeEach(async () => { | ||
stripeCancelSubscriptionStub = sinon.stub(stripePayments, 'cancelSubscription').returnsPromise().resolves({}); | ||
}); | ||
|
||
afterEach(() => { | ||
stripePayments.cancelSubscription.restore(); | ||
}); | ||
|
||
it('cancels a user subscription', async () => { | ||
user = await generateUser({ | ||
'profile.name': 'sender', | ||
'purchased.plan.customerId': 'customer-id', | ||
'purchased.plan.planId': 'basic_3mo', | ||
'purchased.plan.lastBillingDate': new Date(), | ||
balance: 2, | ||
}); | ||
|
||
await user.get(`${endpoint}?redirect=none`); | ||
|
||
expect(stripeCancelSubscriptionStub).to.be.calledOnce; | ||
expect(stripeCancelSubscriptionStub.args[0][0].user._id).to.eql(user._id); | ||
expect(stripeCancelSubscriptionStub.args[0][0].groupId).to.eql(undefined); | ||
}); | ||
|
||
it('cancels a group subscription', async () => { | ||
user = await generateUser({ | ||
'profile.name': 'sender', | ||
'purchased.plan.customerId': 'customer-id', | ||
'purchased.plan.planId': 'basic_3mo', | ||
'purchased.plan.lastBillingDate': new Date(), | ||
balance: 2, | ||
}); | ||
|
||
group = await generateGroup(user, { | ||
name: 'test group', | ||
type: 'guild', | ||
privacy: 'public', | ||
'purchased.plan.customerId': 'customer-id', | ||
'purchased.plan.planId': 'basic_3mo', | ||
'purchased.plan.lastBillingDate': new Date(), | ||
}); | ||
|
||
await user.get(`${endpoint}?groupId=${group._id}&redirect=none`); | ||
|
||
expect(stripeCancelSubscriptionStub).to.be.calledOnce; | ||
expect(stripeCancelSubscriptionStub.args[0][0].user._id).to.eql(user._id); | ||
expect(stripeCancelSubscriptionStub.args[0][0].groupId).to.eql(group._id); | ||
}); | ||
}); | ||
}); |
75 changes: 75 additions & 0 deletions
75
test/api/v3/integration/payments/stripe/POST-payments_stripe_checkout.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { | ||
generateUser, | ||
generateGroup, | ||
} from '../../../../../helpers/api-integration/v3'; | ||
import stripePayments from '../../../../../../website/server/libs/stripePayments'; | ||
|
||
describe('payments - stripe - #checkout', () => { | ||
let endpoint = '/stripe/checkout'; | ||
let user, group; | ||
|
||
beforeEach(async () => { | ||
user = await generateUser(); | ||
}); | ||
|
||
it('verifies credentials', async () => { | ||
await expect(user.post(endpoint, {id: 123})).to.eventually.be.rejected.and.eql({ | ||
code: 401, | ||
error: 'Error', | ||
message: 'Invalid API Key provided: ****************************1111', | ||
}); | ||
}); | ||
|
||
describe('success', () => { | ||
let stripeCheckoutSubscriptionStub; | ||
|
||
beforeEach(async () => { | ||
stripeCheckoutSubscriptionStub = sinon.stub(stripePayments, 'checkout').returnsPromise().resolves({}); | ||
}); | ||
|
||
afterEach(() => { | ||
stripePayments.checkout.restore(); | ||
}); | ||
|
||
it('cancels a user subscription', async () => { | ||
user = await generateUser({ | ||
'profile.name': 'sender', | ||
'purchased.plan.customerId': 'customer-id', | ||
'purchased.plan.planId': 'basic_3mo', | ||
'purchased.plan.lastBillingDate': new Date(), | ||
balance: 2, | ||
}); | ||
|
||
await user.post(endpoint); | ||
|
||
expect(stripeCheckoutSubscriptionStub).to.be.calledOnce; | ||
expect(stripeCheckoutSubscriptionStub.args[0][0].user._id).to.eql(user._id); | ||
expect(stripeCheckoutSubscriptionStub.args[0][0].groupId).to.eql(undefined); | ||
}); | ||
|
||
it('cancels a group subscription', async () => { | ||
user = await generateUser({ | ||
'profile.name': 'sender', | ||
'purchased.plan.customerId': 'customer-id', | ||
'purchased.plan.planId': 'basic_3mo', | ||
'purchased.plan.lastBillingDate': new Date(), | ||
balance: 2, | ||
}); | ||
|
||
group = await generateGroup(user, { | ||
name: 'test group', | ||
type: 'guild', | ||
privacy: 'public', | ||
'purchased.plan.customerId': 'customer-id', | ||
'purchased.plan.planId': 'basic_3mo', | ||
'purchased.plan.lastBillingDate': new Date(), | ||
}); | ||
|
||
await user.post(`${endpoint}?groupId=${group._id}`); | ||
|
||
expect(stripeCheckoutSubscriptionStub).to.be.calledOnce; | ||
expect(stripeCheckoutSubscriptionStub.args[0][0].user._id).to.eql(user._id); | ||
expect(stripeCheckoutSubscriptionStub.args[0][0].groupId).to.eql(group._id); | ||
}); | ||
}); | ||
}); |
78 changes: 78 additions & 0 deletions
78
test/api/v3/integration/payments/stripe/POST-payments_stripe_subscribe_edit.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { | ||
generateUser, | ||
generateGroup, | ||
translate as t, | ||
} from '../../../../../helpers/api-integration/v3'; | ||
import stripePayments from '../../../../../../website/server/libs/stripePayments'; | ||
|
||
describe('payments - stripe - #subscribeEdit', () => { | ||
let endpoint = '/stripe/subscribe/edit'; | ||
let user, group; | ||
|
||
beforeEach(async () => { | ||
user = await generateUser(); | ||
}); | ||
|
||
it('verifies credentials', async () => { | ||
await expect(user.post(endpoint)).to.eventually.be.rejected.and.eql({ | ||
code: 401, | ||
error: 'NotAuthorized', | ||
message: t('missingSubscription'), | ||
}); | ||
}); | ||
|
||
describe('success', () => { | ||
let stripeEditSubscriptionStub; | ||
|
||
beforeEach(async () => { | ||
stripeEditSubscriptionStub = sinon.stub(stripePayments, 'editSubscription').returnsPromise().resolves({}); | ||
}); | ||
|
||
afterEach(() => { | ||
stripePayments.editSubscription.restore(); | ||
}); | ||
|
||
it('cancels a user subscription', async () => { | ||
user = await generateUser({ | ||
'profile.name': 'sender', | ||
'purchased.plan.customerId': 'customer-id', | ||
'purchased.plan.planId': 'basic_3mo', | ||
'purchased.plan.lastBillingDate': new Date(), | ||
balance: 2, | ||
}); | ||
|
||
await user.post(endpoint); | ||
|
||
expect(stripeEditSubscriptionStub).to.be.calledOnce; | ||
expect(stripeEditSubscriptionStub.args[0][0].user._id).to.eql(user._id); | ||
expect(stripeEditSubscriptionStub.args[0][0].groupId).to.eql(undefined); | ||
}); | ||
|
||
it('cancels a group subscription', async () => { | ||
user = await generateUser({ | ||
'profile.name': 'sender', | ||
'purchased.plan.customerId': 'customer-id', | ||
'purchased.plan.planId': 'basic_3mo', | ||
'purchased.plan.lastBillingDate': new Date(), | ||
balance: 2, | ||
}); | ||
|
||
group = await generateGroup(user, { | ||
name: 'test group', | ||
type: 'guild', | ||
privacy: 'public', | ||
'purchased.plan.customerId': 'customer-id', | ||
'purchased.plan.planId': 'basic_3mo', | ||
'purchased.plan.lastBillingDate': new Date(), | ||
}); | ||
|
||
await user.post(endpoint, { | ||
groupId: group._id, | ||
}); | ||
|
||
expect(stripeEditSubscriptionStub).to.be.calledOnce; | ||
expect(stripeEditSubscriptionStub.args[0][0].user._id).to.eql(user._id); | ||
expect(stripeEditSubscriptionStub.args[0][0].groupId).to.eql(group._id); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.