Merge pull request #3495 from overleaf/ae-prettier-2

Upgrade Prettier to v2

GitOrigin-RevId: 85aa3fa1acb6332c4f58c46165a43d1a51471f33
This commit is contained in:
Alf Eaton
2021-04-14 14:17:21 +01:00
committed by Copybot
parent 930d7ba028
commit 1ebc8a79cb
582 changed files with 20382 additions and 20374 deletions
@@ -4,8 +4,8 @@ const sinon = require('sinon')
const modulePath = '../../../../app/src/Features/Subscription/FeaturesUpdater'
const { ObjectId } = require('mongodb')
describe('FeaturesUpdater', function() {
beforeEach(function() {
describe('FeaturesUpdater', function () {
beforeEach(function () {
this.user_id = ObjectId().toString()
this.FeaturesUpdater = SandboxedModule.require(modulePath, {
@@ -25,8 +25,8 @@ describe('FeaturesUpdater', function() {
})
})
describe('refreshFeatures', function() {
beforeEach(function() {
describe('refreshFeatures', function () {
beforeEach(function () {
this.user = {
_id: this.user_id,
features: {}
@@ -56,7 +56,7 @@ describe('FeaturesUpdater', function() {
this.callback = sinon.stub()
})
it('should return features and featuresChanged', function() {
it('should return features and featuresChanged', function () {
this.FeaturesUpdater.refreshFeatures(
this.user_id,
(err, features, featuresChanged) => {
@@ -67,54 +67,54 @@ describe('FeaturesUpdater', function() {
)
})
describe('normally', function() {
beforeEach(function() {
describe('normally', function () {
beforeEach(function () {
this.FeaturesUpdater.refreshFeatures(this.user_id, this.callback)
})
it('should get the individual features', function() {
it('should get the individual features', function () {
this.FeaturesUpdater._getIndividualFeatures
.calledWith(this.user_id)
.should.equal(true)
})
it('should get the group features', function() {
it('should get the group features', function () {
this.FeaturesUpdater._getGroupFeatureSets
.calledWith(this.user_id)
.should.equal(true)
})
it('should get the institution features', function() {
it('should get the institution features', function () {
this.InstitutionsFeatures.getInstitutionsFeatures
.calledWith(this.user_id)
.should.equal(true)
})
it('should get the v1 features', function() {
it('should get the v1 features', function () {
this.FeaturesUpdater._getV1Features
.calledWith(this.user_id)
.should.equal(true)
})
it('should get the bonus features', function() {
it('should get the bonus features', function () {
this.ReferalFeatures.getBonusFeatures
.calledWith(this.user_id)
.should.equal(true)
})
it('should merge from the default features', function() {
it('should merge from the default features', function () {
this.FeaturesUpdater._mergeFeatures
.calledWith(this.Settings.defaultFeatures)
.should.equal(true)
})
it('should merge the individual features', function() {
it('should merge the individual features', function () {
this.FeaturesUpdater._mergeFeatures
.calledWith(sinon.match.any, { individual: 'features' })
.should.equal(true)
})
it('should merge the group features', function() {
it('should merge the group features', function () {
this.FeaturesUpdater._mergeFeatures
.calledWith(sinon.match.any, { group: 'features' })
.should.equal(true)
@@ -123,32 +123,32 @@ describe('FeaturesUpdater', function() {
.should.equal(true)
})
it('should merge the institutions features', function() {
it('should merge the institutions features', function () {
this.FeaturesUpdater._mergeFeatures
.calledWith(sinon.match.any, { institutions: 'features' })
.should.equal(true)
})
it('should merge the v1 features', function() {
it('should merge the v1 features', function () {
this.FeaturesUpdater._mergeFeatures
.calledWith(sinon.match.any, { v1: 'features' })
.should.equal(true)
})
it('should merge the bonus features', function() {
it('should merge the bonus features', function () {
this.FeaturesUpdater._mergeFeatures
.calledWith(sinon.match.any, { bonus: 'features' })
.should.equal(true)
})
it('should update the user with the merged features', function() {
it('should update the user with the merged features', function () {
this.UserFeaturesUpdater.updateFeatures
.calledWith(this.user_id, { merged: 'features' })
.should.equal(true)
})
})
describe('when losing dropbox feature', function() {
beforeEach(function() {
describe('when losing dropbox feature', function () {
beforeEach(function () {
this.user = {
_id: this.user_id,
features: { dropbox: true }
@@ -159,7 +159,7 @@ describe('FeaturesUpdater', function() {
.returns({ dropbox: false })
this.FeaturesUpdater.refreshFeatures(this.user_id, this.callback)
})
it('should fire module hook to unlink dropbox', function() {
it('should fire module hook to unlink dropbox', function () {
this.Modules.hooks.fire
.calledWith('removeDropbox', this.user._id)
.should.equal(true)
@@ -167,8 +167,8 @@ describe('FeaturesUpdater', function() {
})
})
describe('_mergeFeatures', function() {
it('should prefer priority over standard for compileGroup', function() {
describe('_mergeFeatures', function () {
it('should prefer priority over standard for compileGroup', function () {
expect(
this.FeaturesUpdater._mergeFeatures(
{
@@ -219,7 +219,7 @@ describe('FeaturesUpdater', function() {
})
})
it('should prefer -1 over any other for collaborators', function() {
it('should prefer -1 over any other for collaborators', function () {
expect(
this.FeaturesUpdater._mergeFeatures(
{
@@ -258,7 +258,7 @@ describe('FeaturesUpdater', function() {
})
})
it('should prefer the higher of compileTimeout', function() {
it('should prefer the higher of compileTimeout', function () {
expect(
this.FeaturesUpdater._mergeFeatures(
{
@@ -285,7 +285,7 @@ describe('FeaturesUpdater', function() {
})
})
it('should prefer the true over false for other keys', function() {
it('should prefer the true over false for other keys', function () {
expect(
this.FeaturesUpdater._mergeFeatures(
{
@@ -337,8 +337,8 @@ describe('FeaturesUpdater', function() {
})
})
describe('doSyncFromV1', function() {
beforeEach(function() {
describe('doSyncFromV1', function () {
beforeEach(function () {
this.v1UserId = 1
this.user = {
_id: this.user_id,
@@ -355,8 +355,8 @@ describe('FeaturesUpdater', function() {
}
})
describe('when all goes well', function() {
it('should call getUser', function(done) {
describe('when all goes well', function () {
it('should call getUser', function (done) {
this.call(() => {
expect(this.UserGetter.getUser.callCount).to.equal(1)
expect(
@@ -366,7 +366,7 @@ describe('FeaturesUpdater', function() {
})
})
it('should call refreshFeatures', function(done) {
it('should call refreshFeatures', function (done) {
this.call(() => {
expect(this.FeaturesUpdater.refreshFeatures.callCount).to.equal(1)
expect(
@@ -376,7 +376,7 @@ describe('FeaturesUpdater', function() {
})
})
it('should not produce an error', function(done) {
it('should not produce an error', function (done) {
this.call(err => {
expect(err).to.not.exist
done()
@@ -384,18 +384,18 @@ describe('FeaturesUpdater', function() {
})
})
describe('when getUser produces an error', function() {
beforeEach(function() {
describe('when getUser produces an error', function () {
beforeEach(function () {
this.UserGetter.getUser = sinon
.stub()
.callsArgWith(2, new Error('woops'))
})
it('should not call refreshFeatures', function() {
it('should not call refreshFeatures', function () {
expect(this.FeaturesUpdater.refreshFeatures.callCount).to.equal(0)
})
it('should produce an error', function(done) {
it('should produce an error', function (done) {
this.call(err => {
expect(err).to.exist
done()
@@ -403,19 +403,19 @@ describe('FeaturesUpdater', function() {
})
})
describe('when getUser does not find a user', function() {
beforeEach(function() {
describe('when getUser does not find a user', function () {
beforeEach(function () {
this.UserGetter.getUser = sinon.stub().callsArgWith(2, null, null)
})
it('should not call refreshFeatures', function(done) {
it('should not call refreshFeatures', function (done) {
this.call(() => {
expect(this.FeaturesUpdater.refreshFeatures.callCount).to.equal(0)
done()
})
})
it('should not produce an error', function(done) {
it('should not produce an error', function (done) {
this.call(err => {
expect(err).to.not.exist
done()
@@ -19,8 +19,8 @@ const modulePath = require('path').join(
'../../../../app/src/Features/Subscription/LimitationsManager'
)
describe('LimitationsManager', function() {
beforeEach(function() {
describe('LimitationsManager', function () {
beforeEach(function () {
this.project = { _id: (this.project_id = 'project-id') }
this.user = { _id: (this.user_id = 'user-id'), features: {} }
this.ProjectGetter = {
@@ -60,9 +60,9 @@ describe('LimitationsManager', function() {
}))
})
describe('allowedNumberOfCollaboratorsInProject', function() {
describe('when the project is owned by a user without a subscription', function() {
beforeEach(function() {
describe('allowedNumberOfCollaboratorsInProject', function () {
describe('when the project is owned by a user without a subscription', function () {
beforeEach(function () {
this.Settings.defaultFeatures = { collaborators: 23 }
this.project.owner_ref = this.user_id
delete this.user.features
@@ -73,15 +73,15 @@ describe('LimitationsManager', function() {
)
})
it('should return the default number', function() {
it('should return the default number', function () {
return this.callback
.calledWith(null, this.Settings.defaultFeatures.collaborators)
.should.equal(true)
})
})
describe('when the project is owned by a user with a subscription', function() {
beforeEach(function() {
describe('when the project is owned by a user with a subscription', function () {
beforeEach(function () {
this.project.owner_ref = this.user_id
this.user.features = { collaborators: 21 }
this.callback = sinon.stub()
@@ -91,7 +91,7 @@ describe('LimitationsManager', function() {
)
})
it('should return the number of collaborators the user is allowed', function() {
it('should return the number of collaborators the user is allowed', function () {
return this.callback
.calledWith(null, this.user.features.collaborators)
.should.equal(true)
@@ -99,9 +99,9 @@ describe('LimitationsManager', function() {
})
})
describe('allowedNumberOfCollaboratorsForUser', function() {
describe('when the user has no features', function() {
beforeEach(function() {
describe('allowedNumberOfCollaboratorsForUser', function () {
describe('when the user has no features', function () {
beforeEach(function () {
this.Settings.defaultFeatures = { collaborators: 23 }
delete this.user.features
this.callback = sinon.stub()
@@ -111,15 +111,15 @@ describe('LimitationsManager', function() {
)
})
it('should return the default number', function() {
it('should return the default number', function () {
return this.callback
.calledWith(null, this.Settings.defaultFeatures.collaborators)
.should.equal(true)
})
})
describe('when the user has features', function() {
beforeEach(function() {
describe('when the user has features', function () {
beforeEach(function () {
this.user.features = { collaborators: 21 }
this.callback = sinon.stub()
return this.LimitationsManager.allowedNumberOfCollaboratorsForUser(
@@ -128,7 +128,7 @@ describe('LimitationsManager', function() {
)
})
it('should return the number of collaborators the user is allowed', function() {
it('should return the number of collaborators the user is allowed', function () {
return this.callback
.calledWith(null, this.user.features.collaborators)
.should.equal(true)
@@ -136,9 +136,9 @@ describe('LimitationsManager', function() {
})
})
describe('canAddXCollaborators', function() {
describe('when the project has fewer collaborators than allowed', function() {
beforeEach(function() {
describe('canAddXCollaborators', function () {
describe('when the project has fewer collaborators than allowed', function () {
beforeEach(function () {
this.current_number = 1
this.allowed_number = 2
this.invite_count = 0
@@ -166,13 +166,13 @@ describe('LimitationsManager', function() {
)
})
it('should return true', function() {
it('should return true', function () {
return this.callback.calledWith(null, true).should.equal(true)
})
})
describe('when the project has fewer collaborators and invites than allowed', function() {
beforeEach(function() {
describe('when the project has fewer collaborators and invites than allowed', function () {
beforeEach(function () {
this.current_number = 1
this.allowed_number = 4
this.invite_count = 1
@@ -200,13 +200,13 @@ describe('LimitationsManager', function() {
)
})
it('should return true', function() {
it('should return true', function () {
return this.callback.calledWith(null, true).should.equal(true)
})
})
describe('when the project has fewer collaborators than allowed but I want to add more than allowed', function() {
beforeEach(function() {
describe('when the project has fewer collaborators than allowed but I want to add more than allowed', function () {
beforeEach(function () {
this.current_number = 1
this.allowed_number = 2
this.invite_count = 0
@@ -234,13 +234,13 @@ describe('LimitationsManager', function() {
)
})
it('should return false', function() {
it('should return false', function () {
return this.callback.calledWith(null, false).should.equal(true)
})
})
describe('when the project has more collaborators than allowed', function() {
beforeEach(function() {
describe('when the project has more collaborators than allowed', function () {
beforeEach(function () {
this.current_number = 3
this.allowed_number = 2
this.invite_count = 0
@@ -268,13 +268,13 @@ describe('LimitationsManager', function() {
)
})
it('should return false', function() {
it('should return false', function () {
return this.callback.calledWith(null, false).should.equal(true)
})
})
describe('when the project has infinite collaborators', function() {
beforeEach(function() {
describe('when the project has infinite collaborators', function () {
beforeEach(function () {
this.current_number = 100
this.allowed_number = -1
this.invite_count = 0
@@ -302,13 +302,13 @@ describe('LimitationsManager', function() {
)
})
it('should return true', function() {
it('should return true', function () {
return this.callback.calledWith(null, true).should.equal(true)
})
})
describe('when the project has more invites than allowed', function() {
beforeEach(function() {
describe('when the project has more invites than allowed', function () {
beforeEach(function () {
this.current_number = 0
this.allowed_number = 2
this.invite_count = 2
@@ -336,13 +336,13 @@ describe('LimitationsManager', function() {
)
})
it('should return false', function() {
it('should return false', function () {
return this.callback.calledWith(null, false).should.equal(true)
})
})
describe('when the project has more invites and collaborators than allowed', function() {
beforeEach(function() {
describe('when the project has more invites and collaborators than allowed', function () {
beforeEach(function () {
this.current_number = 1
this.allowed_number = 2
this.invite_count = 1
@@ -370,18 +370,18 @@ describe('LimitationsManager', function() {
)
})
it('should return false', function() {
it('should return false', function () {
return this.callback.calledWith(null, false).should.equal(true)
})
})
})
describe('userHasV2Subscription', function() {
beforeEach(function() {
describe('userHasV2Subscription', function () {
beforeEach(function () {
return (this.SubscriptionLocator.getUsersSubscription = sinon.stub())
})
it('should return true if the recurly token is set', function(done) {
it('should return true if the recurly token is set', function (done) {
this.SubscriptionLocator.getUsersSubscription.callsArgWith(1, null, {
recurlySubscription_id: '1234'
})
@@ -394,7 +394,7 @@ describe('LimitationsManager', function() {
)
})
it('should return false if the recurly token is not set', function(done) {
it('should return false if the recurly token is not set', function (done) {
this.SubscriptionLocator.getUsersSubscription.callsArgWith(1, null, {})
this.subscription = {}
return this.LimitationsManager.userHasV2Subscription(
@@ -406,7 +406,7 @@ describe('LimitationsManager', function() {
)
})
it('should return false if the subscription is undefined', function(done) {
it('should return false if the subscription is undefined', function (done) {
this.SubscriptionLocator.getUsersSubscription.callsArgWith(1)
return this.LimitationsManager.userHasV2Subscription(
this.user,
@@ -417,7 +417,7 @@ describe('LimitationsManager', function() {
)
})
it('should return the subscription', function(done) {
it('should return the subscription', function (done) {
const stubbedSubscription = { freeTrial: {}, token: '' }
this.SubscriptionLocator.getUsersSubscription.callsArgWith(
1,
@@ -433,8 +433,8 @@ describe('LimitationsManager', function() {
)
})
describe('when user has a custom account', function() {
beforeEach(function() {
describe('when user has a custom account', function () {
beforeEach(function () {
this.fakeSubscription = { customAccount: true }
return this.SubscriptionLocator.getUsersSubscription.callsArgWith(
1,
@@ -443,7 +443,7 @@ describe('LimitationsManager', function() {
)
})
it('should return true', function(done) {
it('should return true', function (done) {
return this.LimitationsManager.userHasV2Subscription(
this.user,
(err, hasSubscription, subscription) => {
@@ -453,7 +453,7 @@ describe('LimitationsManager', function() {
)
})
it('should return the subscription', function(done) {
it('should return the subscription', function (done) {
return this.LimitationsManager.userHasV2Subscription(
this.user,
(err, hasSubscription, subscription) => {
@@ -465,12 +465,12 @@ describe('LimitationsManager', function() {
})
})
describe('userIsMemberOfGroupSubscription', function() {
beforeEach(function() {
describe('userIsMemberOfGroupSubscription', function () {
beforeEach(function () {
return (this.SubscriptionLocator.getMemberSubscriptions = sinon.stub())
})
it('should return false if there are no groups subcriptions', function(done) {
it('should return false if there are no groups subcriptions', function (done) {
this.SubscriptionLocator.getMemberSubscriptions.callsArgWith(1, null, [])
return this.LimitationsManager.userIsMemberOfGroupSubscription(
this.user,
@@ -481,7 +481,7 @@ describe('LimitationsManager', function() {
)
})
it('should return true if there are no groups subcriptions', function(done) {
it('should return true if there are no groups subcriptions', function (done) {
let subscriptions
this.SubscriptionLocator.getMemberSubscriptions.callsArgWith(
1,
@@ -499,8 +499,8 @@ describe('LimitationsManager', function() {
})
})
describe('hasPaidSubscription', function() {
beforeEach(function() {
describe('hasPaidSubscription', function () {
beforeEach(function () {
this.LimitationsManager.userIsMemberOfGroupSubscription = sinon
.stub()
.yields(null, false)
@@ -512,7 +512,7 @@ describe('LimitationsManager', function() {
.yields(null, false))
})
it('should return true if userIsMemberOfGroupSubscription', function(done) {
it('should return true if userIsMemberOfGroupSubscription', function (done) {
this.LimitationsManager.userIsMemberOfGroupSubscription = sinon
.stub()
.yields(null, true)
@@ -525,7 +525,7 @@ describe('LimitationsManager', function() {
)
})
it('should return true if userHasV2Subscription', function(done) {
it('should return true if userHasV2Subscription', function (done) {
this.LimitationsManager.userHasV2Subscription = sinon
.stub()
.yields(null, true)
@@ -538,7 +538,7 @@ describe('LimitationsManager', function() {
)
})
it('should return true if userHasV1Subscription', function(done) {
it('should return true if userHasV1Subscription', function (done) {
this.LimitationsManager.userHasV1Subscription = sinon
.stub()
.yields(null, true)
@@ -551,7 +551,7 @@ describe('LimitationsManager', function() {
)
})
it('should return false if none are true', function(done) {
it('should return false if none are true', function (done) {
return this.LimitationsManager.hasPaidSubscription(
this.user,
(err, hasSubOrIsGroupMember) => {
@@ -561,7 +561,7 @@ describe('LimitationsManager', function() {
)
})
it('should have userHasSubscriptionOrIsGroupMember alias', function(done) {
it('should have userHasSubscriptionOrIsGroupMember alias', function (done) {
return this.LimitationsManager.userHasSubscriptionOrIsGroupMember(
this.user,
(err, hasSubOrIsGroupMember) => {
@@ -572,8 +572,8 @@ describe('LimitationsManager', function() {
})
})
describe('userHasV1OrV2Subscription', function() {
beforeEach(function() {
describe('userHasV1OrV2Subscription', function () {
beforeEach(function () {
this.LimitationsManager.userHasV2Subscription = sinon
.stub()
.yields(null, false)
@@ -582,7 +582,7 @@ describe('LimitationsManager', function() {
.yields(null, false))
})
it('should return true if userHasV2Subscription', function(done) {
it('should return true if userHasV2Subscription', function (done) {
this.LimitationsManager.userHasV2Subscription = sinon
.stub()
.yields(null, true)
@@ -595,7 +595,7 @@ describe('LimitationsManager', function() {
)
})
it('should return true if userHasV1Subscription', function(done) {
it('should return true if userHasV1Subscription', function (done) {
this.LimitationsManager.userHasV1Subscription = sinon
.stub()
.yields(null, true)
@@ -608,7 +608,7 @@ describe('LimitationsManager', function() {
)
})
it('should return false if none are true', function(done) {
it('should return false if none are true', function (done) {
return this.LimitationsManager.userHasV1OrV2Subscription(
this.user,
(err, hasSub) => {
@@ -619,8 +619,8 @@ describe('LimitationsManager', function() {
})
})
describe('hasGroupMembersLimitReached', function() {
beforeEach(function() {
describe('hasGroupMembersLimitReached', function () {
beforeEach(function () {
this.subscriptionId = '12312'
return (this.subscription = {
membersLimit: 3,
@@ -631,7 +631,7 @@ describe('LimitationsManager', function() {
})
})
it('should return true if the limit is hit (including members and invites)', function(done) {
it('should return true if the limit is hit (including members and invites)', function (done) {
this.SubscriptionLocator.getSubscription.callsArgWith(
1,
null,
@@ -646,7 +646,7 @@ describe('LimitationsManager', function() {
)
})
it('should return false if the limit is not hit (including members and invites)', function(done) {
it('should return false if the limit is not hit (including members and invites)', function (done) {
this.subscription.membersLimit = 4
this.SubscriptionLocator.getSubscription.callsArgWith(
1,
@@ -662,7 +662,7 @@ describe('LimitationsManager', function() {
)
})
it('should return true if the limit has been exceded (including members and invites)', function(done) {
it('should return true if the limit has been exceded (including members and invites)', function (done) {
this.subscription.membersLimit = 2
this.SubscriptionLocator.getSubscription.callsArgWith(
1,
@@ -679,8 +679,8 @@ describe('LimitationsManager', function() {
})
})
describe('userHasV1Subscription', function() {
it('should return true if v1 returns has_subscription = true', function(done) {
describe('userHasV1Subscription', function () {
it('should return true if v1 returns has_subscription = true', function (done) {
this.V1SubscriptionManager.getSubscriptionsFromV1 = sinon
.stub()
.yields(null, { has_subscription: true })
@@ -696,7 +696,7 @@ describe('LimitationsManager', function() {
)
})
it('should return false if v1 returns has_subscription = false', function(done) {
it('should return false if v1 returns has_subscription = false', function (done) {
this.V1SubscriptionManager.getSubscriptionsFromV1 = sinon
.stub()
.yields(null, { has_subscription: false })
@@ -712,7 +712,7 @@ describe('LimitationsManager', function() {
)
})
it('should return false if v1 returns nothing', function(done) {
it('should return false if v1 returns nothing', function (done) {
this.V1SubscriptionManager.getSubscriptionsFromV1 = sinon
.stub()
.yields(null, null)
@@ -9,8 +9,8 @@ const recurly = require('recurly')
const modulePath = '../../../../app/src/Features/Subscription/RecurlyClient'
const SandboxedModule = require('sandboxed-module')
describe('RecurlyClient', function() {
beforeEach(function() {
describe('RecurlyClient', function () {
beforeEach(function () {
this.settings = {
apis: {
recurly: {
@@ -40,7 +40,7 @@ describe('RecurlyClient', function() {
}
this.recurly = {
errors: recurly.errors,
Client: function() {
Client: function () {
return client
}
}
@@ -64,8 +64,8 @@ describe('RecurlyClient', function() {
}))
})
describe('initalizing recurly client with undefined API key parameter', function() {
it('should create a client without error', function() {
describe('initalizing recurly client with undefined API key parameter', function () {
it('should create a client without error', function () {
let testClient
expect(() => {
testClient = new recurly.Client(undefined)
@@ -74,8 +74,8 @@ describe('RecurlyClient', function() {
})
})
describe('getAccountForUserId', function() {
it('should return an Account if one exists', async function() {
describe('getAccountForUserId', function () {
it('should return an Account if one exists', async function () {
this.client.getAccount = sinon.stub().resolves(this.recurlyAccount)
await expect(
this.RecurlyClient.promises.getAccountForUserId(this.user._id)
@@ -84,7 +84,7 @@ describe('RecurlyClient', function() {
.that.has.property('code', this.user._id)
})
it('should return nothing if no account found', async function() {
it('should return nothing if no account found', async function () {
this.client.getAccount = sinon
.stub()
.throws(new recurly.errors.NotFoundError())
@@ -93,7 +93,7 @@ describe('RecurlyClient', function() {
).to.eventually.equal(undefined)
})
it('should re-throw caught errors', async function() {
it('should re-throw caught errors', async function () {
this.client.getAccount = sinon.stub().throws()
await expect(
this.RecurlyClient.promises.getAccountForUserId(this.user._id)
@@ -101,8 +101,8 @@ describe('RecurlyClient', function() {
})
})
describe('createAccountForUserId', function() {
it('should return the Account as created by recurly', async function() {
describe('createAccountForUserId', function () {
it('should return the Account as created by recurly', async function () {
this.client.createAccount = sinon.stub().resolves(this.recurlyAccount)
await expect(
this.RecurlyClient.promises.createAccountForUserId(this.user._id)
@@ -111,7 +111,7 @@ describe('RecurlyClient', function() {
.that.has.property('code', this.user._id)
})
it('should throw any API errors', async function() {
it('should throw any API errors', async function () {
this.client.createAccount = sinon.stub().throws()
await expect(
this.RecurlyClient.promises.createAccountForUserId(this.user._id)
File diff suppressed because it is too large Load Diff
@@ -37,8 +37,8 @@ const mockSubscriptions = {
}
}
describe('SubscriptionController', function() {
beforeEach(function() {
describe('SubscriptionController', function () {
beforeEach(function () {
this.user = {
email: 'tom@yahoo.com',
_id: 'one',
@@ -126,8 +126,8 @@ describe('SubscriptionController', function() {
return (this.stubbedCurrencyCode = 'GBP')
})
describe('plansPage', function() {
beforeEach(function() {
describe('plansPage', function () {
beforeEach(function () {
this.req.ip = '1234.3123.3131.333 313.133.445.666 653.5345.5345.534'
return this.GeoIpLookup.getCurrencyCode.callsArgWith(
1,
@@ -136,19 +136,19 @@ describe('SubscriptionController', function() {
)
})
describe('when user is logged in', function(done) {
beforeEach(function(done) {
describe('when user is logged in', function (done) {
beforeEach(function (done) {
this.res.callback = done
return this.SubscriptionController.plansPage(this.req, this.res)
})
it('should fetch the current user', function(done) {
it('should fetch the current user', function (done) {
this.UserGetter.getUser.callCount.should.equal(1)
return done()
})
describe('not dependant on logged in state', function(done) {
describe('not dependant on logged in state', function (done) {
// these could have been put in 'when user is not logged in' too
it('should set the recommended currency from the geoiplookup', function(done) {
it('should set the recommended currency from the geoiplookup', function (done) {
this.res.renderedVariables.recomendedCurrency.should.equal(
this.stubbedCurrencyCode
)
@@ -157,15 +157,15 @@ describe('SubscriptionController', function() {
.should.equal(true)
return done()
})
it('should include data for features table', function(done) {
it('should include data for features table', function (done) {
this.res.renderedVariables.planFeatures.length.should.not.equal(0)
return done()
})
})
})
describe('when user is not logged in', function(done) {
beforeEach(function(done) {
describe('when user is not logged in', function (done) {
beforeEach(function (done) {
this.res.callback = done
this.AuthenticationController.getLoggedInUserId = sinon
.stub()
@@ -173,15 +173,15 @@ describe('SubscriptionController', function() {
return this.SubscriptionController.plansPage(this.req, this.res)
})
it('should not fetch the current user', function(done) {
it('should not fetch the current user', function (done) {
this.UserGetter.getUser.callCount.should.equal(0)
return done()
})
})
})
describe('paymentPage', function() {
beforeEach(function() {
describe('paymentPage', function () {
beforeEach(function () {
this.req.headers = {}
this.SubscriptionHandler.validateNoSubscriptionInRecurly = sinon
.stub()
@@ -193,8 +193,8 @@ describe('SubscriptionController', function() {
)
})
describe('with a user without a subscription', function() {
beforeEach(function() {
describe('with a user without a subscription', function () {
beforeEach(function () {
this.LimitationsManager.userHasV1OrV2Subscription.callsArgWith(
1,
null,
@@ -203,8 +203,8 @@ describe('SubscriptionController', function() {
return this.PlansLocator.findLocalPlanInSettings.returns({})
})
describe('with a valid plan code', function() {
it('should render the new subscription page', function(done) {
describe('with a valid plan code', function () {
it('should render the new subscription page', function (done) {
this.res.render = (page, opts) => {
page.should.equal('subscriptions/new')
return done()
@@ -214,8 +214,8 @@ describe('SubscriptionController', function() {
})
})
describe('with a user with subscription', function() {
it('should redirect to the subscription dashboard', function(done) {
describe('with a user with subscription', function () {
it('should redirect to the subscription dashboard', function (done) {
this.PlansLocator.findLocalPlanInSettings.returns({})
this.LimitationsManager.userHasV1OrV2Subscription.callsArgWith(
1,
@@ -230,8 +230,8 @@ describe('SubscriptionController', function() {
})
})
describe('with an invalid plan code', function() {
it('should return 422 error - Unprocessable Entity', function(done) {
describe('with an invalid plan code', function () {
it('should return 422 error - Unprocessable Entity', function (done) {
this.LimitationsManager.userHasV1OrV2Subscription.callsArgWith(
1,
null,
@@ -254,8 +254,8 @@ describe('SubscriptionController', function() {
})
})
describe('which currency to use', function() {
beforeEach(function() {
describe('which currency to use', function () {
beforeEach(function () {
this.LimitationsManager.userHasV1OrV2Subscription.callsArgWith(
1,
null,
@@ -264,7 +264,7 @@ describe('SubscriptionController', function() {
return this.PlansLocator.findLocalPlanInSettings.returns({})
})
it('should use the set currency from the query string', function(done) {
it('should use the set currency from the query string', function (done) {
this.req.query.currency = 'EUR'
this.res.render = (page, opts) => {
opts.currency.should.equal('EUR')
@@ -274,7 +274,7 @@ describe('SubscriptionController', function() {
return this.SubscriptionController.paymentPage(this.req, this.res)
})
it('should upercase the currency code', function(done) {
it('should upercase the currency code', function (done) {
this.req.query.currency = 'eur'
this.res.render = (page, opts) => {
opts.currency.should.equal('EUR')
@@ -283,7 +283,7 @@ describe('SubscriptionController', function() {
return this.SubscriptionController.paymentPage(this.req, this.res)
})
it('should use the geo ip currency if non is provided', function(done) {
it('should use the geo ip currency if non is provided', function (done) {
this.req.query.currency = null
this.res.render = (page, opts) => {
opts.currency.should.equal(this.stubbedCurrencyCode)
@@ -293,8 +293,8 @@ describe('SubscriptionController', function() {
})
})
describe('with a recurly subscription already', function() {
it('should redirect to the subscription dashboard', function(done) {
describe('with a recurly subscription already', function () {
it('should redirect to the subscription dashboard', function (done) {
this.PlansLocator.findLocalPlanInSettings.returns({})
this.LimitationsManager.userHasV1OrV2Subscription.callsArgWith(
1,
@@ -313,8 +313,8 @@ describe('SubscriptionController', function() {
})
})
describe('successful_subscription', function() {
beforeEach(function(done) {
describe('successful_subscription', function () {
beforeEach(function (done) {
this.SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel.callsArgWith(
1,
null,
@@ -328,8 +328,8 @@ describe('SubscriptionController', function() {
})
})
describe('userSubscriptionPage', function() {
beforeEach(function(done) {
describe('userSubscriptionPage', function () {
beforeEach(function (done) {
this.SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel.callsArgWith(
1,
null,
@@ -361,7 +361,7 @@ describe('SubscriptionController', function() {
)
})
it('should load the personal, groups and v1 subscriptions', function() {
it('should load the personal, groups and v1 subscriptions', function () {
expect(this.data.personalSubscription).to.deep.equal(
this.personalSubscription
)
@@ -370,17 +370,17 @@ describe('SubscriptionController', function() {
)
})
it('should load the user', function() {
it('should load the user', function () {
return expect(this.data.user).to.deep.equal(this.user)
})
it('should load the plans', function() {
it('should load the plans', function () {
return expect(this.data.plans).to.deep.equal(this.plans)
})
})
describe('createSubscription', function() {
beforeEach(function(done) {
describe('createSubscription', function () {
beforeEach(function (done) {
this.res = {
sendStatus() {
return done()
@@ -402,7 +402,7 @@ describe('SubscriptionController', function() {
return this.SubscriptionController.createSubscription(this.req, this.res)
})
it('should send the user and subscriptionId to the handler', function(done) {
it('should send the user and subscriptionId to the handler', function (done) {
this.SubscriptionHandler.createSubscription
.calledWithMatch(
this.user,
@@ -413,14 +413,14 @@ describe('SubscriptionController', function() {
return done()
})
it('should redurect to the subscription page', function(done) {
it('should redurect to the subscription page', function (done) {
this.res.sendStatus.calledWith(201).should.equal(true)
return done()
})
})
describe('createSubscription with errors', function() {
it('should handle users with subscription', function(done) {
describe('createSubscription with errors', function () {
it('should handle users with subscription', function (done) {
this.LimitationsManager.userHasV1OrV2Subscription.yields(null, true)
this.SubscriptionController.createSubscription(this.req, {
sendStatus: status => {
@@ -432,7 +432,7 @@ describe('SubscriptionController', function() {
})
})
it('should handle 3DSecure errors', function(done) {
it('should handle 3DSecure errors', function (done) {
this.next = sinon.stub()
this.LimitationsManager.userHasV1OrV2Subscription.yields(null, false)
this.SubscriptionHandler.createSubscription.yields(
@@ -449,7 +449,7 @@ describe('SubscriptionController', function() {
this.SubscriptionController.createSubscription(this.req, this.res)
})
it('should handle validation errors', function(done) {
it('should handle validation errors', function (done) {
this.next = sinon.stub()
this.LimitationsManager.userHasV1OrV2Subscription.yields(null, false)
this.SubscriptionHandler.createSubscription.yields(
@@ -466,7 +466,7 @@ describe('SubscriptionController', function() {
this.SubscriptionController.createSubscription(this.req, this.res)
})
it('should handle recurly errors', function(done) {
it('should handle recurly errors', function (done) {
this.LimitationsManager.userHasV1OrV2Subscription.yields(null, false)
this.SubscriptionHandler.createSubscription.yields(
new SubscriptionErrors.RecurlyTransactionError({})
@@ -484,7 +484,7 @@ describe('SubscriptionController', function() {
return this.SubscriptionController.createSubscription(this.req, this.res)
})
it('should handle invalid error', function(done) {
it('should handle invalid error', function (done) {
this.LimitationsManager.userHasV1OrV2Subscription.yields(null, false)
this.SubscriptionHandler.createSubscription.yields(
new Errors.InvalidError({})
@@ -500,8 +500,8 @@ describe('SubscriptionController', function() {
})
})
describe('updateSubscription via post', function() {
beforeEach(function(done) {
describe('updateSubscription via post', function () {
beforeEach(function (done) {
this.res = {
redirect() {
return done()
@@ -513,21 +513,21 @@ describe('SubscriptionController', function() {
return this.SubscriptionController.updateSubscription(this.req, this.res)
})
it('should send the user and subscriptionId to the handler', function(done) {
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()
})
it('should redurect to the subscription page', function(done) {
it('should redurect to the subscription page', function (done) {
this.res.redirect.calledWith('/user/subscription').should.equal(true)
return done()
})
})
describe('updateAccountEmailAddress via put', function() {
it('should send the user and subscriptionId to RecurlyWrapper', function() {
describe('updateAccountEmailAddress via put', function () {
it('should send the user and subscriptionId to RecurlyWrapper', function () {
this.res.sendStatus = sinon.spy()
this.SubscriptionController.updateAccountEmailAddress(this.req, this.res)
this.RecurlyWrapper.updateAccountEmailAddress
@@ -535,13 +535,13 @@ describe('SubscriptionController', function() {
.should.equal(true)
})
it('should respond with 200', function() {
it('should respond with 200', function () {
this.res.sendStatus = sinon.spy()
this.SubscriptionController.updateAccountEmailAddress(this.req, this.res)
this.res.sendStatus.calledWith(200).should.equal(true)
})
it('should send the error to the next handler when updating recurly account email fails', function(done) {
it('should send the error to the next handler when updating recurly account email fails', function (done) {
this.RecurlyWrapper.updateAccountEmailAddress.yields(new Error())
this.next = sinon.spy(error => {
expect(error).instanceOf(Error)
@@ -555,8 +555,8 @@ describe('SubscriptionController', function() {
})
})
describe('reactivateSubscription', function() {
beforeEach(function(done) {
describe('reactivateSubscription', function () {
beforeEach(function (done) {
this.res = {
redirect() {
return done()
@@ -569,21 +569,21 @@ describe('SubscriptionController', function() {
)
})
it('should tell the handler to reactivate this user', function(done) {
it('should tell the handler to reactivate this user', function (done) {
this.SubscriptionHandler.reactivateSubscription
.calledWith(this.user)
.should.equal(true)
return done()
})
it('should redurect to the subscription page', function(done) {
it('should redurect to the subscription page', function (done) {
this.res.redirect.calledWith('/user/subscription').should.equal(true)
return done()
})
})
describe('cancelSubscription', function() {
beforeEach(function(done) {
describe('cancelSubscription', function () {
beforeEach(function (done) {
this.res = {
redirect() {
return done()
@@ -593,14 +593,14 @@ describe('SubscriptionController', function() {
return this.SubscriptionController.cancelSubscription(this.req, this.res)
})
it('should tell the handler to cancel this user', function(done) {
it('should tell the handler to cancel this user', function (done) {
this.SubscriptionHandler.cancelSubscription
.calledWith(this.user)
.should.equal(true)
return done()
})
it('should redurect to the subscription page', function(done) {
it('should redurect to the subscription page', function (done) {
this.res.redirect
.calledWith('/user/subscription/canceled')
.should.equal(true)
@@ -608,9 +608,9 @@ describe('SubscriptionController', function() {
})
})
describe('recurly callback', function() {
describe('with a sync subscription request', function() {
beforeEach(function(done) {
describe('recurly callback', function () {
describe('with a sync subscription request', function () {
beforeEach(function (done) {
this.req = {
body: {
expired_subscription_notification: {
@@ -629,19 +629,19 @@ describe('SubscriptionController', function() {
return this.SubscriptionController.recurlyCallback(this.req, this.res)
})
it('should tell the SubscriptionHandler to process the recurly callback', function(done) {
it('should tell the SubscriptionHandler to process the recurly callback', function (done) {
this.SubscriptionHandler.syncSubscription.called.should.equal(true)
return done()
})
it('should send a 200', function(done) {
it('should send a 200', function (done) {
this.res.sendStatus.calledWith(200)
return done()
})
})
describe('with a billing info updated request', function() {
beforeEach(function(done) {
describe('with a billing info updated request', function () {
beforeEach(function (done) {
this.req = {
body: {
billing_info_updated_notification: {
@@ -660,21 +660,21 @@ describe('SubscriptionController', function() {
this.SubscriptionController.recurlyCallback(this.req, this.res)
})
it('should call attemptPaypalInvoiceCollection', function(done) {
it('should call attemptPaypalInvoiceCollection', function (done) {
this.SubscriptionHandler.attemptPaypalInvoiceCollection
.calledWith('mock-account-code')
.should.equal(true)
done()
})
it('should send a 200', function(done) {
it('should send a 200', function (done) {
this.res.sendStatus.calledWith(200)
done()
})
})
describe('with a non-actionable request', function() {
beforeEach(function(done) {
describe('with a non-actionable request', function () {
beforeEach(function (done) {
this.user.id = this.activeRecurlySubscription.account.account_code
this.req = {
body: {
@@ -694,23 +694,23 @@ describe('SubscriptionController', function() {
return this.SubscriptionController.recurlyCallback(this.req, this.res)
})
it('should not call the subscriptionshandler', function() {
it('should not call the subscriptionshandler', function () {
this.SubscriptionHandler.syncSubscription.called.should.equal(false)
this.SubscriptionHandler.attemptPaypalInvoiceCollection.called.should.equal(
false
)
})
it('should respond with a 200 status', function() {
it('should respond with a 200 status', function () {
return this.res.sendStatus.calledWith(200)
})
})
})
describe('renderUpgradeToAnnualPlanPage', function() {
it('should redirect to the plans page if the user does not have a subscription', function(done) {
describe('renderUpgradeToAnnualPlanPage', function () {
it('should redirect to the plans page if the user does not have a subscription', function (done) {
this.LimitationsManager.userHasV2Subscription.callsArgWith(1, null, false)
this.res.redirect = function(url) {
this.res.redirect = function (url) {
url.should.equal('/user/subscription/plans')
return done()
}
@@ -720,14 +720,14 @@ describe('SubscriptionController', function() {
)
})
it('should pass the plan code to the view - student', function(done) {
it('should pass the plan code to the view - student', function (done) {
this.LimitationsManager.userHasV2Subscription.callsArgWith(
1,
null,
true,
{ planCode: 'Student free trial 14 days' }
)
this.res.render = function(view, opts) {
this.res.render = function (view, opts) {
view.should.equal('subscriptions/upgradeToAnnual')
opts.planName.should.equal('student')
return done()
@@ -738,14 +738,14 @@ describe('SubscriptionController', function() {
)
})
it('should pass the plan code to the view - collaborator', function(done) {
it('should pass the plan code to the view - collaborator', function (done) {
this.LimitationsManager.userHasV2Subscription.callsArgWith(
1,
null,
true,
{ planCode: 'free trial for Collaborator free trial 14 days' }
)
this.res.render = function(view, opts) {
this.res.render = function (view, opts) {
opts.planName.should.equal('collaborator')
return done()
}
@@ -755,14 +755,14 @@ describe('SubscriptionController', function() {
)
})
it('should pass annual as the plan name if the user is already on an annual plan', function(done) {
it('should pass annual as the plan name if the user is already on an annual plan', function (done) {
this.LimitationsManager.userHasV2Subscription.callsArgWith(
1,
null,
true,
{ planCode: 'student annual with free trial' }
)
this.res.render = function(view, opts) {
this.res.render = function (view, opts) {
opts.planName.should.equal('annual')
return done()
}
@@ -773,10 +773,10 @@ describe('SubscriptionController', function() {
})
})
describe('processUpgradeToAnnualPlan', function() {
beforeEach(function() {})
describe('processUpgradeToAnnualPlan', function () {
beforeEach(function () {})
it('should tell the subscription handler to update the subscription with the annual plan and apply a coupon code', function(done) {
it('should tell the subscription handler to update the subscription with the annual plan and apply a coupon code', function (done) {
this.req.body = { planName: 'student' }
this.res.sendStatus = () => {
@@ -792,7 +792,7 @@ describe('SubscriptionController', function() {
)
})
it('should get the collaborator coupon code', function(done) {
it('should get the collaborator coupon code', function (done) {
this.req.body = { planName: 'collaborator' }
this.res.sendStatus = url => {
@@ -17,8 +17,8 @@ const modulePath =
'../../../../app/src/Features/Subscription/SubscriptionGroupController'
const MockResponse = require('../helpers/MockResponse')
describe('SubscriptionGroupController', function() {
beforeEach(function() {
describe('SubscriptionGroupController', function () {
beforeEach(function () {
this.user = { _id: '!@312431', email: 'user@email.com' }
this.adminUserId = '123jlkj'
this.subscriptionId = '123434325412'
@@ -65,8 +65,8 @@ describe('SubscriptionGroupController', function() {
}))
})
describe('removeUserFromGroup', function() {
it('should use the subscription id for the logged in user and take the user id from the params', function(done) {
describe('removeUserFromGroup', function () {
it('should use the subscription id for the logged in user and take the user id from the params', function (done) {
const userIdToRemove = '31231'
this.req.params = { user_id: userIdToRemove }
this.req.entity = this.subscription
@@ -83,8 +83,8 @@ describe('SubscriptionGroupController', function() {
})
})
describe('removeSelfFromGroup', function() {
it('gets subscription and remove user', function(done) {
describe('removeSelfFromGroup', function () {
it('gets subscription and remove user', function (done) {
const userIdToRemove = '31231'
this.req.query = { subscriptionId: this.subscriptionId }
const memberUserIdToremove = 123456789
@@ -18,8 +18,8 @@ const { assert, expect } = require('chai')
const modulePath =
'../../../../app/src/Features/Subscription/SubscriptionGroupHandler'
describe('SubscriptionGroupHandler', function() {
beforeEach(function() {
describe('SubscriptionGroupHandler', function () {
beforeEach(function () {
this.adminUser_id = '12321'
this.newEmail = 'bob@smith.com'
this.user_id = '3121321'
@@ -105,8 +105,8 @@ describe('SubscriptionGroupHandler', function() {
}))
})
describe('removeUserFromGroup', function() {
it('should call the subscription updater to remove the user', function(done) {
describe('removeUserFromGroup', function () {
it('should call the subscription updater to remove the user', function (done) {
return this.Handler.removeUserFromGroup(
this.adminUser_id,
this.user._id,
@@ -120,8 +120,8 @@ describe('SubscriptionGroupHandler', function() {
})
})
describe('replaceUserReferencesInGroups', function() {
beforeEach(function(done) {
describe('replaceUserReferencesInGroups', function () {
beforeEach(function (done) {
this.oldId = 'ba5eba11'
this.newId = '5ca1ab1e'
return this.Handler.replaceUserReferencesInGroups(
@@ -131,13 +131,13 @@ describe('SubscriptionGroupHandler', function() {
)
})
it('replaces the admin_id', function() {
it('replaces the admin_id', function () {
return this.Subscription.updateOne
.calledWith({ admin_id: this.oldId }, { admin_id: this.newId })
.should.equal(true)
})
it('replaces the manager_ids', function() {
it('replaces the manager_ids', function () {
this.Subscription.updateMany
.calledWith(
{ manager_ids: 'ba5eba11' },
@@ -153,7 +153,7 @@ describe('SubscriptionGroupHandler', function() {
.should.equal(true)
})
it('replaces the member ids', function() {
it('replaces the member ids', function () {
this.Subscription.updateMany
.calledWith(
{ member_ids: this.oldId },
@@ -170,12 +170,12 @@ describe('SubscriptionGroupHandler', function() {
})
})
describe('isUserPartOfGroup', function() {
beforeEach(function() {
describe('isUserPartOfGroup', function () {
beforeEach(function () {
return (this.subscription_id = '123ed13123')
})
it('should return true when user is part of subscription', function(done) {
it('should return true when user is part of subscription', function (done) {
this.SubscriptionLocator.getSubscriptionByMemberIdAndId.callsArgWith(
2,
null,
@@ -191,7 +191,7 @@ describe('SubscriptionGroupHandler', function() {
)
})
it('should return false when no subscription is found', function(done) {
it('should return false when no subscription is found', function (done) {
this.SubscriptionLocator.getSubscriptionByMemberIdAndId.callsArgWith(
2,
null
@@ -207,12 +207,12 @@ describe('SubscriptionGroupHandler', function() {
})
})
describe('getTotalConfirmedUsersInGroup', function() {
describe('for existing subscriptions', function() {
beforeEach(function() {
describe('getTotalConfirmedUsersInGroup', function () {
describe('for existing subscriptions', function () {
beforeEach(function () {
return (this.subscription.member_ids = ['12321', '3121321'])
})
it('should call the subscription locator and return 2 users', function(done) {
it('should call the subscription locator and return 2 users', function (done) {
return this.Handler.getTotalConfirmedUsersInGroup(
this.subscription_id,
(err, count) => {
@@ -225,8 +225,8 @@ describe('SubscriptionGroupHandler', function() {
)
})
})
describe('for nonexistent subscriptions', function() {
it('should return undefined', function(done) {
describe('for nonexistent subscriptions', function () {
it('should return undefined', function (done) {
return this.Handler.getTotalConfirmedUsersInGroup(
'fake-id',
(err, count) => {
@@ -19,8 +19,8 @@ const mockRecurlySubscriptions = {
}
}
describe('SubscriptionHandler', function() {
beforeEach(function() {
describe('SubscriptionHandler', function () {
beforeEach(function () {
this.Settings = {
plans: [
{
@@ -92,8 +92,8 @@ describe('SubscriptionHandler', function() {
.callsArgWith(2)
})
describe('createSubscription', function() {
beforeEach(function() {
describe('createSubscription', function () {
beforeEach(function () {
this.callback = sinon.stub()
this.subscriptionDetails = {
cvv: '123',
@@ -105,8 +105,8 @@ describe('SubscriptionHandler', function() {
.yields(null, true)
})
describe('successfully', function() {
beforeEach(function() {
describe('successfully', function () {
beforeEach(function () {
this.SubscriptionHandler.createSubscription(
this.user,
this.subscriptionDetails,
@@ -115,13 +115,13 @@ describe('SubscriptionHandler', function() {
)
})
it('should create the subscription with the wrapper', function() {
it('should create the subscription with the wrapper', function () {
this.RecurlyWrapper.createSubscription
.calledWith(this.user, this.subscriptionDetails, this.recurlyTokenIds)
.should.equal(true)
})
it('should sync the subscription to the user', function() {
it('should sync the subscription to the user', function () {
this.SubscriptionUpdater.syncSubscription.calledOnce.should.equal(true)
this.SubscriptionUpdater.syncSubscription.args[0][0].should.deep.equal(
this.activeRecurlySubscription
@@ -132,8 +132,8 @@ describe('SubscriptionHandler', function() {
})
})
describe('when there is already a subscription in Recurly', function() {
beforeEach(function() {
describe('when there is already a subscription in Recurly', function () {
beforeEach(function () {
this.SubscriptionHandler.validateNoSubscriptionInRecurly = sinon
.stub()
.yields(null, false)
@@ -145,7 +145,7 @@ describe('SubscriptionHandler', function() {
)
})
it('should an error', function() {
it('should an error', function () {
this.callback.calledWith(
new Error('user already has subscription in recurly')
)
@@ -153,10 +153,10 @@ describe('SubscriptionHandler', function() {
})
})
describe('updateSubscription', function() {
describe('with a user with a subscription', function() {
describe('with a valid plan code', function() {
beforeEach(function(done) {
describe('updateSubscription', function () {
describe('with a user with a subscription', function () {
describe('with a valid plan code', function () {
beforeEach(function (done) {
this.plan_code = 'collaborator'
this.LimitationsManager.userHasV2Subscription.callsArgWith(
1,
@@ -172,7 +172,7 @@ describe('SubscriptionHandler', function() {
)
})
it('should update the subscription', function() {
it('should update the subscription', function () {
this.RecurlyWrapper.updateSubscription
.calledWith(this.subscription.recurlySubscription_id)
.should.equal(true)
@@ -181,13 +181,13 @@ describe('SubscriptionHandler', function() {
updateOptions.plan_code.should.equal(this.plan_code)
})
it('should update immediately', function() {
it('should update immediately', function () {
const updateOptions = this.RecurlyWrapper.updateSubscription
.args[0][1]
updateOptions.timeframe.should.equal('now')
})
it('should sync the new subscription to the user', function() {
it('should sync the new subscription to the user', function () {
this.SubscriptionUpdater.syncSubscription.calledOnce.should.equal(
true
)
@@ -201,8 +201,8 @@ describe('SubscriptionHandler', function() {
})
})
describe('with a user without a subscription', function() {
beforeEach(function(done) {
describe('with a user without a subscription', function () {
beforeEach(function (done) {
this.LimitationsManager.userHasV2Subscription.callsArgWith(
1,
null,
@@ -216,7 +216,7 @@ describe('SubscriptionHandler', function() {
)
})
it('should redirect to the subscription dashboard', function() {
it('should redirect to the subscription dashboard', function () {
this.RecurlyWrapper.updateSubscription.called.should.equal(false)
this.SubscriptionHandler.syncSubscriptionToUser.called.should.equal(
false
@@ -224,8 +224,8 @@ describe('SubscriptionHandler', function() {
})
})
describe('with a coupon code', function() {
beforeEach(function(done) {
describe('with a coupon code', function () {
beforeEach(function (done) {
this.plan_code = 'collaborator'
this.coupon_code = '1231312'
this.LimitationsManager.userHasV2Subscription.callsArgWith(
@@ -242,13 +242,13 @@ describe('SubscriptionHandler', function() {
)
})
it('should get the users account', function() {
it('should get the users account', function () {
this.RecurlyWrapper.getSubscription
.calledWith(this.activeRecurlySubscription.uuid)
.should.equal(true)
})
it('should redeme the coupon', function(done) {
it('should redeme the coupon', function (done) {
this.RecurlyWrapper.redeemCoupon
.calledWith(
this.activeRecurlySubscription.account.account_code,
@@ -258,7 +258,7 @@ describe('SubscriptionHandler', function() {
done()
})
it('should update the subscription', function() {
it('should update the subscription', function () {
this.RecurlyWrapper.updateSubscription
.calledWith(this.subscription.recurlySubscription_id)
.should.equal(true)
@@ -268,9 +268,9 @@ describe('SubscriptionHandler', function() {
})
})
describe('cancelSubscription', function() {
describe('with a user without a subscription', function() {
beforeEach(function(done) {
describe('cancelSubscription', function () {
describe('with a user without a subscription', function () {
beforeEach(function (done) {
this.LimitationsManager.userHasV2Subscription.callsArgWith(
1,
null,
@@ -280,13 +280,13 @@ describe('SubscriptionHandler', function() {
this.SubscriptionHandler.cancelSubscription(this.user, done)
})
it('should redirect to the subscription dashboard', function() {
it('should redirect to the subscription dashboard', function () {
this.RecurlyWrapper.cancelSubscription.called.should.equal(false)
})
})
describe('with a user with a subscription', function() {
beforeEach(function(done) {
describe('with a user with a subscription', function () {
beforeEach(function (done) {
this.LimitationsManager.userHasV2Subscription.callsArgWith(
1,
null,
@@ -296,7 +296,7 @@ describe('SubscriptionHandler', function() {
this.SubscriptionHandler.cancelSubscription(this.user, done)
})
it('should cancel the subscription', function() {
it('should cancel the subscription', function () {
this.RecurlyWrapper.cancelSubscription.called.should.equal(true)
this.RecurlyWrapper.cancelSubscription
.calledWith(this.subscription.recurlySubscription_id)
@@ -305,9 +305,9 @@ describe('SubscriptionHandler', function() {
})
})
describe('reactiveRecurlySubscription', function() {
describe('with a user without a subscription', function() {
beforeEach(function(done) {
describe('reactiveRecurlySubscription', function () {
describe('with a user without a subscription', function () {
beforeEach(function (done) {
this.LimitationsManager.userHasV2Subscription.callsArgWith(
1,
null,
@@ -317,17 +317,17 @@ describe('SubscriptionHandler', function() {
this.SubscriptionHandler.reactivateSubscription(this.user, done)
})
it('should redirect to the subscription dashboard', function() {
it('should redirect to the subscription dashboard', function () {
this.RecurlyWrapper.reactivateSubscription.called.should.equal(false)
})
it('should not send a notification email', function() {
it('should not send a notification email', function () {
sinon.assert.notCalled(this.EmailHandler.sendEmail)
})
})
describe('with a user with a subscription', function() {
beforeEach(function(done) {
describe('with a user with a subscription', function () {
beforeEach(function (done) {
this.LimitationsManager.userHasV2Subscription.callsArgWith(
1,
null,
@@ -337,14 +337,14 @@ describe('SubscriptionHandler', function() {
this.SubscriptionHandler.reactivateSubscription(this.user, done)
})
it('should reactivate the subscription', function() {
it('should reactivate the subscription', function () {
this.RecurlyWrapper.reactivateSubscription.called.should.equal(true)
this.RecurlyWrapper.reactivateSubscription
.calledWith(this.subscription.recurlySubscription_id)
.should.equal(true)
})
it('should send a notification email', function() {
it('should send a notification email', function () {
sinon.assert.calledWith(
this.EmailHandler.sendEmail,
'reactivatedSubscription'
@@ -353,9 +353,9 @@ describe('SubscriptionHandler', function() {
})
})
describe('syncSubscription', function() {
describe('with an actionable request', function() {
beforeEach(function(done) {
describe('syncSubscription', function () {
describe('with an actionable request', function () {
beforeEach(function (done) {
this.user.id = this.activeRecurlySubscription.account.account_code
this.User.findById = (userId, projection, callback) => {
@@ -369,18 +369,18 @@ describe('SubscriptionHandler', function() {
)
})
it('should request the affected subscription from the API', function() {
it('should request the affected subscription from the API', function () {
this.RecurlyWrapper.getSubscription
.calledWith(this.activeRecurlySubscription.uuid)
.should.equal(true)
})
it('should request the account details of the subscription', function() {
it('should request the account details of the subscription', function () {
const options = this.RecurlyWrapper.getSubscription.args[0][1]
options.includeAccount.should.equal(true)
})
it('should sync the subscription to the user', function() {
it('should sync the subscription to the user', function () {
this.SubscriptionUpdater.syncSubscription.calledOnce.should.equal(true)
this.SubscriptionUpdater.syncSubscription.args[0][0].should.deep.equal(
this.activeRecurlySubscription
@@ -392,9 +392,9 @@ describe('SubscriptionHandler', function() {
})
})
describe('attemptPaypalInvoiceCollection', function() {
describe('for credit card users', function() {
beforeEach(function(done) {
describe('attemptPaypalInvoiceCollection', function () {
describe('for credit card users', function () {
beforeEach(function (done) {
this.RecurlyWrapper.getBillingInfo.yields(null, {
paypal_billing_agreement_id: null
})
@@ -404,20 +404,20 @@ describe('SubscriptionHandler', function() {
)
})
it('gets billing infos', function() {
it('gets billing infos', function () {
sinon.assert.calledWith(
this.RecurlyWrapper.getBillingInfo,
this.activeRecurlySubscription.account.account_code
)
})
it('skips user', function() {
it('skips user', function () {
sinon.assert.notCalled(this.RecurlyWrapper.getAccountPastDueInvoices)
})
})
describe('for paypal users', function() {
beforeEach(function(done) {
describe('for paypal users', function () {
beforeEach(function (done) {
this.RecurlyWrapper.getBillingInfo.yields(null, {
paypal_billing_agreement_id: 'mock-billing-agreement'
})
@@ -430,14 +430,14 @@ describe('SubscriptionHandler', function() {
)
})
it('gets past due invoices', function() {
it('gets past due invoices', function () {
sinon.assert.calledWith(
this.RecurlyWrapper.getAccountPastDueInvoices,
this.activeRecurlySubscription.account.account_code
)
})
it('calls attemptInvoiceCollection', function() {
it('calls attemptInvoiceCollection', function () {
sinon.assert.calledWith(
this.RecurlyWrapper.attemptInvoiceCollection,
'mock-invoice-number'
@@ -446,8 +446,8 @@ describe('SubscriptionHandler', function() {
})
})
describe('validateNoSubscriptionInRecurly', function() {
beforeEach(function() {
describe('validateNoSubscriptionInRecurly', function () {
beforeEach(function () {
this.subscriptions = []
this.RecurlyWrapper.listAccountActiveSubscriptions = sinon
.stub()
@@ -456,8 +456,8 @@ describe('SubscriptionHandler', function() {
this.callback = sinon.stub()
})
describe('with no subscription in recurly', function() {
beforeEach(function() {
describe('with no subscription in recurly', function () {
beforeEach(function () {
this.subscriptions.push((this.subscription = { mock: 'subscription' }))
this.SubscriptionHandler.validateNoSubscriptionInRecurly(
this.user_id,
@@ -465,36 +465,36 @@ describe('SubscriptionHandler', function() {
)
})
it('should call RecurlyWrapper.listAccountActiveSubscriptions with the user id', function() {
it('should call RecurlyWrapper.listAccountActiveSubscriptions with the user id', function () {
this.RecurlyWrapper.listAccountActiveSubscriptions
.calledWith(this.user_id)
.should.equal(true)
})
it('should sync the subscription', function() {
it('should sync the subscription', function () {
this.SubscriptionUpdater.syncSubscription
.calledWith(this.subscription, this.user_id)
.should.equal(true)
})
it('should call the callback with valid == false', function() {
it('should call the callback with valid == false', function () {
this.callback.calledWith(null, false).should.equal(true)
})
})
describe('with a subscription in recurly', function() {
beforeEach(function() {
describe('with a subscription in recurly', function () {
beforeEach(function () {
this.SubscriptionHandler.validateNoSubscriptionInRecurly(
this.user_id,
this.callback
)
})
it('should not sync the subscription', function() {
it('should not sync the subscription', function () {
this.SubscriptionUpdater.syncSubscription.called.should.equal(false)
})
it('should call the callback with valid == true', function() {
it('should call the callback with valid == true', function () {
this.callback.calledWith(null, true).should.equal(true)
})
})
@@ -17,8 +17,8 @@ const modulePath =
'../../../../app/src/Features/Subscription/SubscriptionLocator'
const { assert } = require('chai')
describe('Subscription Locator Tests', function() {
beforeEach(function() {
describe('Subscription Locator Tests', function () {
beforeEach(function () {
this.user = { _id: '5208dd34438842e2db333333' }
this.subscription = { hello: 'world' }
this.Subscription = {
@@ -42,8 +42,8 @@ describe('Subscription Locator Tests', function() {
}))
})
describe('finding users subscription', function() {
it('should send the users features', function(done) {
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.user,
@@ -57,7 +57,7 @@ describe('Subscription Locator Tests', function() {
)
})
it('should error if not found', function(done) {
it('should error if not found', function (done) {
this.Subscription.findOne.callsArgWith(1, 'not found')
return this.SubscriptionLocator.getUsersSubscription(
this.user,
@@ -68,7 +68,7 @@ describe('Subscription Locator Tests', function() {
)
})
it('should take a user id rather than the user object', function(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.user._id,
@@ -5,8 +5,8 @@ const modulePath =
const { assert, expect } = require('chai')
const { ObjectId } = require('mongodb')
describe('SubscriptionUpdater', function() {
beforeEach(function() {
describe('SubscriptionUpdater', function () {
beforeEach(function () {
this.recurlySubscription = {
uuid: '1238uoijdasjhd',
plan: {
@@ -106,8 +106,8 @@ describe('SubscriptionUpdater', function() {
})
})
describe('updateAdmin', function() {
it('should update the subscription admin', function(done) {
describe('updateAdmin', function () {
it('should update the subscription admin', function (done) {
this.subscription.groupPlan = true
this.SubscriptionUpdater.updateAdmin(
this.subscription,
@@ -134,7 +134,7 @@ describe('SubscriptionUpdater', function() {
)
})
it('should remove the manager for non-group subscriptions', function(done) {
it('should remove the manager for non-group subscriptions', function (done) {
this.SubscriptionUpdater.updateAdmin(
this.subscription,
this.otherUserId,
@@ -163,8 +163,8 @@ describe('SubscriptionUpdater', function() {
})
})
describe('syncSubscription', function() {
beforeEach(function() {
describe('syncSubscription', function () {
beforeEach(function () {
this.SubscriptionLocator.getUsersSubscription.callsArgWith(
1,
null,
@@ -175,7 +175,7 @@ describe('SubscriptionUpdater', function() {
.yields()
})
it('should update the subscription if the user already is admin of one', function(done) {
it('should update the subscription if the user already is admin of one', function (done) {
this.SubscriptionUpdater._createNewSubscription = sinon.stub()
this.SubscriptionUpdater.syncSubscription(
@@ -199,7 +199,7 @@ describe('SubscriptionUpdater', function() {
)
})
it('should not call updateFeatures with group subscription if recurly subscription is not expired', function(done) {
it('should not call updateFeatures with group subscription if recurly subscription is not expired', function (done) {
this.SubscriptionUpdater.syncSubscription(
this.recurlySubscription,
this.adminUser._id,
@@ -223,17 +223,17 @@ describe('SubscriptionUpdater', function() {
})
})
describe('_updateSubscriptionFromRecurly', function() {
beforeEach(function() {
describe('_updateSubscriptionFromRecurly', function () {
beforeEach(function () {
this.FeaturesUpdater.refreshFeatures = sinon.stub().callsArgWith(1)
this.SubscriptionUpdater.deleteSubscription = sinon.stub().yields()
})
afterEach(function() {
afterEach(function () {
this.subscription.member_ids = []
})
it('should update the subscription with token etc when not expired', function(done) {
it('should update the subscription with token etc when not expired', function (done) {
this.SubscriptionUpdater._updateSubscriptionFromRecurly(
this.recurlySubscription,
this.subscription,
@@ -257,7 +257,7 @@ describe('SubscriptionUpdater', function() {
)
})
it('should remove the subscription when expired', function(done) {
it('should remove the subscription when expired', function (done) {
this.recurlySubscription.state = 'expired'
this.SubscriptionUpdater._updateSubscriptionFromRecurly(
this.recurlySubscription,
@@ -275,7 +275,7 @@ describe('SubscriptionUpdater', function() {
)
})
it('should update all the users features', function(done) {
it('should update all the users features', function (done) {
this.subscription.member_ids = this.allUserIds
this.SubscriptionUpdater._updateSubscriptionFromRecurly(
this.recurlySubscription,
@@ -302,7 +302,7 @@ describe('SubscriptionUpdater', function() {
)
})
it('should set group to true and save how many members can be added to group', function(done) {
it('should set group to true and save how many members can be added to group', function (done) {
this.PlansLocator.findLocalPlanInSettings
.withArgs(this.recurlySubscription.plan.plan_code)
.returns({ groupPlan: true, membersLimit: 5 })
@@ -324,7 +324,7 @@ describe('SubscriptionUpdater', function() {
)
})
it('should not set group to true or set groupPlan', function(done) {
it('should not set group to true or set groupPlan', function (done) {
this.SubscriptionUpdater._updateSubscriptionFromRecurly(
this.recurlySubscription,
this.subscription,
@@ -340,8 +340,8 @@ describe('SubscriptionUpdater', function() {
)
})
describe('when the plan allows adding more seats', function() {
beforeEach(function() {
describe('when the plan allows adding more seats', function () {
beforeEach(function () {
this.membersLimitAddOn = 'add_on1'
this.PlansLocator.findLocalPlanInSettings
.withArgs(this.recurlySubscription.plan.plan_code)
@@ -353,7 +353,7 @@ describe('SubscriptionUpdater', function() {
})
function expectMembersLimit(limit) {
it('should set the membersLimit accordingly', function(done) {
it('should set the membersLimit accordingly', function (done) {
this.SubscriptionUpdater._updateSubscriptionFromRecurly(
this.recurlySubscription,
this.subscription,
@@ -368,15 +368,15 @@ describe('SubscriptionUpdater', function() {
})
}
describe('when the recurlySubscription does not have add ons', function() {
beforeEach(function() {
describe('when the recurlySubscription does not have add ons', function () {
beforeEach(function () {
delete this.recurlySubscription.subscription_add_ons
})
expectMembersLimit(5)
})
describe('when the recurlySubscription has non-matching add ons', function() {
beforeEach(function() {
describe('when the recurlySubscription has non-matching add ons', function () {
beforeEach(function () {
this.recurlySubscription.subscription_add_ons = [
{ add_on_code: 'add_on_99', quantity: 3 }
]
@@ -384,8 +384,8 @@ describe('SubscriptionUpdater', function() {
expectMembersLimit(5)
})
describe('when the recurlySubscription has a matching add on', function() {
beforeEach(function() {
describe('when the recurlySubscription has a matching add on', function () {
beforeEach(function () {
this.recurlySubscription.subscription_add_ons = [
{ add_on_code: this.membersLimitAddOn, quantity: 10 }
]
@@ -394,8 +394,8 @@ describe('SubscriptionUpdater', function() {
})
// NOTE: This is unexpected, but we are going to support it anyways.
describe('when the recurlySubscription has multiple matching add ons', function() {
beforeEach(function() {
describe('when the recurlySubscription has multiple matching add ons', function () {
beforeEach(function () {
this.recurlySubscription.subscription_add_ons = [
{ add_on_code: this.membersLimitAddOn, quantity: 10 },
{ add_on_code: this.membersLimitAddOn, quantity: 3 }
@@ -406,8 +406,8 @@ describe('SubscriptionUpdater', function() {
})
})
describe('_createNewSubscription', function() {
it('should create a new subscription then update the subscription', function(done) {
describe('_createNewSubscription', function () {
it('should create a new subscription then update the subscription', function (done) {
this.SubscriptionUpdater._createNewSubscription(
this.adminUser._id,
() => {
@@ -420,12 +420,12 @@ describe('SubscriptionUpdater', function() {
})
})
describe('addUserToGroup', function() {
beforeEach(function() {
describe('addUserToGroup', function () {
beforeEach(function () {
this.SubscriptionUpdater.addUsersToGroup = sinon.stub().yields(null)
})
it('delegates to addUsersToGroup', function(done) {
it('delegates to addUsersToGroup', function (done) {
this.SubscriptionUpdater.addUserToGroup(
this.subscription._id,
this.otherUserId,
@@ -439,12 +439,12 @@ describe('SubscriptionUpdater', function() {
})
})
describe('addUsersToGroup', function() {
beforeEach(function() {
describe('addUsersToGroup', function () {
beforeEach(function () {
this.FeaturesUpdater.refreshFeatures = sinon.stub().callsArgWith(1)
})
it('should add the user ids to the group as a set', function(done) {
it('should add the user ids to the group as a set', function (done) {
this.SubscriptionUpdater.addUsersToGroup(
this.subscription._id,
[this.otherUserId],
@@ -461,7 +461,7 @@ describe('SubscriptionUpdater', function() {
)
})
it('should update the users features', function(done) {
it('should update the users features', function (done) {
this.SubscriptionUpdater.addUserToGroup(
this.subscription._id,
this.otherUserId,
@@ -475,8 +475,8 @@ describe('SubscriptionUpdater', function() {
})
})
describe('removeUserFromGroups', function() {
beforeEach(function() {
describe('removeUserFromGroups', function () {
beforeEach(function () {
this.FeaturesUpdater.refreshFeatures = sinon.stub().callsArgWith(1)
this.UserGetter.getUser.yields(null, {})
this.fakeSubscriptions = [{ _id: 'fake-id-1' }, { _id: 'fake-id-2' }]
@@ -486,7 +486,7 @@ describe('SubscriptionUpdater', function() {
)
})
it('should pull the users id from the group', function(done) {
it('should pull the users id from the group', function (done) {
this.SubscriptionUpdater.removeUserFromGroup(
this.subscription._id,
this.otherUserId,
@@ -501,7 +501,7 @@ describe('SubscriptionUpdater', function() {
)
})
it('should pull the users id from all groups', function(done) {
it('should pull the users id from all groups', function (done) {
this.SubscriptionUpdater.removeUserFromAllGroups(this.otherUserId, () => {
const filter = { _id: ['fake-id-1', 'fake-id-2'] }
const removeOperation = { $pull: { member_ids: this.otherUserId } }
@@ -510,7 +510,7 @@ describe('SubscriptionUpdater', function() {
})
})
it('should update the users features', function(done) {
it('should update the users features', function (done) {
this.SubscriptionUpdater.removeUserFromGroup(
this.subscription._id,
this.otherUserId,
@@ -524,8 +524,8 @@ describe('SubscriptionUpdater', function() {
})
})
describe('deleteSubscription', function() {
beforeEach(function(done) {
describe('deleteSubscription', function () {
beforeEach(function (done) {
this.subscription = {
_id: ObjectId().toString(),
mock: 'subscription',
@@ -539,19 +539,19 @@ describe('SubscriptionUpdater', function() {
this.SubscriptionUpdater.deleteSubscription(this.subscription, {}, done)
})
it('should remove the subscription', function() {
it('should remove the subscription', function () {
this.SubscriptionModel.deleteOne
.calledWith({ _id: this.subscription._id })
.should.equal(true)
})
it('should downgrade the admin_id', function() {
it('should downgrade the admin_id', function () {
this.FeaturesUpdater.refreshFeatures
.calledWith(this.subscription.admin_id)
.should.equal(true)
})
it('should downgrade all of the members', function() {
it('should downgrade all of the members', function () {
for (const userId of this.subscription.member_ids) {
this.FeaturesUpdater.refreshFeatures
.calledWith(userId)
@@ -7,8 +7,8 @@ const modulePath =
const { ObjectId } = require('mongodb')
const Errors = require('../../../../app/src/Features/Errors/Errors')
describe('TeamInvitesHandler', function() {
beforeEach(function() {
describe('TeamInvitesHandler', function () {
beforeEach(function () {
this.manager = {
_id: '666666',
first_name: 'Daenerys',
@@ -98,8 +98,8 @@ describe('TeamInvitesHandler', function() {
})
})
describe('getInvite', function() {
it("returns the invite if there's one", function(done) {
describe('getInvite', function () {
it("returns the invite if there's one", function (done) {
this.TeamInvitesHandler.getInvite(
this.token,
(err, invite, subscription) => {
@@ -111,7 +111,7 @@ describe('TeamInvitesHandler', function() {
)
})
it("returns teamNotFound if there's none", function(done) {
it("returns teamNotFound if there's none", function (done) {
this.Subscription.findOne = sinon.stub().yields(null, null)
this.TeamInvitesHandler.getInvite(
@@ -124,8 +124,8 @@ describe('TeamInvitesHandler', function() {
})
})
describe('createInvite', function() {
it('adds the team invite to the subscription', function(done) {
describe('createInvite', function () {
it('adds the team invite to the subscription', function (done) {
this.TeamInvitesHandler.createInvite(
this.manager._id,
this.subscription,
@@ -144,7 +144,7 @@ describe('TeamInvitesHandler', function() {
)
})
it('sends an email', function(done) {
it('sends an email', function (done) {
this.TeamInvitesHandler.createInvite(
this.manager._id,
this.subscription,
@@ -165,7 +165,7 @@ describe('TeamInvitesHandler', function() {
)
})
it('refreshes the existing invite if the email has already been invited', function(done) {
it('refreshes the existing invite if the email has already been invited', function (done) {
const originalInvite = Object.assign({}, this.teamInvite)
this.TeamInvitesHandler.createInvite(
@@ -188,7 +188,7 @@ describe('TeamInvitesHandler', function() {
)
})
it('removes any legacy invite from the subscription', function(done) {
it('removes any legacy invite from the subscription', function (done) {
this.TeamInvitesHandler.createInvite(
this.manager._id,
this.subscription,
@@ -205,7 +205,7 @@ describe('TeamInvitesHandler', function() {
)
})
it('add user to subscription if inviting self', function(done) {
it('add user to subscription if inviting self', function (done) {
this.TeamInvitesHandler.createInvite(
this.manager._id,
this.subscription,
@@ -228,12 +228,12 @@ describe('TeamInvitesHandler', function() {
})
})
describe('importInvite', function() {
beforeEach(function() {
describe('importInvite', function () {
beforeEach(function () {
this.sentAt = new Date()
})
it('can imports an invite from v1', function() {
it('can imports an invite from v1', function () {
this.TeamInvitesHandler.importInvite(
this.subscription,
'A-Team',
@@ -255,8 +255,8 @@ describe('TeamInvitesHandler', function() {
})
})
describe('acceptInvite', function() {
beforeEach(function() {
describe('acceptInvite', function () {
beforeEach(function () {
this.user = {
id: '123456789',
first_name: 'Tyrion',
@@ -275,7 +275,7 @@ describe('TeamInvitesHandler', function() {
})
})
it('adds the user to the team', function(done) {
it('adds the user to the team', function (done) {
this.TeamInvitesHandler.acceptInvite('dddddddd', this.user.id, () => {
this.SubscriptionUpdater.addUserToGroup
.calledWith(this.subscription._id, this.user.id)
@@ -284,7 +284,7 @@ describe('TeamInvitesHandler', function() {
})
})
it('removes the invite from the subscription', function(done) {
it('removes the invite from the subscription', function (done) {
this.TeamInvitesHandler.acceptInvite('dddddddd', this.user.id, () => {
this.Subscription.updateOne
.calledWith(
@@ -297,8 +297,8 @@ describe('TeamInvitesHandler', function() {
})
})
describe('revokeInvite', function() {
it('removes the team invite from the subscription', function(done) {
describe('revokeInvite', function () {
it('removes the team invite from the subscription', function (done) {
this.TeamInvitesHandler.revokeInvite(
this.manager._id,
this.subscription,
@@ -323,8 +323,8 @@ describe('TeamInvitesHandler', function() {
})
})
describe('createTeamInvitesForLegacyInvitedEmail', function(done) {
beforeEach(function() {
describe('createTeamInvitesForLegacyInvitedEmail', function (done) {
beforeEach(function () {
this.subscription.invited_emails = [
'eddard@example.com',
'robert@example.com'
@@ -335,7 +335,7 @@ describe('TeamInvitesHandler', function() {
.yields(null, [this.subscription])
})
it('sends an invitation email to addresses in the legacy invited_emails field', function(done) {
it('sends an invitation email to addresses in the legacy invited_emails field', function (done) {
this.TeamInvitesHandler.createTeamInvitesForLegacyInvitedEmail(
'eddard@example.com',
(err, invite) => {
@@ -357,8 +357,8 @@ describe('TeamInvitesHandler', function() {
})
})
describe('validation', function() {
it("doesn't create an invite if the team limit has been reached", function(done) {
describe('validation', function () {
it("doesn't create an invite if the team limit has been reached", function (done) {
this.LimitationsManager.teamHasReachedMemberLimit = sinon
.stub()
.returns(true)
@@ -373,7 +373,7 @@ describe('TeamInvitesHandler', function() {
)
})
it("doesn't create an invite if the subscription is not in a group plan", function(done) {
it("doesn't create an invite if the subscription is not in a group plan", function (done) {
this.subscription.groupPlan = false
this.TeamInvitesHandler.createInvite(
this.manager._id,
@@ -386,7 +386,7 @@ describe('TeamInvitesHandler', function() {
)
})
it("doesn't create an invite if the user is already part of the team", function(done) {
it("doesn't create an invite if the user is already part of the team", function (done) {
const member = {
id: '1a2b',
_id: '1a2b',
@@ -18,8 +18,8 @@ const modulePath =
'../../../../app/src/Features/Subscription/UserFeaturesUpdater'
const { assert } = require('chai')
describe('UserFeaturesUpdater', function() {
beforeEach(function() {
describe('UserFeaturesUpdater', function () {
beforeEach(function () {
this.User = { updateOne: sinon.stub().callsArgWith(2) }
return (this.UserFeaturesUpdater = SandboxedModule.require(modulePath, {
requires: {
@@ -30,8 +30,8 @@ describe('UserFeaturesUpdater', function() {
}))
})
describe('updateFeatures', function() {
it('should send the users features', function(done) {
describe('updateFeatures', function () {
it('should send the users features', function (done) {
const user_id = '5208dd34438842e2db000005'
this.features = { versioning: true, collaborators: 10 }
return this.UserFeaturesUpdater.updateFeatures(
@@ -22,8 +22,8 @@ const modulePath = path.join(
const sinon = require('sinon')
const { expect } = require('chai')
describe('V1SubscriptionManager', function() {
beforeEach(function() {
describe('V1SubscriptionManager', function () {
beforeEach(function () {
this.V1SubscriptionManager = SandboxedModule.require(modulePath, {
requires: {
'../User/UserGetter': (this.UserGetter = {}),
@@ -54,8 +54,8 @@ describe('V1SubscriptionManager', function() {
})
})
describe('getPlanCodeFromV1', function() {
beforeEach(function() {
describe('getPlanCodeFromV1', function () {
beforeEach(function () {
this.responseBody = {
id: 32,
plan_name: 'pro'
@@ -68,8 +68,8 @@ describe('V1SubscriptionManager', function() {
})
})
describe('when all goes well', function() {
it('should call _v1Request', function(done) {
describe('when all goes well', function () {
it('should call _v1Request', function (done) {
return this.call((err, planCode) => {
expect(this.V1SubscriptionManager._v1Request.callCount).to.equal(1)
expect(
@@ -79,14 +79,14 @@ describe('V1SubscriptionManager', function() {
})
})
it('should return the v1 user id', function(done) {
return this.call(function(err, planCode, v1Id) {
it('should return the v1 user id', function (done) {
return this.call(function (err, planCode, v1Id) {
expect(v1Id).to.equal(this.v1UserId)
return done()
})
})
it('should produce a plan-code without error', function(done) {
it('should produce a plan-code without error', function (done) {
return this.call((err, planCode) => {
expect(err).to.not.exist
expect(planCode).to.equal('v1_pro')
@@ -94,12 +94,12 @@ describe('V1SubscriptionManager', function() {
})
})
describe('when the plan_name from v1 is null', function() {
beforeEach(function() {
describe('when the plan_name from v1 is null', function () {
beforeEach(function () {
return (this.responseBody.plan_name = null)
})
it('should produce a null plan-code without error', function(done) {
it('should produce a null plan-code without error', function (done) {
return this.call((err, planCode) => {
expect(err).to.not.exist
expect(planCode).to.equal(null)
@@ -110,9 +110,9 @@ describe('V1SubscriptionManager', function() {
})
})
describe('getGrandfatheredFeaturesForV1User', function() {
describe('when the user ID is greater than the cutoff', function() {
it('should return an empty feature set', function(done) {
describe('getGrandfatheredFeaturesForV1User', function () {
describe('when the user ID is greater than the cutoff', function () {
it('should return an empty feature set', function (done) {
expect(
this.V1SubscriptionManager.getGrandfatheredFeaturesForV1User(100)
).to.eql({})
@@ -120,8 +120,8 @@ describe('V1SubscriptionManager', function() {
})
})
describe('when the user ID is less than the cutoff', function() {
it('should return a feature set with grandfathered properties for github and mendeley', function(done) {
describe('when the user ID is less than the cutoff', function () {
it('should return a feature set with grandfathered properties for github and mendeley', function (done) {
expect(
this.V1SubscriptionManager.getGrandfatheredFeaturesForV1User(1)
).to.eql({
@@ -133,13 +133,13 @@ describe('V1SubscriptionManager', function() {
})
})
describe('_v1Request', function() {
beforeEach(function() {
describe('_v1Request', function () {
beforeEach(function () {
return (this.UserGetter.getUser = sinon.stub().yields(null, this.user))
})
describe('when v1IdForUser produces an error', function() {
beforeEach(function() {
describe('when v1IdForUser produces an error', function () {
beforeEach(function () {
this.V1SubscriptionManager.v1IdForUser = sinon
.stub()
.yields(new Error('woops'))
@@ -156,14 +156,14 @@ describe('V1SubscriptionManager', function() {
})
})
it('should not call request', function(done) {
it('should not call request', function (done) {
return this.call((err, planCode) => {
expect(this.request.callCount).to.equal(0)
return done()
})
})
it('should produce an error', function(done) {
it('should produce an error', function (done) {
return this.call((err, planCode) => {
expect(err).to.exist
return done()
@@ -171,8 +171,8 @@ describe('V1SubscriptionManager', function() {
})
})
describe('when v1IdForUser does not find a user', function() {
beforeEach(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(
@@ -187,14 +187,14 @@ describe('V1SubscriptionManager', function() {
})
})
it('should not call request', function(done) {
it('should not call request', function (done) {
return this.call((err, planCode) => {
expect(this.request.callCount).to.equal(0)
return done()
})
})
it('should not error', function(done) {
it('should not error', function (done) {
return this.call(err => {
expect(err).to.not.exist
return done()
@@ -202,8 +202,8 @@ describe('V1SubscriptionManager', function() {
})
})
describe('when the request to v1 fails', function() {
beforeEach(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(
@@ -218,7 +218,7 @@ describe('V1SubscriptionManager', function() {
})
})
it('should produce an error', function(done) {
it('should produce an error', function (done) {
return this.call(err => {
expect(err).to.exist
return done()
@@ -226,8 +226,8 @@ describe('V1SubscriptionManager', function() {
})
})
describe('when the call succeeds', function() {
beforeEach(function() {
describe('when the call succeeds', function () {
beforeEach(function () {
this.V1SubscriptionManager.v1IdForUser = sinon
.stub()
.yields(null, this.v1UserId)
@@ -245,21 +245,21 @@ describe('V1SubscriptionManager', function() {
})
})
it('should not produce an error', function(done) {
it('should not produce an error', function (done) {
return this.call((err, body, v1Id) => {
expect(err).not.to.exist
return done()
})
})
it('should return the v1 user id', function(done) {
it('should return the v1 user id', function (done) {
return this.call((err, body, v1Id) => {
expect(v1Id).to.equal(this.v1UserId)
return done()
})
})
it('should return the http response body', function(done) {
it('should return the http response body', function (done) {
return this.call((err, body, v1Id) => {
expect(body).to.equal('{}')
return done()
@@ -267,8 +267,8 @@ describe('V1SubscriptionManager', function() {
})
})
describe('when the call returns an http error status code', function() {
beforeEach(function() {
describe('when the call returns an http error status code', function () {
beforeEach(function () {
this.V1SubscriptionManager.v1IdForUser = sinon
.stub()
.yields(null, this.v1UserId)
@@ -286,7 +286,7 @@ describe('V1SubscriptionManager', function() {
})
})
it('should produce an error', function(done) {
it('should produce an error', function (done) {
return this.call((err, body, v1Id) => {
expect(err).to.exist
return done()
@@ -294,8 +294,8 @@ describe('V1SubscriptionManager', function() {
})
})
describe('when the call returns an http not-found status code', function() {
beforeEach(function() {
describe('when the call returns an http not-found status code', function () {
beforeEach(function () {
this.V1SubscriptionManager.v1IdForUser = sinon
.stub()
.yields(null, this.v1UserId)
@@ -313,7 +313,7 @@ describe('V1SubscriptionManager', function() {
})
})
it('should produce an not-found error', function(done) {
it('should produce an not-found error', function (done) {
return this.call((err, body, v1Id) => {
expect(err).to.exist
expect(err.name).to.equal('NotFoundError')
@@ -323,20 +323,20 @@ describe('V1SubscriptionManager', function() {
})
})
describe('v1IdForUser', function() {
beforeEach(function() {
describe('v1IdForUser', function () {
beforeEach(function () {
return (this.UserGetter.getUser = sinon.stub().yields(null, this.user))
})
describe('when getUser produces an error', function() {
beforeEach(function() {
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)
})
})
it('should produce an error', function(done) {
it('should produce an error', function (done) {
return this.call(err => {
expect(err).to.exist
return done()
@@ -344,15 +344,15 @@ describe('V1SubscriptionManager', function() {
})
})
describe('when getUser does not find a user', function() {
beforeEach(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)
})
})
it('should not error', function(done) {
it('should not error', function (done) {
return this.call((err, user_id) => {
expect(err).to.not.exist
return done()
@@ -360,21 +360,21 @@ describe('V1SubscriptionManager', function() {
})
})
describe('when it works', function() {
beforeEach(function() {
describe('when it works', function () {
beforeEach(function () {
return (this.call = cb => {
return this.V1SubscriptionManager.v1IdForUser(this.user_id, cb)
})
})
it('should not error', function(done) {
it('should not error', function (done) {
return this.call((err, user_id) => {
expect(err).to.not.exist
return done()
})
})
it('should return the v1 user id', function(done) {
it('should return the v1 user id', function (done) {
return this.call((err, user_id) => {
expect(user_id).to.eql(42)
return done()