mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-18 02:21:47 -05:00
Added tests for smart_cancel param
refs https://github.com/TryGhost/Team/issues/530
This commit is contained in:
parent
3ed10ecdf6
commit
48ad254df3
1 changed files with 98 additions and 0 deletions
|
@ -90,5 +90,103 @@ describe('MemberController', function () {
|
|||
|
||||
memberRepository.updateSubscription.verify();
|
||||
});
|
||||
|
||||
describe('smart_cancel', function () {
|
||||
it('Updates a paid subscriptions cancel_at_period_end via the member repository', async function () {
|
||||
const tokenService = {
|
||||
decodeToken: sinon.fake.resolves({sub: 'fake@email.com'})
|
||||
};
|
||||
const stripePlansService = {
|
||||
getPlan: sinon.fake.returns({id: 'plan_id'})
|
||||
};
|
||||
|
||||
const memberRepository = {
|
||||
updateSubscription: sinon.mock('updateSubscription').once().withArgs({
|
||||
email: 'fake@email.com',
|
||||
subscription: {
|
||||
subscription_id: 'subscription_id',
|
||||
cancellationReason: 'For reasonable reasons',
|
||||
cancel_at_period_end: true
|
||||
}
|
||||
}),
|
||||
getSubscription: sinon.fake.resolves({
|
||||
status: 'active'
|
||||
})
|
||||
};
|
||||
|
||||
const controller = new MemberController({
|
||||
memberRepository,
|
||||
stripePlansService,
|
||||
tokenService
|
||||
});
|
||||
|
||||
const req = {
|
||||
body: {
|
||||
identity: 'token',
|
||||
smart_cancel: true,
|
||||
cancellation_reason: 'For reasonable reasons'
|
||||
},
|
||||
params: {
|
||||
id: 'subscription_id'
|
||||
}
|
||||
};
|
||||
const res = {
|
||||
writeHead() {},
|
||||
end() {}
|
||||
};
|
||||
|
||||
await controller.updateSubscription(req, res);
|
||||
|
||||
memberRepository.updateSubscription.verify();
|
||||
});
|
||||
|
||||
it('Cancels an unpaid subscription via the member repository', async function () {
|
||||
const tokenService = {
|
||||
decodeToken: sinon.fake.resolves({sub: 'fake@email.com'})
|
||||
};
|
||||
const stripePlansService = {
|
||||
getPlan: sinon.fake.returns({id: 'plan_id'})
|
||||
};
|
||||
|
||||
const memberRepository = {
|
||||
updateSubscription: sinon.fake(),
|
||||
cancelSubscription: sinon.mock('cancelSubscription').once().withArgs({
|
||||
email: 'fake@email.com',
|
||||
subscription: {
|
||||
subscription_id: 'subscription_id',
|
||||
cancellationReason: 'For reasonable reasons'
|
||||
}
|
||||
}),
|
||||
getSubscription: sinon.fake.resolves({
|
||||
status: 'unpaid'
|
||||
})
|
||||
};
|
||||
|
||||
const controller = new MemberController({
|
||||
memberRepository,
|
||||
stripePlansService,
|
||||
tokenService
|
||||
});
|
||||
|
||||
const req = {
|
||||
body: {
|
||||
identity: 'token',
|
||||
smart_cancel: true,
|
||||
cancellation_reason: 'For reasonable reasons'
|
||||
},
|
||||
params: {
|
||||
id: 'subscription_id'
|
||||
}
|
||||
};
|
||||
const res = {
|
||||
writeHead() {},
|
||||
end() {}
|
||||
};
|
||||
|
||||
await controller.updateSubscription(req, res);
|
||||
|
||||
memberRepository.cancelSubscription.verify();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue