2019-10-08 18:45:38 +00:00
|
|
|
import { generateUser } from '../../../../../helpers/api-integration/v3';
|
2018-04-08 14:27:03 +00:00
|
|
|
import applePayments from '../../../../../../website/server/libs/payments/apple';
|
2017-02-21 18:22:13 +00:00
|
|
|
|
|
|
|
|
describe('payments : apple #cancelSubscribe', () => {
|
2019-10-08 18:45:38 +00:00
|
|
|
const endpoint = '/iap/ios/subscribe/cancel?noRedirect=true';
|
2017-02-21 18:22:13 +00:00
|
|
|
let user;
|
|
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
|
user = await generateUser();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('success', () => {
|
|
|
|
|
let cancelStub;
|
|
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
2018-10-26 16:15:28 +00:00
|
|
|
cancelStub = sinon.stub(applePayments, 'cancelSubscribe').resolves({});
|
2017-02-21 18:22:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
|
applePayments.cancelSubscribe.restore();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('cancels the subscription', async () => {
|
|
|
|
|
user = await generateUser({
|
|
|
|
|
'profile.name': 'sender',
|
|
|
|
|
'purchased.plan.paymentMethod': 'Apple',
|
|
|
|
|
'purchased.plan.customerId': 'customer-id',
|
|
|
|
|
'purchased.plan.planId': 'basic_3mo',
|
|
|
|
|
'purchased.plan.lastBillingDate': new Date(),
|
|
|
|
|
balance: 2,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await user.get(endpoint);
|
|
|
|
|
|
|
|
|
|
expect(cancelStub).to.be.calledOnce;
|
|
|
|
|
expect(cancelStub.args[0][0]._id).to.eql(user._id);
|
|
|
|
|
expect(cancelStub.args[0][1]['x-api-key']).to.eql(user.apiToken);
|
|
|
|
|
expect(cancelStub.args[0][1]['x-api-user']).to.eql(user._id);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|