Subscription code decaf cleanup (#7918)
GitOrigin-RevId: 43adff9af7ca347808980823ac641db05129a79b
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,16 +1,3 @@
|
||||
/* eslint-disable
|
||||
max-len,
|
||||
mocha/handle-done-callback,
|
||||
no-return-assign,
|
||||
no-unused-vars,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const sinon = require('sinon')
|
||||
const { assert, expect } = require('chai')
|
||||
@@ -172,13 +159,13 @@ describe('SubscriptionController', function () {
|
||||
this.req.body = {}
|
||||
this.req.query = { planCode: '123123' }
|
||||
|
||||
return (this.stubbedCurrencyCode = 'GBP')
|
||||
this.stubbedCurrencyCode = 'GBP'
|
||||
})
|
||||
|
||||
describe('plansPage', function () {
|
||||
beforeEach(function () {
|
||||
this.req.ip = '1234.3123.3131.333 313.133.445.666 653.5345.5345.534'
|
||||
return this.GeoIpLookup.promises.getCurrencyCode.resolves({
|
||||
this.GeoIpLookup.promises.getCurrencyCode.resolves({
|
||||
currencyCode: this.stubbedCurrencyCode,
|
||||
})
|
||||
})
|
||||
@@ -234,7 +221,7 @@ describe('SubscriptionController', function () {
|
||||
this.SubscriptionHandler.promises.validateNoSubscriptionInRecurly = sinon
|
||||
.stub()
|
||||
.resolves(true)
|
||||
return this.GeoIpLookup.promises.getCurrencyCode.resolves({
|
||||
this.GeoIpLookup.promises.getCurrencyCode.resolves({
|
||||
currencyCode: this.stubbedCurrencyCode,
|
||||
})
|
||||
})
|
||||
@@ -244,7 +231,7 @@ describe('SubscriptionController', function () {
|
||||
this.LimitationsManager.promises.userHasV1OrV2Subscription.resolves(
|
||||
false
|
||||
)
|
||||
return this.PlansLocator.findLocalPlanInSettings.returns({})
|
||||
this.PlansLocator.findLocalPlanInSettings.returns({})
|
||||
})
|
||||
|
||||
describe('with a valid plan code', function () {
|
||||
@@ -266,9 +253,9 @@ describe('SubscriptionController', function () {
|
||||
)
|
||||
this.res.redirect = url => {
|
||||
url.should.equal('/user/subscription?hasSubscription=true')
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
return this.SubscriptionController.paymentPage(this.req, this.res)
|
||||
this.SubscriptionController.paymentPage(this.req, this.res)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -286,7 +273,7 @@ describe('SubscriptionController', function () {
|
||||
done()
|
||||
}
|
||||
)
|
||||
return this.SubscriptionController.paymentPage(this.req, this.res)
|
||||
this.SubscriptionController.paymentPage(this.req, this.res)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -295,7 +282,7 @@ describe('SubscriptionController', function () {
|
||||
this.LimitationsManager.promises.userHasV1OrV2Subscription.resolves(
|
||||
false
|
||||
)
|
||||
return this.PlansLocator.findLocalPlanInSettings.returns({})
|
||||
this.PlansLocator.findLocalPlanInSettings.returns({})
|
||||
})
|
||||
|
||||
it('should use the set currency from the query string', function (done) {
|
||||
@@ -303,18 +290,18 @@ describe('SubscriptionController', function () {
|
||||
this.res.render = (page, opts) => {
|
||||
opts.currency.should.equal('EUR')
|
||||
opts.currency.should.not.equal(this.stubbedCurrencyCode)
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
return this.SubscriptionController.paymentPage(this.req, this.res)
|
||||
this.SubscriptionController.paymentPage(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should upercase the currency code', function (done) {
|
||||
this.req.query.currency = 'eur'
|
||||
this.res.render = (page, opts) => {
|
||||
opts.currency.should.equal('EUR')
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
return this.SubscriptionController.paymentPage(this.req, this.res)
|
||||
this.SubscriptionController.paymentPage(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should use the geo ip currency if non is provided', function (done) {
|
||||
@@ -348,9 +335,9 @@ describe('SubscriptionController', function () {
|
||||
)
|
||||
this.res.redirect = url => {
|
||||
url.should.equal('/user/subscription?hasSubscription=true')
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
return this.SubscriptionController.paymentPage(this.req, this.res)
|
||||
this.SubscriptionController.paymentPage(this.req, this.res)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -434,17 +421,17 @@ describe('SubscriptionController', function () {
|
||||
expect(this.data.personalSubscription).to.deep.equal(
|
||||
this.personalSubscription
|
||||
)
|
||||
return expect(this.data.memberGroupSubscriptions).to.deep.equal(
|
||||
expect(this.data.memberGroupSubscriptions).to.deep.equal(
|
||||
this.memberGroupSubscriptions
|
||||
)
|
||||
})
|
||||
|
||||
it('should load the user', function () {
|
||||
return expect(this.data.user).to.deep.equal(this.user)
|
||||
expect(this.data.user).to.deep.equal(this.user)
|
||||
})
|
||||
|
||||
it('should load the plans', function () {
|
||||
return expect(this.data.plans).to.deep.equal(this.plans)
|
||||
expect(this.data.plans).to.deep.equal(this.plans)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -452,7 +439,7 @@ describe('SubscriptionController', function () {
|
||||
beforeEach(function (done) {
|
||||
this.res = {
|
||||
sendStatus() {
|
||||
return done()
|
||||
done()
|
||||
},
|
||||
}
|
||||
sinon.spy(this.res, 'sendStatus')
|
||||
@@ -469,7 +456,7 @@ describe('SubscriptionController', function () {
|
||||
this.recurlyTokenIds.threeDSecureActionResult
|
||||
this.req.body.subscriptionDetails = this.subscriptionDetails
|
||||
this.LimitationsManager.userHasV1OrV2Subscription.yields(null, false)
|
||||
return this.SubscriptionController.createSubscription(this.req, this.res)
|
||||
this.SubscriptionController.createSubscription(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should send the user and subscriptionId to the handler', function (done) {
|
||||
@@ -480,12 +467,12 @@ describe('SubscriptionController', function () {
|
||||
this.recurlyTokenIds
|
||||
)
|
||||
.should.equal(true)
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
|
||||
it('should redurect to the subscription page', function (done) {
|
||||
this.res.sendStatus.calledWith(201).should.equal(true)
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -551,7 +538,7 @@ describe('SubscriptionController', function () {
|
||||
}
|
||||
)
|
||||
|
||||
return this.SubscriptionController.createSubscription(this.req, this.res)
|
||||
this.SubscriptionController.createSubscription(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should handle invalid error', function (done) {
|
||||
@@ -566,7 +553,7 @@ describe('SubscriptionController', function () {
|
||||
done()
|
||||
})
|
||||
|
||||
return this.SubscriptionController.createSubscription(this.req, this.res)
|
||||
this.SubscriptionController.createSubscription(this.req, this.res)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -574,25 +561,25 @@ describe('SubscriptionController', function () {
|
||||
beforeEach(function (done) {
|
||||
this.res = {
|
||||
redirect() {
|
||||
return done()
|
||||
done()
|
||||
},
|
||||
}
|
||||
sinon.spy(this.res, 'redirect')
|
||||
this.plan_code = '1234'
|
||||
this.req.body.plan_code = this.plan_code
|
||||
return this.SubscriptionController.updateSubscription(this.req, this.res)
|
||||
this.SubscriptionController.updateSubscription(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should send the user and subscriptionId to the handler', function (done) {
|
||||
this.SubscriptionHandler.updateSubscription
|
||||
.calledWith(this.user, this.plan_code)
|
||||
.should.equal(true)
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
|
||||
it('should redurect to the subscription page', function (done) {
|
||||
this.res.redirect.calledWith('/user/subscription').should.equal(true)
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -629,26 +616,23 @@ describe('SubscriptionController', function () {
|
||||
beforeEach(function (done) {
|
||||
this.res = {
|
||||
redirect() {
|
||||
return done()
|
||||
done()
|
||||
},
|
||||
}
|
||||
sinon.spy(this.res, 'redirect')
|
||||
return this.SubscriptionController.reactivateSubscription(
|
||||
this.req,
|
||||
this.res
|
||||
)
|
||||
this.SubscriptionController.reactivateSubscription(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should tell the handler to reactivate this user', function (done) {
|
||||
this.SubscriptionHandler.reactivateSubscription
|
||||
.calledWith(this.user)
|
||||
.should.equal(true)
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
|
||||
it('should redurect to the subscription page', function (done) {
|
||||
this.res.redirect.calledWith('/user/subscription').should.equal(true)
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -656,25 +640,25 @@ describe('SubscriptionController', function () {
|
||||
beforeEach(function (done) {
|
||||
this.res = {
|
||||
redirect() {
|
||||
return done()
|
||||
done()
|
||||
},
|
||||
}
|
||||
sinon.spy(this.res, 'redirect')
|
||||
return this.SubscriptionController.cancelSubscription(this.req, this.res)
|
||||
this.SubscriptionController.cancelSubscription(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should tell the handler to cancel this user', function (done) {
|
||||
this.SubscriptionHandler.cancelSubscription
|
||||
.calledWith(this.user)
|
||||
.should.equal(true)
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
|
||||
it('should redurect to the subscription page', function (done) {
|
||||
this.res.redirect
|
||||
.calledWith('/user/subscription/canceled')
|
||||
.should.equal(true)
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -699,21 +683,21 @@ describe('SubscriptionController', function () {
|
||||
}
|
||||
this.res = {
|
||||
sendStatus() {
|
||||
return done()
|
||||
done()
|
||||
},
|
||||
}
|
||||
sinon.spy(this.res, 'sendStatus')
|
||||
return this.SubscriptionController.recurlyCallback(this.req, this.res)
|
||||
this.SubscriptionController.recurlyCallback(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should tell the SubscriptionHandler to process the recurly callback', function (done) {
|
||||
this.SubscriptionHandler.syncSubscription.called.should.equal(true)
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
|
||||
it('should send a 200', function (done) {
|
||||
this.res.sendStatus.calledWith(200)
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -771,11 +755,11 @@ describe('SubscriptionController', function () {
|
||||
}
|
||||
this.res = {
|
||||
sendStatus() {
|
||||
return done()
|
||||
done()
|
||||
},
|
||||
}
|
||||
sinon.spy(this.res, 'sendStatus')
|
||||
return this.SubscriptionController.recurlyCallback(this.req, this.res)
|
||||
this.SubscriptionController.recurlyCallback(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should not call the subscriptionshandler', function () {
|
||||
@@ -786,7 +770,7 @@ describe('SubscriptionController', function () {
|
||||
})
|
||||
|
||||
it('should respond with a 200 status', function () {
|
||||
return this.res.sendStatus.calledWith(200)
|
||||
this.res.sendStatus.calledWith(200)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -796,9 +780,9 @@ describe('SubscriptionController', function () {
|
||||
this.LimitationsManager.userHasV2Subscription.callsArgWith(1, null, false)
|
||||
this.res.redirect = function (url) {
|
||||
url.should.equal('/user/subscription/plans')
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
return this.SubscriptionController.renderUpgradeToAnnualPlanPage(
|
||||
this.SubscriptionController.renderUpgradeToAnnualPlanPage(
|
||||
this.req,
|
||||
this.res
|
||||
)
|
||||
@@ -814,9 +798,9 @@ describe('SubscriptionController', function () {
|
||||
this.res.render = function (view, opts) {
|
||||
view.should.equal('subscriptions/upgradeToAnnual')
|
||||
opts.planName.should.equal('student')
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
return this.SubscriptionController.renderUpgradeToAnnualPlanPage(
|
||||
this.SubscriptionController.renderUpgradeToAnnualPlanPage(
|
||||
this.req,
|
||||
this.res
|
||||
)
|
||||
@@ -831,9 +815,9 @@ describe('SubscriptionController', function () {
|
||||
)
|
||||
this.res.render = function (view, opts) {
|
||||
opts.planName.should.equal('collaborator')
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
return this.SubscriptionController.renderUpgradeToAnnualPlanPage(
|
||||
this.SubscriptionController.renderUpgradeToAnnualPlanPage(
|
||||
this.req,
|
||||
this.res
|
||||
)
|
||||
@@ -848,9 +832,9 @@ describe('SubscriptionController', function () {
|
||||
)
|
||||
this.res.render = function (view, opts) {
|
||||
opts.planName.should.equal('annual')
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
return this.SubscriptionController.renderUpgradeToAnnualPlanPage(
|
||||
this.SubscriptionController.renderUpgradeToAnnualPlanPage(
|
||||
this.req,
|
||||
this.res
|
||||
)
|
||||
@@ -867,13 +851,10 @@ describe('SubscriptionController', function () {
|
||||
this.SubscriptionHandler.updateSubscription
|
||||
.calledWith(this.user, 'student-annual', 'STUDENTCODEHERE')
|
||||
.should.equal(true)
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
|
||||
return this.SubscriptionController.processUpgradeToAnnualPlan(
|
||||
this.req,
|
||||
this.res
|
||||
)
|
||||
this.SubscriptionController.processUpgradeToAnnualPlan(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should get the collaborator coupon code', function (done) {
|
||||
@@ -883,13 +864,10 @@ describe('SubscriptionController', function () {
|
||||
this.SubscriptionHandler.updateSubscription
|
||||
.calledWith(this.user, 'collaborator-annual', 'COLLABORATORCODEHERE')
|
||||
.should.equal(true)
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
|
||||
return this.SubscriptionController.processUpgradeToAnnualPlan(
|
||||
this.req,
|
||||
this.res
|
||||
)
|
||||
this.SubscriptionController.processUpgradeToAnnualPlan(this.req, this.res)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,21 +1,7 @@
|
||||
/* eslint-disable
|
||||
max-len,
|
||||
no-return-assign,
|
||||
no-unused-vars,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const sinon = require('sinon')
|
||||
const { assert } = require('chai')
|
||||
const modulePath =
|
||||
'../../../../app/src/Features/Subscription/SubscriptionGroupController'
|
||||
const MockResponse = require('../helpers/MockResponse')
|
||||
|
||||
describe('SubscriptionGroupController', function () {
|
||||
beforeEach(function () {
|
||||
@@ -55,13 +41,13 @@ describe('SubscriptionGroupController', function () {
|
||||
},
|
||||
}
|
||||
|
||||
return (this.Controller = SandboxedModule.require(modulePath, {
|
||||
this.Controller = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
'./SubscriptionGroupHandler': this.GroupHandler,
|
||||
'./SubscriptionLocator': this.SubscriptionLocator,
|
||||
'../Authentication/SessionManager': this.SessionManager,
|
||||
},
|
||||
}))
|
||||
})
|
||||
})
|
||||
|
||||
describe('removeUserFromGroup', function () {
|
||||
@@ -75,16 +61,15 @@ describe('SubscriptionGroupController', function () {
|
||||
this.GroupHandler.removeUserFromGroup
|
||||
.calledWith(this.subscriptionId, userIdToRemove)
|
||||
.should.equal(true)
|
||||
return done()
|
||||
done()
|
||||
},
|
||||
}
|
||||
return this.Controller.removeUserFromGroup(this.req, res)
|
||||
this.Controller.removeUserFromGroup(this.req, res)
|
||||
})
|
||||
})
|
||||
|
||||
describe('removeSelfFromGroup', function () {
|
||||
it('gets subscription and remove user', function (done) {
|
||||
const userIdToRemove = '31231'
|
||||
this.req.query = { subscriptionId: this.subscriptionId }
|
||||
const memberUserIdToremove = 123456789
|
||||
this.req.session.user._id = memberUserIdToremove
|
||||
@@ -100,10 +85,10 @@ describe('SubscriptionGroupController', function () {
|
||||
this.subscriptionId,
|
||||
memberUserIdToremove
|
||||
)
|
||||
return done()
|
||||
done()
|
||||
},
|
||||
}
|
||||
return this.Controller.removeSelfFromGroup(this.req, res)
|
||||
this.Controller.removeSelfFromGroup(this.req, res)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,20 +1,6 @@
|
||||
/* eslint-disable
|
||||
n/handle-callback-err,
|
||||
max-len,
|
||||
no-dupe-keys,
|
||||
no-return-assign,
|
||||
no-unused-vars,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const sinon = require('sinon')
|
||||
const { assert, expect } = require('chai')
|
||||
const { expect } = require('chai')
|
||||
const modulePath =
|
||||
'../../../../app/src/Features/Subscription/SubscriptionGroupHandler'
|
||||
|
||||
@@ -85,7 +71,7 @@ describe('SubscriptionGroupHandler', function () {
|
||||
},
|
||||
}
|
||||
|
||||
return (this.Handler = SandboxedModule.require(modulePath, {
|
||||
this.Handler = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
'../User/UserCreator': this.UserCreator,
|
||||
'./SubscriptionUpdater': this.SubscriptionUpdater,
|
||||
@@ -102,19 +88,20 @@ describe('SubscriptionGroupHandler', function () {
|
||||
'../UserMembership/UserMembershipViewModel':
|
||||
this.UserMembershipViewModel,
|
||||
},
|
||||
}))
|
||||
})
|
||||
})
|
||||
|
||||
describe('removeUserFromGroup', function () {
|
||||
it('should call the subscription updater to remove the user', function (done) {
|
||||
return this.Handler.removeUserFromGroup(
|
||||
this.Handler.removeUserFromGroup(
|
||||
this.adminUser_id,
|
||||
this.user._id,
|
||||
err => {
|
||||
if (err) return done(err)
|
||||
this.SubscriptionUpdater.removeUserFromGroup
|
||||
.calledWith(this.adminUser_id, this.user._id)
|
||||
.should.equal(true)
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
@@ -124,15 +111,13 @@ describe('SubscriptionGroupHandler', function () {
|
||||
beforeEach(function (done) {
|
||||
this.oldId = 'ba5eba11'
|
||||
this.newId = '5ca1ab1e'
|
||||
return this.Handler.replaceUserReferencesInGroups(
|
||||
this.oldId,
|
||||
this.newId,
|
||||
() => done()
|
||||
this.Handler.replaceUserReferencesInGroups(this.oldId, this.newId, () =>
|
||||
done()
|
||||
)
|
||||
})
|
||||
|
||||
it('replaces the admin_id', function () {
|
||||
return this.Subscription.updateOne
|
||||
this.Subscription.updateOne
|
||||
.calledWith({ admin_id: this.oldId }, { admin_id: this.newId })
|
||||
.should.equal(true)
|
||||
})
|
||||
@@ -145,7 +130,7 @@ describe('SubscriptionGroupHandler', function () {
|
||||
)
|
||||
.should.equal(true)
|
||||
|
||||
return this.Subscription.updateMany
|
||||
this.Subscription.updateMany
|
||||
.calledWith(
|
||||
{ manager_ids: 'ba5eba11' },
|
||||
{ $pull: { manager_ids: 'ba5eba11' } }
|
||||
@@ -161,7 +146,7 @@ describe('SubscriptionGroupHandler', function () {
|
||||
)
|
||||
.should.equal(true)
|
||||
|
||||
return this.Subscription.updateMany
|
||||
this.Subscription.updateMany
|
||||
.calledWith(
|
||||
{ member_ids: this.oldId },
|
||||
{ $pull: { member_ids: this.oldId } }
|
||||
@@ -172,7 +157,7 @@ describe('SubscriptionGroupHandler', function () {
|
||||
|
||||
describe('isUserPartOfGroup', function () {
|
||||
beforeEach(function () {
|
||||
return (this.subscription_id = '123ed13123')
|
||||
this.subscription_id = '123ed13123'
|
||||
})
|
||||
|
||||
it('should return true when user is part of subscription', function (done) {
|
||||
@@ -181,12 +166,13 @@ describe('SubscriptionGroupHandler', function () {
|
||||
null,
|
||||
{ _id: this.subscription_id }
|
||||
)
|
||||
return this.Handler.isUserPartOfGroup(
|
||||
this.Handler.isUserPartOfGroup(
|
||||
this.user_id,
|
||||
this.subscription_id,
|
||||
(err, partOfGroup) => {
|
||||
if (err) return done(err)
|
||||
partOfGroup.should.equal(true)
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
@@ -196,12 +182,13 @@ describe('SubscriptionGroupHandler', function () {
|
||||
2,
|
||||
null
|
||||
)
|
||||
return this.Handler.isUserPartOfGroup(
|
||||
this.Handler.isUserPartOfGroup(
|
||||
this.user_id,
|
||||
this.subscription_id,
|
||||
(err, partOfGroup) => {
|
||||
if (err) return done(err)
|
||||
partOfGroup.should.equal(false)
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
@@ -210,30 +197,29 @@ describe('SubscriptionGroupHandler', function () {
|
||||
describe('getTotalConfirmedUsersInGroup', function () {
|
||||
describe('for existing subscriptions', function () {
|
||||
beforeEach(function () {
|
||||
return (this.subscription.member_ids = ['12321', '3121321'])
|
||||
this.subscription.member_ids = ['12321', '3121321']
|
||||
})
|
||||
it('should call the subscription locator and return 2 users', function (done) {
|
||||
return this.Handler.getTotalConfirmedUsersInGroup(
|
||||
this.Handler.getTotalConfirmedUsersInGroup(
|
||||
this.subscription_id,
|
||||
(err, count) => {
|
||||
if (err) return done(err)
|
||||
this.SubscriptionLocator.getSubscription
|
||||
.calledWith(this.subscription_id)
|
||||
.should.equal(true)
|
||||
count.should.equal(2)
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
describe('for nonexistent subscriptions', function () {
|
||||
it('should return undefined', function (done) {
|
||||
return this.Handler.getTotalConfirmedUsersInGroup(
|
||||
'fake-id',
|
||||
(err, count) => {
|
||||
expect(count).not.to.exist
|
||||
return done()
|
||||
}
|
||||
)
|
||||
this.Handler.getTotalConfirmedUsersInGroup('fake-id', (err, count) => {
|
||||
if (err) return done(err)
|
||||
expect(count).not.to.exist
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,21 +1,7 @@
|
||||
/* eslint-disable
|
||||
n/handle-callback-err,
|
||||
max-len,
|
||||
no-return-assign,
|
||||
no-unused-vars,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const sinon = require('sinon')
|
||||
const modulePath =
|
||||
'../../../../app/src/Features/Subscription/SubscriptionLocator'
|
||||
const { assert } = require('chai')
|
||||
|
||||
describe('Subscription Locator Tests', function () {
|
||||
beforeEach(function () {
|
||||
@@ -29,7 +15,7 @@ describe('Subscription Locator Tests', function () {
|
||||
findOne: sinon.stub().yields(),
|
||||
find: sinon.stub().yields(),
|
||||
}
|
||||
return (this.SubscriptionLocator = SandboxedModule.require(modulePath, {
|
||||
this.SubscriptionLocator = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
'./GroupPlansData': {},
|
||||
'../../models/Subscription': {
|
||||
@@ -39,45 +25,47 @@ describe('Subscription Locator Tests', function () {
|
||||
DeletedSubscription: this.DeletedSubscription,
|
||||
},
|
||||
},
|
||||
}))
|
||||
})
|
||||
})
|
||||
|
||||
describe('finding users subscription', function () {
|
||||
it('should send the users features', function (done) {
|
||||
this.Subscription.findOne.callsArgWith(1, null, this.subscription)
|
||||
return this.SubscriptionLocator.getUsersSubscription(
|
||||
this.SubscriptionLocator.getUsersSubscription(
|
||||
this.user,
|
||||
(err, subscription) => {
|
||||
if (err) return done(err)
|
||||
this.Subscription.findOne
|
||||
.calledWith({ admin_id: this.user._id })
|
||||
.should.equal(true)
|
||||
subscription.should.equal(this.subscription)
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('should error if not found', function (done) {
|
||||
this.Subscription.findOne.callsArgWith(1, 'not found')
|
||||
return this.SubscriptionLocator.getUsersSubscription(
|
||||
this.SubscriptionLocator.getUsersSubscription(
|
||||
this.user,
|
||||
(err, subscription) => {
|
||||
err.should.exist
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('should take a user id rather than the user object', function (done) {
|
||||
this.Subscription.findOne.callsArgWith(1, null, this.subscription)
|
||||
return this.SubscriptionLocator.getUsersSubscription(
|
||||
this.SubscriptionLocator.getUsersSubscription(
|
||||
this.user._id,
|
||||
(err, subscription) => {
|
||||
if (err) return done(err)
|
||||
this.Subscription.findOne
|
||||
.calledWith({ admin_id: this.user._id })
|
||||
.should.equal(true)
|
||||
subscription.should.equal(this.subscription)
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
@@ -1,19 +1,4 @@
|
||||
/* eslint-disable
|
||||
camelcase,
|
||||
n/handle-callback-err,
|
||||
max-len,
|
||||
no-return-assign,
|
||||
no-unused-vars,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const assert = require('assert')
|
||||
const path = require('path')
|
||||
const modulePath = path.join(
|
||||
__dirname,
|
||||
@@ -45,13 +30,13 @@ describe('V1SubscriptionManager', function () {
|
||||
})
|
||||
this.userId = 'abcd'
|
||||
this.v1UserId = 42
|
||||
return (this.user = {
|
||||
this.user = {
|
||||
_id: this.userId,
|
||||
email: 'user@example.com',
|
||||
overleaf: {
|
||||
id: this.v1UserId,
|
||||
},
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
describe('getGrandfatheredFeaturesForV1User', function () {
|
||||
@@ -60,7 +45,7 @@ describe('V1SubscriptionManager', function () {
|
||||
expect(
|
||||
this.V1SubscriptionManager.getGrandfatheredFeaturesForV1User(100)
|
||||
).to.eql({})
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -72,14 +57,14 @@ describe('V1SubscriptionManager', function () {
|
||||
github: true,
|
||||
mendeley: true,
|
||||
})
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('_v1Request', function () {
|
||||
beforeEach(function () {
|
||||
return (this.UserGetter.getUser = sinon.stub().yields(null, this.user))
|
||||
this.UserGetter.getUser = sinon.stub().yields(null, this.user)
|
||||
})
|
||||
|
||||
describe('when v1IdForUser produces an error', function () {
|
||||
@@ -87,8 +72,8 @@ describe('V1SubscriptionManager', function () {
|
||||
this.V1SubscriptionManager.v1IdForUser = sinon
|
||||
.stub()
|
||||
.yields(new Error('woops'))
|
||||
return (this.call = cb => {
|
||||
return this.V1SubscriptionManager._v1Request(
|
||||
this.call = cb => {
|
||||
this.V1SubscriptionManager._v1Request(
|
||||
this.user_id,
|
||||
{
|
||||
url() {
|
||||
@@ -97,20 +82,20 @@ describe('V1SubscriptionManager', function () {
|
||||
},
|
||||
cb
|
||||
)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
it('should not call request', function (done) {
|
||||
return this.call((err, planCode) => {
|
||||
this.call(() => {
|
||||
expect(this.request.callCount).to.equal(0)
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should produce an error', function (done) {
|
||||
return this.call((err, planCode) => {
|
||||
this.call((err, planCode) => {
|
||||
expect(err).to.exist
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -118,8 +103,8 @@ describe('V1SubscriptionManager', function () {
|
||||
describe('when v1IdForUser does not find a user', function () {
|
||||
beforeEach(function () {
|
||||
this.V1SubscriptionManager.v1IdForUser = sinon.stub().yields(null, null)
|
||||
return (this.call = cb => {
|
||||
return this.V1SubscriptionManager._v1Request(
|
||||
this.call = cb => {
|
||||
this.V1SubscriptionManager._v1Request(
|
||||
this.user_id,
|
||||
{
|
||||
url() {
|
||||
@@ -128,20 +113,21 @@ describe('V1SubscriptionManager', function () {
|
||||
},
|
||||
cb
|
||||
)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
it('should not call request', function (done) {
|
||||
return this.call((err, planCode) => {
|
||||
this.call((err, planCode) => {
|
||||
if (err) return done(err)
|
||||
expect(this.request.callCount).to.equal(0)
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should not error', function (done) {
|
||||
return this.call(err => {
|
||||
this.call(err => {
|
||||
expect(err).to.not.exist
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -149,8 +135,8 @@ describe('V1SubscriptionManager', function () {
|
||||
describe('when the request to v1 fails', function () {
|
||||
beforeEach(function () {
|
||||
this.request.yields(new Error('woops'))
|
||||
return (this.call = cb => {
|
||||
return this.V1SubscriptionManager._v1Request(
|
||||
this.call = cb => {
|
||||
this.V1SubscriptionManager._v1Request(
|
||||
this.user_id,
|
||||
{
|
||||
url() {
|
||||
@@ -159,13 +145,13 @@ describe('V1SubscriptionManager', function () {
|
||||
},
|
||||
cb
|
||||
)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
it('should produce an error', function (done) {
|
||||
return this.call(err => {
|
||||
this.call(err => {
|
||||
expect(err).to.exist
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -176,8 +162,8 @@ describe('V1SubscriptionManager', function () {
|
||||
.stub()
|
||||
.yields(null, this.v1UserId)
|
||||
this.request.yields(null, { statusCode: 200 }, '{}')
|
||||
return (this.call = cb => {
|
||||
return this.V1SubscriptionManager._v1Request(
|
||||
this.call = cb => {
|
||||
this.V1SubscriptionManager._v1Request(
|
||||
this.user_id,
|
||||
{
|
||||
method: 'GET',
|
||||
@@ -187,39 +173,42 @@ describe('V1SubscriptionManager', function () {
|
||||
},
|
||||
cb
|
||||
)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
it('should not produce an error', function (done) {
|
||||
return this.call((err, body, v1Id) => {
|
||||
this.call((err, body, v1Id) => {
|
||||
expect(err).not.to.exist
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should have supplied retry options to request', function (done) {
|
||||
return this.call((err, body, v1Id) => {
|
||||
this.call((err, body, v1Id) => {
|
||||
if (err) return done(err)
|
||||
const requestOptions = this.request.lastCall.args[0]
|
||||
expect(requestOptions.url).to.equal('/foo')
|
||||
expect(requestOptions.maxAttempts).to.exist
|
||||
expect(requestOptions.maxAttempts > 0).to.be.true
|
||||
expect(requestOptions.retryDelay).to.exist
|
||||
expect(requestOptions.retryDelay > 0).to.be.true
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should return the v1 user id', function (done) {
|
||||
return this.call((err, body, v1Id) => {
|
||||
this.call((err, body, v1Id) => {
|
||||
if (err) return done(err)
|
||||
expect(v1Id).to.equal(this.v1UserId)
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should return the http response body', function (done) {
|
||||
return this.call((err, body, v1Id) => {
|
||||
this.call((err, body, v1Id) => {
|
||||
if (err) return done(err)
|
||||
expect(body).to.equal('{}')
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -230,8 +219,8 @@ describe('V1SubscriptionManager', function () {
|
||||
.stub()
|
||||
.yields(null, this.v1UserId)
|
||||
this.request.yields(null, { statusCode: 500 }, '{}')
|
||||
return (this.call = cb => {
|
||||
return this.V1SubscriptionManager._v1Request(
|
||||
this.call = cb => {
|
||||
this.V1SubscriptionManager._v1Request(
|
||||
this.user_id,
|
||||
{
|
||||
url() {
|
||||
@@ -240,13 +229,13 @@ describe('V1SubscriptionManager', function () {
|
||||
},
|
||||
cb
|
||||
)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
it('should produce an error', function (done) {
|
||||
return this.call((err, body, v1Id) => {
|
||||
this.call((err, body, v1Id) => {
|
||||
expect(err).to.exist
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -257,8 +246,8 @@ describe('V1SubscriptionManager', function () {
|
||||
.stub()
|
||||
.yields(null, this.v1UserId)
|
||||
this.request.yields(null, { statusCode: 404 }, '{}')
|
||||
return (this.call = cb => {
|
||||
return this.V1SubscriptionManager._v1Request(
|
||||
this.call = cb => {
|
||||
this.V1SubscriptionManager._v1Request(
|
||||
this.user_id,
|
||||
{
|
||||
url() {
|
||||
@@ -267,14 +256,14 @@ describe('V1SubscriptionManager', function () {
|
||||
},
|
||||
cb
|
||||
)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
it('should produce an not-found error', function (done) {
|
||||
return this.call((err, body, v1Id) => {
|
||||
this.call((err, body, v1Id) => {
|
||||
expect(err).to.exist
|
||||
expect(err.name).to.equal('NotFoundError')
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -282,21 +271,21 @@ describe('V1SubscriptionManager', function () {
|
||||
|
||||
describe('v1IdForUser', function () {
|
||||
beforeEach(function () {
|
||||
return (this.UserGetter.getUser = sinon.stub().yields(null, this.user))
|
||||
this.UserGetter.getUser = sinon.stub().yields(null, this.user)
|
||||
})
|
||||
|
||||
describe('when getUser produces an error', function () {
|
||||
beforeEach(function () {
|
||||
this.UserGetter.getUser = sinon.stub().yields(new Error('woops'))
|
||||
return (this.call = cb => {
|
||||
return this.V1SubscriptionManager.v1IdForUser(this.user_id, cb)
|
||||
})
|
||||
this.call = cb => {
|
||||
this.V1SubscriptionManager.v1IdForUser(this.user_id, cb)
|
||||
}
|
||||
})
|
||||
|
||||
it('should produce an error', function (done) {
|
||||
return this.call(err => {
|
||||
this.call(err => {
|
||||
expect(err).to.exist
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -304,37 +293,38 @@ describe('V1SubscriptionManager', function () {
|
||||
describe('when getUser does not find a user', function () {
|
||||
beforeEach(function () {
|
||||
this.UserGetter.getUser = sinon.stub().yields(null, null)
|
||||
return (this.call = cb => {
|
||||
return this.V1SubscriptionManager.v1IdForUser(this.user_id, cb)
|
||||
})
|
||||
this.call = cb => {
|
||||
this.V1SubscriptionManager.v1IdForUser(this.user_id, cb)
|
||||
}
|
||||
})
|
||||
|
||||
it('should not error', function (done) {
|
||||
return this.call((err, user_id) => {
|
||||
this.call((err, userId) => {
|
||||
expect(err).to.not.exist
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('when it works', function () {
|
||||
beforeEach(function () {
|
||||
return (this.call = cb => {
|
||||
return this.V1SubscriptionManager.v1IdForUser(this.user_id, cb)
|
||||
})
|
||||
this.call = cb => {
|
||||
this.V1SubscriptionManager.v1IdForUser(this.user_id, cb)
|
||||
}
|
||||
})
|
||||
|
||||
it('should not error', function (done) {
|
||||
return this.call((err, user_id) => {
|
||||
this.call((err, userId) => {
|
||||
expect(err).to.not.exist
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should return the v1 user id', function (done) {
|
||||
return this.call((err, user_id) => {
|
||||
expect(user_id).to.eql(42)
|
||||
return done()
|
||||
this.call((err, userId) => {
|
||||
if (err) return done(err)
|
||||
expect(userId).to.eql(42)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user