mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #3986 from overleaf/tm-decaf-limitations-manager
Decaf cleanup of LimitationsManager and tests GitOrigin-RevId: 9bbfc4c3ad002a424863a43c3c19dc66fa5e9854
This commit is contained in:
parent
6583d6de21
commit
46ecb39bdb
2 changed files with 215 additions and 246 deletions
|
@ -1,16 +1,3 @@
|
||||||
/* eslint-disable
|
|
||||||
camelcase,
|
|
||||||
node/handle-callback-err,
|
|
||||||
max-len,
|
|
||||||
*/
|
|
||||||
// TODO: This file was created by bulk-decaffeinate.
|
|
||||||
// Fix any style issues and re-enable lint.
|
|
||||||
/*
|
|
||||||
* decaffeinate suggestions:
|
|
||||||
* DS102: Remove unnecessary code created because of implicit returns
|
|
||||||
* DS207: Consider shorter variations of null checks
|
|
||||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
||||||
*/
|
|
||||||
let LimitationsManager
|
let LimitationsManager
|
||||||
const OError = require('@overleaf/o-error')
|
const OError = require('@overleaf/o-error')
|
||||||
const logger = require('logger-sharelatex')
|
const logger = require('logger-sharelatex')
|
||||||
|
@ -24,65 +11,62 @@ const V1SubscriptionManager = require('./V1SubscriptionManager')
|
||||||
const { V1ConnectionError } = require('../Errors/Errors')
|
const { V1ConnectionError } = require('../Errors/Errors')
|
||||||
|
|
||||||
module.exports = LimitationsManager = {
|
module.exports = LimitationsManager = {
|
||||||
allowedNumberOfCollaboratorsInProject(project_id, callback) {
|
allowedNumberOfCollaboratorsInProject(projectId, callback) {
|
||||||
return ProjectGetter.getProject(
|
ProjectGetter.getProject(
|
||||||
project_id,
|
projectId,
|
||||||
{ owner_ref: true },
|
{ owner_ref: true },
|
||||||
(error, project) => {
|
(error, project) => {
|
||||||
if (error != null) {
|
if (error) {
|
||||||
return callback(error)
|
return callback(error)
|
||||||
}
|
}
|
||||||
return this.allowedNumberOfCollaboratorsForUser(
|
this.allowedNumberOfCollaboratorsForUser(project.owner_ref, callback)
|
||||||
project.owner_ref,
|
|
||||||
callback
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
allowedNumberOfCollaboratorsForUser(user_id, callback) {
|
allowedNumberOfCollaboratorsForUser(userId, callback) {
|
||||||
return UserGetter.getUser(user_id, { features: 1 }, function (error, user) {
|
UserGetter.getUser(userId, { features: 1 }, function (error, user) {
|
||||||
if (error != null) {
|
if (error) {
|
||||||
return callback(error)
|
return callback(error)
|
||||||
}
|
}
|
||||||
if (user.features != null && user.features.collaborators != null) {
|
if (user.features && user.features.collaborators) {
|
||||||
return callback(null, user.features.collaborators)
|
callback(null, user.features.collaborators)
|
||||||
} else {
|
} else {
|
||||||
return callback(null, Settings.defaultFeatures.collaborators)
|
callback(null, Settings.defaultFeatures.collaborators)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
canAddXCollaborators(project_id, x_collaborators, callback) {
|
canAddXCollaborators(projectId, numberOfNewCollaborators, callback) {
|
||||||
if (callback == null) {
|
if (!callback) {
|
||||||
callback = function (error, allowed) {}
|
callback = function (error, allowed) {}
|
||||||
}
|
}
|
||||||
return this.allowedNumberOfCollaboratorsInProject(
|
this.allowedNumberOfCollaboratorsInProject(
|
||||||
project_id,
|
projectId,
|
||||||
(error, allowed_number) => {
|
(error, allowedNumber) => {
|
||||||
if (error != null) {
|
if (error) {
|
||||||
return callback(error)
|
return callback(error)
|
||||||
}
|
}
|
||||||
return CollaboratorsGetter.getInvitedCollaboratorCount(
|
CollaboratorsGetter.getInvitedCollaboratorCount(
|
||||||
project_id,
|
projectId,
|
||||||
(error, current_number) => {
|
(error, currentNumber) => {
|
||||||
if (error != null) {
|
if (error) {
|
||||||
return callback(error)
|
return callback(error)
|
||||||
}
|
}
|
||||||
return CollaboratorsInvitesHandler.getInviteCount(
|
CollaboratorsInvitesHandler.getInviteCount(
|
||||||
project_id,
|
projectId,
|
||||||
(error, invite_count) => {
|
(error, inviteCount) => {
|
||||||
if (error != null) {
|
if (error) {
|
||||||
return callback(error)
|
return callback(error)
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
current_number + invite_count + x_collaborators <=
|
currentNumber + inviteCount + numberOfNewCollaborators <=
|
||||||
allowed_number ||
|
allowedNumber ||
|
||||||
allowed_number < 0
|
allowedNumber < 0
|
||||||
) {
|
) {
|
||||||
return callback(null, true)
|
callback(null, true)
|
||||||
} else {
|
} else {
|
||||||
return callback(null, false)
|
callback(null, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -93,116 +77,115 @@ module.exports = LimitationsManager = {
|
||||||
},
|
},
|
||||||
|
|
||||||
hasPaidSubscription(user, callback) {
|
hasPaidSubscription(user, callback) {
|
||||||
if (callback == null) {
|
if (!callback) {
|
||||||
callback = function (err, hasSubscriptionOrIsMember) {}
|
callback = function (err, hasSubscriptionOrIsMember) {}
|
||||||
}
|
}
|
||||||
return this.userHasV2Subscription(
|
this.userHasV2Subscription(user, (err, hasSubscription, subscription) => {
|
||||||
user,
|
if (err) {
|
||||||
(err, hasSubscription, subscription) => {
|
return callback(err)
|
||||||
if (err != null) {
|
}
|
||||||
|
this.userIsMemberOfGroupSubscription(user, (err, isMember) => {
|
||||||
|
if (err) {
|
||||||
return callback(err)
|
return callback(err)
|
||||||
}
|
}
|
||||||
return this.userIsMemberOfGroupSubscription(user, (err, isMember) => {
|
this.userHasV1Subscription(user, (err, hasV1Subscription) => {
|
||||||
if (err != null) {
|
if (err) {
|
||||||
return callback(err)
|
|
||||||
}
|
|
||||||
return this.userHasV1Subscription(user, (err, hasV1Subscription) => {
|
|
||||||
if (err != null) {
|
|
||||||
return callback(
|
|
||||||
new V1ConnectionError(
|
|
||||||
'error getting subscription from v1'
|
|
||||||
).withCause(err)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return callback(
|
return callback(
|
||||||
err,
|
new V1ConnectionError(
|
||||||
isMember || hasSubscription || hasV1Subscription,
|
'error getting subscription from v1'
|
||||||
subscription
|
).withCause(err)
|
||||||
)
|
)
|
||||||
})
|
}
|
||||||
|
callback(
|
||||||
|
err,
|
||||||
|
isMember || hasSubscription || hasV1Subscription,
|
||||||
|
subscription
|
||||||
|
)
|
||||||
})
|
})
|
||||||
}
|
})
|
||||||
)
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
// alias for backward-compatibility with modules. Use `haspaidsubscription` instead
|
// alias for backward-compatibility with modules. Use `haspaidsubscription` instead
|
||||||
userHasSubscriptionOrIsGroupMember(user, callback) {
|
userHasSubscriptionOrIsGroupMember(user, callback) {
|
||||||
return this.hasPaidSubscription(user, callback)
|
this.hasPaidSubscription(user, callback)
|
||||||
},
|
},
|
||||||
|
|
||||||
userHasV2Subscription(user, callback) {
|
userHasV2Subscription(user, callback) {
|
||||||
if (callback == null) {
|
if (!callback) {
|
||||||
callback = function (err, hasSubscription, subscription) {}
|
callback = function (err, hasSubscription, subscription) {}
|
||||||
}
|
}
|
||||||
return SubscriptionLocator.getUsersSubscription(
|
SubscriptionLocator.getUsersSubscription(
|
||||||
user._id,
|
user._id,
|
||||||
function (err, subscription) {
|
function (err, subscription) {
|
||||||
if (err != null) {
|
if (err) {
|
||||||
return callback(err)
|
return callback(err)
|
||||||
}
|
}
|
||||||
const hasValidSubscription =
|
let hasValidSubscription = false
|
||||||
subscription != null &&
|
if (subscription) {
|
||||||
(subscription.recurlySubscription_id != null ||
|
if (
|
||||||
(subscription != null ? subscription.customAccount : undefined) ===
|
subscription.recurlySubscription_id ||
|
||||||
true)
|
subscription.customAccount
|
||||||
return callback(err, hasValidSubscription, subscription)
|
) {
|
||||||
|
hasValidSubscription = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
callback(err, hasValidSubscription, subscription)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
userHasV1OrV2Subscription(user, callback) {
|
userHasV1OrV2Subscription(user, callback) {
|
||||||
if (callback == null) {
|
if (!callback) {
|
||||||
callback = function (err, hasSubscription) {}
|
callback = function (err, hasSubscription) {}
|
||||||
}
|
}
|
||||||
return this.userHasV2Subscription(user, (err, hasV2Subscription) => {
|
this.userHasV2Subscription(user, (err, hasV2Subscription) => {
|
||||||
if (err != null) {
|
if (err) {
|
||||||
return callback(err)
|
return callback(err)
|
||||||
}
|
}
|
||||||
if (hasV2Subscription) {
|
if (hasV2Subscription) {
|
||||||
return callback(null, true)
|
return callback(null, true)
|
||||||
}
|
}
|
||||||
return this.userHasV1Subscription(user, (err, hasV1Subscription) => {
|
this.userHasV1Subscription(user, (err, hasV1Subscription) => {
|
||||||
if (err != null) {
|
if (err) {
|
||||||
return callback(err)
|
return callback(err)
|
||||||
}
|
}
|
||||||
if (hasV1Subscription) {
|
if (hasV1Subscription) {
|
||||||
return callback(null, true)
|
return callback(null, true)
|
||||||
}
|
}
|
||||||
return callback(null, false)
|
callback(null, false)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
userIsMemberOfGroupSubscription(user, callback) {
|
userIsMemberOfGroupSubscription(user, callback) {
|
||||||
if (callback == null) {
|
if (!callback) {
|
||||||
callback = function (error, isMember, subscriptions) {}
|
callback = function (error, isMember, subscriptions) {}
|
||||||
}
|
}
|
||||||
return SubscriptionLocator.getMemberSubscriptions(
|
SubscriptionLocator.getMemberSubscriptions(
|
||||||
user._id,
|
user._id,
|
||||||
function (err, subscriptions) {
|
function (err, subscriptions) {
|
||||||
if (subscriptions == null) {
|
if (!subscriptions) {
|
||||||
subscriptions = []
|
subscriptions = []
|
||||||
}
|
}
|
||||||
if (err != null) {
|
if (err) {
|
||||||
return callback(err)
|
return callback(err)
|
||||||
}
|
}
|
||||||
return callback(err, subscriptions.length > 0, subscriptions)
|
callback(err, subscriptions.length > 0, subscriptions)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
userHasV1Subscription(user, callback) {
|
userHasV1Subscription(user, callback) {
|
||||||
if (callback == null) {
|
if (!callback) {
|
||||||
callback = function (error, hasV1Subscription) {}
|
callback = function (error, hasV1Subscription) {}
|
||||||
}
|
}
|
||||||
return V1SubscriptionManager.getSubscriptionsFromV1(
|
V1SubscriptionManager.getSubscriptionsFromV1(
|
||||||
user._id,
|
user._id,
|
||||||
function (err, v1Subscription) {
|
function (err, v1Subscription) {
|
||||||
return callback(
|
callback(
|
||||||
err,
|
err,
|
||||||
!!(v1Subscription != null
|
!!(v1Subscription ? v1Subscription.has_subscription : undefined)
|
||||||
? v1Subscription.has_subscription
|
|
||||||
: undefined)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -218,19 +201,19 @@ module.exports = LimitationsManager = {
|
||||||
},
|
},
|
||||||
|
|
||||||
hasGroupMembersLimitReached(subscriptionId, callback) {
|
hasGroupMembersLimitReached(subscriptionId, callback) {
|
||||||
if (callback == null) {
|
if (!callback) {
|
||||||
callback = function (err, limitReached, subscription) {}
|
callback = function (err, limitReached, subscription) {}
|
||||||
}
|
}
|
||||||
return SubscriptionLocator.getSubscription(
|
SubscriptionLocator.getSubscription(
|
||||||
subscriptionId,
|
subscriptionId,
|
||||||
function (err, subscription) {
|
function (err, subscription) {
|
||||||
if (err != null) {
|
if (err) {
|
||||||
OError.tag(err, 'error getting subscription', {
|
OError.tag(err, 'error getting subscription', {
|
||||||
subscriptionId,
|
subscriptionId,
|
||||||
})
|
})
|
||||||
return callback(err)
|
return callback(err)
|
||||||
}
|
}
|
||||||
if (subscription == null) {
|
if (!subscription) {
|
||||||
logger.warn({ subscriptionId }, 'no subscription found')
|
logger.warn({ subscriptionId }, 'no subscription found')
|
||||||
return callback(new Error('no subscription found'))
|
return callback(new Error('no subscription found'))
|
||||||
}
|
}
|
||||||
|
@ -238,7 +221,7 @@ module.exports = LimitationsManager = {
|
||||||
const limitReached = LimitationsManager.teamHasReachedMemberLimit(
|
const limitReached = LimitationsManager.teamHasReachedMemberLimit(
|
||||||
subscription
|
subscription
|
||||||
)
|
)
|
||||||
return callback(err, limitReached, subscription)
|
callback(err, limitReached, subscription)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,17 +1,3 @@
|
||||||
/* eslint-disable
|
|
||||||
camelcase,
|
|
||||||
node/handle-callback-err,
|
|
||||||
max-len,
|
|
||||||
no-return-assign,
|
|
||||||
no-unused-vars,
|
|
||||||
*/
|
|
||||||
// TODO: This file was created by bulk-decaffeinate.
|
|
||||||
// Fix any style issues and re-enable lint.
|
|
||||||
/*
|
|
||||||
* decaffeinate suggestions:
|
|
||||||
* DS102: Remove unnecessary code created because of implicit returns
|
|
||||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
||||||
*/
|
|
||||||
const SandboxedModule = require('sandboxed-module')
|
const SandboxedModule = require('sandboxed-module')
|
||||||
const sinon = require('sinon')
|
const sinon = require('sinon')
|
||||||
const modulePath = require('path').join(
|
const modulePath = require('path').join(
|
||||||
|
@ -21,23 +7,23 @@ const modulePath = require('path').join(
|
||||||
|
|
||||||
describe('LimitationsManager', function () {
|
describe('LimitationsManager', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
this.project = { _id: (this.project_id = 'project-id') }
|
this.project = { _id: (this.projectId = 'project-id') }
|
||||||
this.user = { _id: (this.user_id = 'user-id'), features: {} }
|
this.user = { _id: (this.userId = 'user-id'), features: {} }
|
||||||
this.ProjectGetter = {
|
this.ProjectGetter = {
|
||||||
getProject: (project_id, fields, callback) => {
|
getProject: (projectId, fields, callback) => {
|
||||||
if (project_id === this.project_id) {
|
if (projectId === this.projectId) {
|
||||||
return callback(null, this.project)
|
callback(null, this.project)
|
||||||
} else {
|
} else {
|
||||||
return callback(null, null)
|
callback(null, null)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
this.UserGetter = {
|
this.UserGetter = {
|
||||||
getUser: (user_id, filter, callback) => {
|
getUser: (userId, filter, callback) => {
|
||||||
if (user_id === this.user_id) {
|
if (userId === this.userId) {
|
||||||
return callback(null, this.user)
|
callback(null, this.user)
|
||||||
} else {
|
} else {
|
||||||
return callback(null, null)
|
callback(null, null)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -47,7 +33,7 @@ describe('LimitationsManager', function () {
|
||||||
getSubscription: sinon.stub(),
|
getSubscription: sinon.stub(),
|
||||||
}
|
}
|
||||||
|
|
||||||
return (this.LimitationsManager = SandboxedModule.require(modulePath, {
|
this.LimitationsManager = SandboxedModule.require(modulePath, {
|
||||||
requires: {
|
requires: {
|
||||||
'../Project/ProjectGetter': this.ProjectGetter,
|
'../Project/ProjectGetter': this.ProjectGetter,
|
||||||
'../User/UserGetter': this.UserGetter,
|
'../User/UserGetter': this.UserGetter,
|
||||||
|
@ -57,24 +43,24 @@ describe('LimitationsManager', function () {
|
||||||
'../Collaborators/CollaboratorsInviteHandler': (this.CollaboratorsInviteHandler = {}),
|
'../Collaborators/CollaboratorsInviteHandler': (this.CollaboratorsInviteHandler = {}),
|
||||||
'./V1SubscriptionManager': (this.V1SubscriptionManager = {}),
|
'./V1SubscriptionManager': (this.V1SubscriptionManager = {}),
|
||||||
},
|
},
|
||||||
}))
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('allowedNumberOfCollaboratorsInProject', function () {
|
describe('allowedNumberOfCollaboratorsInProject', function () {
|
||||||
describe('when the project is owned by a user without a subscription', function () {
|
describe('when the project is owned by a user without a subscription', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
this.Settings.defaultFeatures = { collaborators: 23 }
|
this.Settings.defaultFeatures = { collaborators: 23 }
|
||||||
this.project.owner_ref = this.user_id
|
this.project.owner_ref = this.userId
|
||||||
delete this.user.features
|
delete this.user.features
|
||||||
this.callback = sinon.stub()
|
this.callback = sinon.stub()
|
||||||
return this.LimitationsManager.allowedNumberOfCollaboratorsInProject(
|
this.LimitationsManager.allowedNumberOfCollaboratorsInProject(
|
||||||
this.project_id,
|
this.projectId,
|
||||||
this.callback
|
this.callback
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return the default number', function () {
|
it('should return the default number', function () {
|
||||||
return this.callback
|
this.callback
|
||||||
.calledWith(null, this.Settings.defaultFeatures.collaborators)
|
.calledWith(null, this.Settings.defaultFeatures.collaborators)
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
})
|
})
|
||||||
|
@ -82,17 +68,17 @@ describe('LimitationsManager', function () {
|
||||||
|
|
||||||
describe('when the project is owned by a user with a subscription', function () {
|
describe('when the project is owned by a user with a subscription', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
this.project.owner_ref = this.user_id
|
this.project.owner_ref = this.userId
|
||||||
this.user.features = { collaborators: 21 }
|
this.user.features = { collaborators: 21 }
|
||||||
this.callback = sinon.stub()
|
this.callback = sinon.stub()
|
||||||
return this.LimitationsManager.allowedNumberOfCollaboratorsInProject(
|
this.LimitationsManager.allowedNumberOfCollaboratorsInProject(
|
||||||
this.project_id,
|
this.projectId,
|
||||||
this.callback
|
this.callback
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
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
|
this.callback
|
||||||
.calledWith(null, this.user.features.collaborators)
|
.calledWith(null, this.user.features.collaborators)
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
})
|
})
|
||||||
|
@ -105,14 +91,14 @@ describe('LimitationsManager', function () {
|
||||||
this.Settings.defaultFeatures = { collaborators: 23 }
|
this.Settings.defaultFeatures = { collaborators: 23 }
|
||||||
delete this.user.features
|
delete this.user.features
|
||||||
this.callback = sinon.stub()
|
this.callback = sinon.stub()
|
||||||
return this.LimitationsManager.allowedNumberOfCollaboratorsForUser(
|
this.LimitationsManager.allowedNumberOfCollaboratorsForUser(
|
||||||
this.user_id,
|
this.userId,
|
||||||
this.callback
|
this.callback
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return the default number', function () {
|
it('should return the default number', function () {
|
||||||
return this.callback
|
this.callback
|
||||||
.calledWith(null, this.Settings.defaultFeatures.collaborators)
|
.calledWith(null, this.Settings.defaultFeatures.collaborators)
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
})
|
})
|
||||||
|
@ -122,14 +108,14 @@ describe('LimitationsManager', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
this.user.features = { collaborators: 21 }
|
this.user.features = { collaborators: 21 }
|
||||||
this.callback = sinon.stub()
|
this.callback = sinon.stub()
|
||||||
return this.LimitationsManager.allowedNumberOfCollaboratorsForUser(
|
this.LimitationsManager.allowedNumberOfCollaboratorsForUser(
|
||||||
this.user_id,
|
this.userId,
|
||||||
this.callback
|
this.callback
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
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
|
this.callback
|
||||||
.calledWith(null, this.user.features.collaborators)
|
.calledWith(null, this.user.features.collaborators)
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
})
|
})
|
||||||
|
@ -143,11 +129,11 @@ describe('LimitationsManager', function () {
|
||||||
this.allowed_number = 2
|
this.allowed_number = 2
|
||||||
this.invite_count = 0
|
this.invite_count = 0
|
||||||
this.CollaboratorsGetter.getInvitedCollaboratorCount = (
|
this.CollaboratorsGetter.getInvitedCollaboratorCount = (
|
||||||
project_id,
|
projectId,
|
||||||
callback
|
callback
|
||||||
) => callback(null, this.current_number)
|
) => callback(null, this.current_number)
|
||||||
this.CollaboratorsInviteHandler.getInviteCount = (
|
this.CollaboratorsInviteHandler.getInviteCount = (
|
||||||
project_id,
|
projectId,
|
||||||
callback
|
callback
|
||||||
) => callback(null, this.invite_count)
|
) => callback(null, this.invite_count)
|
||||||
sinon
|
sinon
|
||||||
|
@ -155,19 +141,19 @@ describe('LimitationsManager', function () {
|
||||||
this.LimitationsManager,
|
this.LimitationsManager,
|
||||||
'allowedNumberOfCollaboratorsInProject'
|
'allowedNumberOfCollaboratorsInProject'
|
||||||
)
|
)
|
||||||
.callsFake((project_id, callback) => {
|
.callsFake((projectId, callback) => {
|
||||||
return callback(null, this.allowed_number)
|
callback(null, this.allowed_number)
|
||||||
})
|
})
|
||||||
this.callback = sinon.stub()
|
this.callback = sinon.stub()
|
||||||
return this.LimitationsManager.canAddXCollaborators(
|
this.LimitationsManager.canAddXCollaborators(
|
||||||
this.project_id,
|
this.projectId,
|
||||||
1,
|
1,
|
||||||
this.callback
|
this.callback
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return true', function () {
|
it('should return true', function () {
|
||||||
return this.callback.calledWith(null, true).should.equal(true)
|
this.callback.calledWith(null, true).should.equal(true)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -177,11 +163,11 @@ describe('LimitationsManager', function () {
|
||||||
this.allowed_number = 4
|
this.allowed_number = 4
|
||||||
this.invite_count = 1
|
this.invite_count = 1
|
||||||
this.CollaboratorsGetter.getInvitedCollaboratorCount = (
|
this.CollaboratorsGetter.getInvitedCollaboratorCount = (
|
||||||
project_id,
|
projectId,
|
||||||
callback
|
callback
|
||||||
) => callback(null, this.current_number)
|
) => callback(null, this.current_number)
|
||||||
this.CollaboratorsInviteHandler.getInviteCount = (
|
this.CollaboratorsInviteHandler.getInviteCount = (
|
||||||
project_id,
|
projectId,
|
||||||
callback
|
callback
|
||||||
) => callback(null, this.invite_count)
|
) => callback(null, this.invite_count)
|
||||||
sinon
|
sinon
|
||||||
|
@ -189,19 +175,19 @@ describe('LimitationsManager', function () {
|
||||||
this.LimitationsManager,
|
this.LimitationsManager,
|
||||||
'allowedNumberOfCollaboratorsInProject'
|
'allowedNumberOfCollaboratorsInProject'
|
||||||
)
|
)
|
||||||
.callsFake((project_id, callback) => {
|
.callsFake((projectId, callback) => {
|
||||||
return callback(null, this.allowed_number)
|
callback(null, this.allowed_number)
|
||||||
})
|
})
|
||||||
this.callback = sinon.stub()
|
this.callback = sinon.stub()
|
||||||
return this.LimitationsManager.canAddXCollaborators(
|
this.LimitationsManager.canAddXCollaborators(
|
||||||
this.project_id,
|
this.projectId,
|
||||||
1,
|
1,
|
||||||
this.callback
|
this.callback
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return true', function () {
|
it('should return true', function () {
|
||||||
return this.callback.calledWith(null, true).should.equal(true)
|
this.callback.calledWith(null, true).should.equal(true)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -211,11 +197,11 @@ describe('LimitationsManager', function () {
|
||||||
this.allowed_number = 2
|
this.allowed_number = 2
|
||||||
this.invite_count = 0
|
this.invite_count = 0
|
||||||
this.CollaboratorsGetter.getInvitedCollaboratorCount = (
|
this.CollaboratorsGetter.getInvitedCollaboratorCount = (
|
||||||
project_id,
|
projectId,
|
||||||
callback
|
callback
|
||||||
) => callback(null, this.current_number)
|
) => callback(null, this.current_number)
|
||||||
this.CollaboratorsInviteHandler.getInviteCount = (
|
this.CollaboratorsInviteHandler.getInviteCount = (
|
||||||
project_id,
|
projectId,
|
||||||
callback
|
callback
|
||||||
) => callback(null, this.invite_count)
|
) => callback(null, this.invite_count)
|
||||||
sinon
|
sinon
|
||||||
|
@ -223,19 +209,19 @@ describe('LimitationsManager', function () {
|
||||||
this.LimitationsManager,
|
this.LimitationsManager,
|
||||||
'allowedNumberOfCollaboratorsInProject'
|
'allowedNumberOfCollaboratorsInProject'
|
||||||
)
|
)
|
||||||
.callsFake((project_id, callback) => {
|
.callsFake((projectId, callback) => {
|
||||||
return callback(null, this.allowed_number)
|
callback(null, this.allowed_number)
|
||||||
})
|
})
|
||||||
this.callback = sinon.stub()
|
this.callback = sinon.stub()
|
||||||
return this.LimitationsManager.canAddXCollaborators(
|
this.LimitationsManager.canAddXCollaborators(
|
||||||
this.project_id,
|
this.projectId,
|
||||||
2,
|
2,
|
||||||
this.callback
|
this.callback
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return false', function () {
|
it('should return false', function () {
|
||||||
return this.callback.calledWith(null, false).should.equal(true)
|
this.callback.calledWith(null, false).should.equal(true)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -245,11 +231,11 @@ describe('LimitationsManager', function () {
|
||||||
this.allowed_number = 2
|
this.allowed_number = 2
|
||||||
this.invite_count = 0
|
this.invite_count = 0
|
||||||
this.CollaboratorsGetter.getInvitedCollaboratorCount = (
|
this.CollaboratorsGetter.getInvitedCollaboratorCount = (
|
||||||
project_id,
|
projectId,
|
||||||
callback
|
callback
|
||||||
) => callback(null, this.current_number)
|
) => callback(null, this.current_number)
|
||||||
this.CollaboratorsInviteHandler.getInviteCount = (
|
this.CollaboratorsInviteHandler.getInviteCount = (
|
||||||
project_id,
|
projectId,
|
||||||
callback
|
callback
|
||||||
) => callback(null, this.invite_count)
|
) => callback(null, this.invite_count)
|
||||||
sinon
|
sinon
|
||||||
|
@ -257,19 +243,19 @@ describe('LimitationsManager', function () {
|
||||||
this.LimitationsManager,
|
this.LimitationsManager,
|
||||||
'allowedNumberOfCollaboratorsInProject'
|
'allowedNumberOfCollaboratorsInProject'
|
||||||
)
|
)
|
||||||
.callsFake((project_id, callback) => {
|
.callsFake((projectId, callback) => {
|
||||||
return callback(null, this.allowed_number)
|
callback(null, this.allowed_number)
|
||||||
})
|
})
|
||||||
this.callback = sinon.stub()
|
this.callback = sinon.stub()
|
||||||
return this.LimitationsManager.canAddXCollaborators(
|
this.LimitationsManager.canAddXCollaborators(
|
||||||
this.project_id,
|
this.projectId,
|
||||||
1,
|
1,
|
||||||
this.callback
|
this.callback
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return false', function () {
|
it('should return false', function () {
|
||||||
return this.callback.calledWith(null, false).should.equal(true)
|
this.callback.calledWith(null, false).should.equal(true)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -279,11 +265,11 @@ describe('LimitationsManager', function () {
|
||||||
this.allowed_number = -1
|
this.allowed_number = -1
|
||||||
this.invite_count = 0
|
this.invite_count = 0
|
||||||
this.CollaboratorsGetter.getInvitedCollaboratorCount = (
|
this.CollaboratorsGetter.getInvitedCollaboratorCount = (
|
||||||
project_id,
|
projectId,
|
||||||
callback
|
callback
|
||||||
) => callback(null, this.current_number)
|
) => callback(null, this.current_number)
|
||||||
this.CollaboratorsInviteHandler.getInviteCount = (
|
this.CollaboratorsInviteHandler.getInviteCount = (
|
||||||
project_id,
|
projectId,
|
||||||
callback
|
callback
|
||||||
) => callback(null, this.invite_count)
|
) => callback(null, this.invite_count)
|
||||||
sinon
|
sinon
|
||||||
|
@ -291,19 +277,19 @@ describe('LimitationsManager', function () {
|
||||||
this.LimitationsManager,
|
this.LimitationsManager,
|
||||||
'allowedNumberOfCollaboratorsInProject'
|
'allowedNumberOfCollaboratorsInProject'
|
||||||
)
|
)
|
||||||
.callsFake((project_id, callback) => {
|
.callsFake((projectId, callback) => {
|
||||||
return callback(null, this.allowed_number)
|
callback(null, this.allowed_number)
|
||||||
})
|
})
|
||||||
this.callback = sinon.stub()
|
this.callback = sinon.stub()
|
||||||
return this.LimitationsManager.canAddXCollaborators(
|
this.LimitationsManager.canAddXCollaborators(
|
||||||
this.project_id,
|
this.projectId,
|
||||||
1,
|
1,
|
||||||
this.callback
|
this.callback
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return true', function () {
|
it('should return true', function () {
|
||||||
return this.callback.calledWith(null, true).should.equal(true)
|
this.callback.calledWith(null, true).should.equal(true)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -313,11 +299,11 @@ describe('LimitationsManager', function () {
|
||||||
this.allowed_number = 2
|
this.allowed_number = 2
|
||||||
this.invite_count = 2
|
this.invite_count = 2
|
||||||
this.CollaboratorsGetter.getInvitedCollaboratorCount = (
|
this.CollaboratorsGetter.getInvitedCollaboratorCount = (
|
||||||
project_id,
|
projectId,
|
||||||
callback
|
callback
|
||||||
) => callback(null, this.current_number)
|
) => callback(null, this.current_number)
|
||||||
this.CollaboratorsInviteHandler.getInviteCount = (
|
this.CollaboratorsInviteHandler.getInviteCount = (
|
||||||
project_id,
|
projectId,
|
||||||
callback
|
callback
|
||||||
) => callback(null, this.invite_count)
|
) => callback(null, this.invite_count)
|
||||||
sinon
|
sinon
|
||||||
|
@ -325,19 +311,19 @@ describe('LimitationsManager', function () {
|
||||||
this.LimitationsManager,
|
this.LimitationsManager,
|
||||||
'allowedNumberOfCollaboratorsInProject'
|
'allowedNumberOfCollaboratorsInProject'
|
||||||
)
|
)
|
||||||
.callsFake((project_id, callback) => {
|
.callsFake((projectId, callback) => {
|
||||||
return callback(null, this.allowed_number)
|
callback(null, this.allowed_number)
|
||||||
})
|
})
|
||||||
this.callback = sinon.stub()
|
this.callback = sinon.stub()
|
||||||
return this.LimitationsManager.canAddXCollaborators(
|
this.LimitationsManager.canAddXCollaborators(
|
||||||
this.project_id,
|
this.projectId,
|
||||||
1,
|
1,
|
||||||
this.callback
|
this.callback
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return false', function () {
|
it('should return false', function () {
|
||||||
return this.callback.calledWith(null, false).should.equal(true)
|
this.callback.calledWith(null, false).should.equal(true)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -347,11 +333,11 @@ describe('LimitationsManager', function () {
|
||||||
this.allowed_number = 2
|
this.allowed_number = 2
|
||||||
this.invite_count = 1
|
this.invite_count = 1
|
||||||
this.CollaboratorsGetter.getInvitedCollaboratorCount = (
|
this.CollaboratorsGetter.getInvitedCollaboratorCount = (
|
||||||
project_id,
|
projectId,
|
||||||
callback
|
callback
|
||||||
) => callback(null, this.current_number)
|
) => callback(null, this.current_number)
|
||||||
this.CollaboratorsInviteHandler.getInviteCount = (
|
this.CollaboratorsInviteHandler.getInviteCount = (
|
||||||
project_id,
|
projectId,
|
||||||
callback
|
callback
|
||||||
) => callback(null, this.invite_count)
|
) => callback(null, this.invite_count)
|
||||||
sinon
|
sinon
|
||||||
|
@ -359,37 +345,37 @@ describe('LimitationsManager', function () {
|
||||||
this.LimitationsManager,
|
this.LimitationsManager,
|
||||||
'allowedNumberOfCollaboratorsInProject'
|
'allowedNumberOfCollaboratorsInProject'
|
||||||
)
|
)
|
||||||
.callsFake((project_id, callback) => {
|
.callsFake((projectId, callback) => {
|
||||||
return callback(null, this.allowed_number)
|
callback(null, this.allowed_number)
|
||||||
})
|
})
|
||||||
this.callback = sinon.stub()
|
this.callback = sinon.stub()
|
||||||
return this.LimitationsManager.canAddXCollaborators(
|
this.LimitationsManager.canAddXCollaborators(
|
||||||
this.project_id,
|
this.projectId,
|
||||||
1,
|
1,
|
||||||
this.callback
|
this.callback
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return false', function () {
|
it('should return false', function () {
|
||||||
return this.callback.calledWith(null, false).should.equal(true)
|
this.callback.calledWith(null, false).should.equal(true)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('userHasV2Subscription', function () {
|
describe('userHasV2Subscription', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
return (this.SubscriptionLocator.getUsersSubscription = sinon.stub())
|
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, {
|
this.SubscriptionLocator.getUsersSubscription.callsArgWith(1, null, {
|
||||||
recurlySubscription_id: '1234',
|
recurlySubscription_id: '1234',
|
||||||
})
|
})
|
||||||
return this.LimitationsManager.userHasV2Subscription(
|
this.LimitationsManager.userHasV2Subscription(
|
||||||
this.user,
|
this.user,
|
||||||
(err, hasSubscription) => {
|
(err, hasSubscription) => {
|
||||||
hasSubscription.should.equal(true)
|
hasSubscription.should.equal(true)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -397,22 +383,22 @@ 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.SubscriptionLocator.getUsersSubscription.callsArgWith(1, null, {})
|
||||||
this.subscription = {}
|
this.subscription = {}
|
||||||
return this.LimitationsManager.userHasV2Subscription(
|
this.LimitationsManager.userHasV2Subscription(
|
||||||
this.user,
|
this.user,
|
||||||
(err, hasSubscription) => {
|
(err, hasSubscription) => {
|
||||||
hasSubscription.should.equal(false)
|
hasSubscription.should.equal(false)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
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)
|
this.SubscriptionLocator.getUsersSubscription.callsArgWith(1)
|
||||||
return this.LimitationsManager.userHasV2Subscription(
|
this.LimitationsManager.userHasV2Subscription(
|
||||||
this.user,
|
this.user,
|
||||||
(err, hasSubscription) => {
|
(err, hasSubscription) => {
|
||||||
hasSubscription.should.equal(false)
|
hasSubscription.should.equal(false)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -424,11 +410,11 @@ describe('LimitationsManager', function () {
|
||||||
null,
|
null,
|
||||||
stubbedSubscription
|
stubbedSubscription
|
||||||
)
|
)
|
||||||
return this.LimitationsManager.userHasV2Subscription(
|
this.LimitationsManager.userHasV2Subscription(
|
||||||
this.user,
|
this.user,
|
||||||
(err, hasSubOrIsGroupMember, subscription) => {
|
(err, hasSubOrIsGroupMember, subscription) => {
|
||||||
subscription.should.deep.equal(stubbedSubscription)
|
subscription.should.deep.equal(stubbedSubscription)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -436,7 +422,7 @@ describe('LimitationsManager', function () {
|
||||||
describe('when user has a custom account', function () {
|
describe('when user has a custom account', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
this.fakeSubscription = { customAccount: true }
|
this.fakeSubscription = { customAccount: true }
|
||||||
return this.SubscriptionLocator.getUsersSubscription.callsArgWith(
|
this.SubscriptionLocator.getUsersSubscription.callsArgWith(
|
||||||
1,
|
1,
|
||||||
null,
|
null,
|
||||||
this.fakeSubscription
|
this.fakeSubscription
|
||||||
|
@ -444,21 +430,21 @@ describe('LimitationsManager', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return true', function (done) {
|
it('should return true', function (done) {
|
||||||
return this.LimitationsManager.userHasV2Subscription(
|
this.LimitationsManager.userHasV2Subscription(
|
||||||
this.user,
|
this.user,
|
||||||
(err, hasSubscription, subscription) => {
|
(err, hasSubscription, subscription) => {
|
||||||
hasSubscription.should.equal(true)
|
hasSubscription.should.equal(true)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return the subscription', function (done) {
|
it('should return the subscription', function (done) {
|
||||||
return this.LimitationsManager.userHasV2Subscription(
|
this.LimitationsManager.userHasV2Subscription(
|
||||||
this.user,
|
this.user,
|
||||||
(err, hasSubscription, subscription) => {
|
(err, hasSubscription, subscription) => {
|
||||||
subscription.should.deep.equal(this.fakeSubscription)
|
subscription.should.deep.equal(this.fakeSubscription)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -467,16 +453,16 @@ describe('LimitationsManager', function () {
|
||||||
|
|
||||||
describe('userIsMemberOfGroupSubscription', function () {
|
describe('userIsMemberOfGroupSubscription', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
return (this.SubscriptionLocator.getMemberSubscriptions = sinon.stub())
|
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, [])
|
this.SubscriptionLocator.getMemberSubscriptions.callsArgWith(1, null, [])
|
||||||
return this.LimitationsManager.userIsMemberOfGroupSubscription(
|
this.LimitationsManager.userIsMemberOfGroupSubscription(
|
||||||
this.user,
|
this.user,
|
||||||
(err, isMember) => {
|
(err, isMember) => {
|
||||||
isMember.should.equal(false)
|
isMember.should.equal(false)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -488,12 +474,12 @@ describe('LimitationsManager', function () {
|
||||||
null,
|
null,
|
||||||
(subscriptions = ['mock-subscription'])
|
(subscriptions = ['mock-subscription'])
|
||||||
)
|
)
|
||||||
return this.LimitationsManager.userIsMemberOfGroupSubscription(
|
this.LimitationsManager.userIsMemberOfGroupSubscription(
|
||||||
this.user,
|
this.user,
|
||||||
(err, isMember, retSubscriptions) => {
|
(err, isMember, retSubscriptions) => {
|
||||||
isMember.should.equal(true)
|
isMember.should.equal(true)
|
||||||
retSubscriptions.should.equal(subscriptions)
|
retSubscriptions.should.equal(subscriptions)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -507,20 +493,20 @@ describe('LimitationsManager', function () {
|
||||||
this.LimitationsManager.userHasV2Subscription = sinon
|
this.LimitationsManager.userHasV2Subscription = sinon
|
||||||
.stub()
|
.stub()
|
||||||
.yields(null, false)
|
.yields(null, false)
|
||||||
return (this.LimitationsManager.userHasV1Subscription = sinon
|
this.LimitationsManager.userHasV1Subscription = sinon
|
||||||
.stub()
|
.stub()
|
||||||
.yields(null, false))
|
.yields(null, false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return true if userIsMemberOfGroupSubscription', function (done) {
|
it('should return true if userIsMemberOfGroupSubscription', function (done) {
|
||||||
this.LimitationsManager.userIsMemberOfGroupSubscription = sinon
|
this.LimitationsManager.userIsMemberOfGroupSubscription = sinon
|
||||||
.stub()
|
.stub()
|
||||||
.yields(null, true)
|
.yields(null, true)
|
||||||
return this.LimitationsManager.hasPaidSubscription(
|
this.LimitationsManager.hasPaidSubscription(
|
||||||
this.user,
|
this.user,
|
||||||
(err, hasSubOrIsGroupMember) => {
|
(err, hasSubOrIsGroupMember) => {
|
||||||
hasSubOrIsGroupMember.should.equal(true)
|
hasSubOrIsGroupMember.should.equal(true)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -529,11 +515,11 @@ describe('LimitationsManager', function () {
|
||||||
this.LimitationsManager.userHasV2Subscription = sinon
|
this.LimitationsManager.userHasV2Subscription = sinon
|
||||||
.stub()
|
.stub()
|
||||||
.yields(null, true)
|
.yields(null, true)
|
||||||
return this.LimitationsManager.hasPaidSubscription(
|
this.LimitationsManager.hasPaidSubscription(
|
||||||
this.user,
|
this.user,
|
||||||
(err, hasSubOrIsGroupMember) => {
|
(err, hasSubOrIsGroupMember) => {
|
||||||
hasSubOrIsGroupMember.should.equal(true)
|
hasSubOrIsGroupMember.should.equal(true)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -542,31 +528,31 @@ describe('LimitationsManager', function () {
|
||||||
this.LimitationsManager.userHasV1Subscription = sinon
|
this.LimitationsManager.userHasV1Subscription = sinon
|
||||||
.stub()
|
.stub()
|
||||||
.yields(null, true)
|
.yields(null, true)
|
||||||
return this.LimitationsManager.hasPaidSubscription(
|
this.LimitationsManager.hasPaidSubscription(
|
||||||
this.user,
|
this.user,
|
||||||
(err, hasSubOrIsGroupMember) => {
|
(err, hasSubOrIsGroupMember) => {
|
||||||
hasSubOrIsGroupMember.should.equal(true)
|
hasSubOrIsGroupMember.should.equal(true)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
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.LimitationsManager.hasPaidSubscription(
|
||||||
this.user,
|
this.user,
|
||||||
(err, hasSubOrIsGroupMember) => {
|
(err, hasSubOrIsGroupMember) => {
|
||||||
hasSubOrIsGroupMember.should.equal(false)
|
hasSubOrIsGroupMember.should.equal(false)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should have userHasSubscriptionOrIsGroupMember alias', function (done) {
|
it('should have userHasSubscriptionOrIsGroupMember alias', function (done) {
|
||||||
return this.LimitationsManager.userHasSubscriptionOrIsGroupMember(
|
this.LimitationsManager.userHasSubscriptionOrIsGroupMember(
|
||||||
this.user,
|
this.user,
|
||||||
(err, hasSubOrIsGroupMember) => {
|
(err, hasSubOrIsGroupMember) => {
|
||||||
hasSubOrIsGroupMember.should.equal(false)
|
hasSubOrIsGroupMember.should.equal(false)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -577,20 +563,20 @@ describe('LimitationsManager', function () {
|
||||||
this.LimitationsManager.userHasV2Subscription = sinon
|
this.LimitationsManager.userHasV2Subscription = sinon
|
||||||
.stub()
|
.stub()
|
||||||
.yields(null, false)
|
.yields(null, false)
|
||||||
return (this.LimitationsManager.userHasV1Subscription = sinon
|
this.LimitationsManager.userHasV1Subscription = sinon
|
||||||
.stub()
|
.stub()
|
||||||
.yields(null, false))
|
.yields(null, false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return true if userHasV2Subscription', function (done) {
|
it('should return true if userHasV2Subscription', function (done) {
|
||||||
this.LimitationsManager.userHasV2Subscription = sinon
|
this.LimitationsManager.userHasV2Subscription = sinon
|
||||||
.stub()
|
.stub()
|
||||||
.yields(null, true)
|
.yields(null, true)
|
||||||
return this.LimitationsManager.userHasV1OrV2Subscription(
|
this.LimitationsManager.userHasV1OrV2Subscription(
|
||||||
this.user,
|
this.user,
|
||||||
(err, hasSub) => {
|
(err, hasSub) => {
|
||||||
hasSub.should.equal(true)
|
hasSub.should.equal(true)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -599,21 +585,21 @@ describe('LimitationsManager', function () {
|
||||||
this.LimitationsManager.userHasV1Subscription = sinon
|
this.LimitationsManager.userHasV1Subscription = sinon
|
||||||
.stub()
|
.stub()
|
||||||
.yields(null, true)
|
.yields(null, true)
|
||||||
return this.LimitationsManager.userHasV1OrV2Subscription(
|
this.LimitationsManager.userHasV1OrV2Subscription(
|
||||||
this.user,
|
this.user,
|
||||||
(err, hasSub) => {
|
(err, hasSub) => {
|
||||||
hasSub.should.equal(true)
|
hasSub.should.equal(true)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
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.LimitationsManager.userHasV1OrV2Subscription(
|
||||||
this.user,
|
this.user,
|
||||||
(err, hasSub) => {
|
(err, hasSub) => {
|
||||||
hasSub.should.equal(false)
|
hasSub.should.equal(false)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -622,13 +608,13 @@ describe('LimitationsManager', function () {
|
||||||
describe('hasGroupMembersLimitReached', function () {
|
describe('hasGroupMembersLimitReached', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
this.subscriptionId = '12312'
|
this.subscriptionId = '12312'
|
||||||
return (this.subscription = {
|
this.subscription = {
|
||||||
membersLimit: 3,
|
membersLimit: 3,
|
||||||
member_ids: ['', ''],
|
member_ids: ['', ''],
|
||||||
teamInvites: [
|
teamInvites: [
|
||||||
{ email: 'bob@example.com', sentAt: new Date(), token: 'hey' },
|
{ email: 'bob@example.com', sentAt: new Date(), token: 'hey' },
|
||||||
],
|
],
|
||||||
})
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
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) {
|
||||||
|
@ -637,11 +623,11 @@ describe('LimitationsManager', function () {
|
||||||
null,
|
null,
|
||||||
this.subscription
|
this.subscription
|
||||||
)
|
)
|
||||||
return this.LimitationsManager.hasGroupMembersLimitReached(
|
this.LimitationsManager.hasGroupMembersLimitReached(
|
||||||
this.subscriptionId,
|
this.subscriptionId,
|
||||||
(err, limitReached) => {
|
(err, limitReached) => {
|
||||||
limitReached.should.equal(true)
|
limitReached.should.equal(true)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -653,11 +639,11 @@ describe('LimitationsManager', function () {
|
||||||
null,
|
null,
|
||||||
this.subscription
|
this.subscription
|
||||||
)
|
)
|
||||||
return this.LimitationsManager.hasGroupMembersLimitReached(
|
this.LimitationsManager.hasGroupMembersLimitReached(
|
||||||
this.subscriptionId,
|
this.subscriptionId,
|
||||||
(err, limitReached) => {
|
(err, limitReached) => {
|
||||||
limitReached.should.equal(false)
|
limitReached.should.equal(false)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -669,11 +655,11 @@ describe('LimitationsManager', function () {
|
||||||
null,
|
null,
|
||||||
this.subscription
|
this.subscription
|
||||||
)
|
)
|
||||||
return this.LimitationsManager.hasGroupMembersLimitReached(
|
this.LimitationsManager.hasGroupMembersLimitReached(
|
||||||
this.subscriptionId,
|
this.subscriptionId,
|
||||||
(err, limitReached) => {
|
(err, limitReached) => {
|
||||||
limitReached.should.equal(true)
|
limitReached.should.equal(true)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -684,14 +670,14 @@ describe('LimitationsManager', function () {
|
||||||
this.V1SubscriptionManager.getSubscriptionsFromV1 = sinon
|
this.V1SubscriptionManager.getSubscriptionsFromV1 = sinon
|
||||||
.stub()
|
.stub()
|
||||||
.yields(null, { has_subscription: true })
|
.yields(null, { has_subscription: true })
|
||||||
return this.LimitationsManager.userHasV1Subscription(
|
this.LimitationsManager.userHasV1Subscription(
|
||||||
this.user,
|
this.user,
|
||||||
(error, result) => {
|
(error, result) => {
|
||||||
this.V1SubscriptionManager.getSubscriptionsFromV1
|
this.V1SubscriptionManager.getSubscriptionsFromV1
|
||||||
.calledWith(this.user_id)
|
.calledWith(this.userId)
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
result.should.equal(true)
|
result.should.equal(true)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -700,14 +686,14 @@ describe('LimitationsManager', function () {
|
||||||
this.V1SubscriptionManager.getSubscriptionsFromV1 = sinon
|
this.V1SubscriptionManager.getSubscriptionsFromV1 = sinon
|
||||||
.stub()
|
.stub()
|
||||||
.yields(null, { has_subscription: false })
|
.yields(null, { has_subscription: false })
|
||||||
return this.LimitationsManager.userHasV1Subscription(
|
this.LimitationsManager.userHasV1Subscription(
|
||||||
this.user,
|
this.user,
|
||||||
(error, result) => {
|
(error, result) => {
|
||||||
this.V1SubscriptionManager.getSubscriptionsFromV1
|
this.V1SubscriptionManager.getSubscriptionsFromV1
|
||||||
.calledWith(this.user_id)
|
.calledWith(this.userId)
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
result.should.equal(false)
|
result.should.equal(false)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -716,14 +702,14 @@ describe('LimitationsManager', function () {
|
||||||
this.V1SubscriptionManager.getSubscriptionsFromV1 = sinon
|
this.V1SubscriptionManager.getSubscriptionsFromV1 = sinon
|
||||||
.stub()
|
.stub()
|
||||||
.yields(null, null)
|
.yields(null, null)
|
||||||
return this.LimitationsManager.userHasV1Subscription(
|
this.LimitationsManager.userHasV1Subscription(
|
||||||
this.user,
|
this.user,
|
||||||
(error, result) => {
|
(error, result) => {
|
||||||
this.V1SubscriptionManager.getSubscriptionsFromV1
|
this.V1SubscriptionManager.getSubscriptionsFromV1
|
||||||
.calledWith(this.user_id)
|
.calledWith(this.userId)
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
result.should.equal(false)
|
result.should.equal(false)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue