mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-12 07:30:46 +02:00
[web] make SubscriptionController.cancelSubscription return a status (#26734)
* [web] make SubscriptionController.cancelSubscription return a status * [web] update acceptance test to match cancel subscription behavior GitOrigin-RevId: 507809dcb7fa645c2a69e38cdf4a9e3f736622e1
This commit is contained in:
@@ -304,20 +304,18 @@ async function resumeSubscription(req, res, next) {
|
||||
}
|
||||
}
|
||||
|
||||
function cancelSubscription(req, res, next) {
|
||||
async function cancelSubscription(req, res, next) {
|
||||
const user = SessionManager.getSessionUser(req.session)
|
||||
logger.debug({ userId: user._id }, 'canceling subscription')
|
||||
SubscriptionHandler.cancelSubscription(user, function (err) {
|
||||
if (err) {
|
||||
OError.tag(err, 'something went wrong canceling subscription', {
|
||||
user_id: user._id,
|
||||
})
|
||||
return next(err)
|
||||
}
|
||||
// Note: this redirect isn't used in the main flow as the redirection is
|
||||
// handled by Angular
|
||||
res.redirect('/user/subscription/canceled')
|
||||
})
|
||||
try {
|
||||
await SubscriptionHandler.promises.cancelSubscription(user)
|
||||
return res.sendStatus(200)
|
||||
} catch (err) {
|
||||
OError.tag(err, 'something went wrong canceling subscription', {
|
||||
user_id: user._id,
|
||||
})
|
||||
return next(err)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -487,28 +487,39 @@ describe('SubscriptionController', function () {
|
||||
})
|
||||
|
||||
describe('cancelSubscription', function () {
|
||||
beforeEach(function (done) {
|
||||
this.res = {
|
||||
redirect() {
|
||||
done()
|
||||
},
|
||||
}
|
||||
sinon.spy(this.res, 'redirect')
|
||||
this.SubscriptionController.cancelSubscription(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should tell the handler to cancel this user', function (done) {
|
||||
this.SubscriptionHandler.cancelSubscription
|
||||
it('should tell the handler to cancel this user', async function () {
|
||||
this.next = sinon.stub()
|
||||
await this.SubscriptionController.cancelSubscription(
|
||||
this.req,
|
||||
this.res,
|
||||
this.next
|
||||
)
|
||||
this.SubscriptionHandler.promises.cancelSubscription
|
||||
.calledWith(this.user)
|
||||
.should.equal(true)
|
||||
done()
|
||||
})
|
||||
|
||||
it('should redurect to the subscription page', function (done) {
|
||||
this.res.redirect
|
||||
.calledWith('/user/subscription/canceled')
|
||||
.should.equal(true)
|
||||
done()
|
||||
it('should return a 200 on success', async function () {
|
||||
this.next = sinon.stub()
|
||||
await this.SubscriptionController.cancelSubscription(
|
||||
this.req,
|
||||
this.res,
|
||||
this.next
|
||||
)
|
||||
expect(this.res.statusCode).to.equal(200)
|
||||
})
|
||||
|
||||
it('should call next with error', async function () {
|
||||
this.SubscriptionHandler.promises.cancelSubscription.rejects(
|
||||
new Error('cancel error')
|
||||
)
|
||||
this.next = sinon.stub()
|
||||
await this.SubscriptionController.cancelSubscription(
|
||||
this.req,
|
||||
this.res,
|
||||
this.next
|
||||
)
|
||||
this.next.calledWith(sinon.match.instanceOf(Error)).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user