2019-05-29 05:21:06 -04:00
|
|
|
/* eslint-disable
|
|
|
|
camelcase,
|
|
|
|
handle-callback-err,
|
|
|
|
max-len,
|
|
|
|
no-return-assign,
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
const sinon = require('sinon')
|
|
|
|
require('chai').should()
|
|
|
|
const modulePath = require('path').join(
|
|
|
|
__dirname,
|
|
|
|
'../../../../app/src/Features/Subscription/LimitationsManager'
|
|
|
|
)
|
|
|
|
const Settings = require('settings-sharelatex')
|
|
|
|
|
|
|
|
describe('LimitationsManager', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.project = { _id: (this.project_id = 'project-id') }
|
|
|
|
this.user = { _id: (this.user_id = 'user-id'), features: {} }
|
|
|
|
this.ProjectGetter = {
|
|
|
|
getProject: (project_id, fields, callback) => {
|
|
|
|
if (project_id === this.project_id) {
|
|
|
|
return callback(null, this.project)
|
|
|
|
} else {
|
|
|
|
return callback(null, null)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.UserGetter = {
|
|
|
|
getUser: (user_id, filter, callback) => {
|
|
|
|
if (user_id === this.user_id) {
|
|
|
|
return callback(null, this.user)
|
|
|
|
} else {
|
|
|
|
return callback(null, null)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.SubscriptionLocator = {
|
|
|
|
getUsersSubscription: sinon.stub(),
|
|
|
|
getSubscription: sinon.stub()
|
|
|
|
}
|
|
|
|
|
|
|
|
return (this.LimitationsManager = SandboxedModule.require(modulePath, {
|
2019-07-15 06:33:47 -04:00
|
|
|
globals: {
|
|
|
|
console: console
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
requires: {
|
|
|
|
'../Project/ProjectGetter': this.ProjectGetter,
|
|
|
|
'../User/UserGetter': this.UserGetter,
|
|
|
|
'./SubscriptionLocator': this.SubscriptionLocator,
|
|
|
|
'settings-sharelatex': (this.Settings = {}),
|
|
|
|
'../Collaborators/CollaboratorsHandler': (this.CollaboratorsHandler = {}),
|
|
|
|
'../Collaborators/CollaboratorsInviteHandler': (this.CollaboratorsInviteHandler = {}),
|
|
|
|
'./V1SubscriptionManager': (this.V1SubscriptionManager = {}),
|
|
|
|
'logger-sharelatex': {
|
|
|
|
log() {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
|
|
|
|
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
|
|
|
|
this.callback = sinon.stub()
|
|
|
|
return this.LimitationsManager.allowedNumberOfCollaboratorsInProject(
|
|
|
|
this.project_id,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should return the default number', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.callback
|
|
|
|
.calledWith(null, this.Settings.defaultFeatures.collaborators)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
describe('when the project is owned by a user with a subscription', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
beforeEach(function() {
|
|
|
|
this.project.owner_ref = this.user_id
|
|
|
|
this.user.features = { collaborators: 21 }
|
|
|
|
this.callback = sinon.stub()
|
|
|
|
return this.LimitationsManager.allowedNumberOfCollaboratorsInProject(
|
|
|
|
this.project_id,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should return the number of collaborators the user is allowed', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.callback
|
|
|
|
.calledWith(null, this.user.features.collaborators)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
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()
|
|
|
|
return this.LimitationsManager.allowedNumberOfCollaboratorsForUser(
|
|
|
|
this.user_id,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should return the default number', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.callback
|
|
|
|
.calledWith(null, this.Settings.defaultFeatures.collaborators)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
describe('when the user has features', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
beforeEach(function() {
|
|
|
|
this.user.features = { collaborators: 21 }
|
|
|
|
this.callback = sinon.stub()
|
|
|
|
return this.LimitationsManager.allowedNumberOfCollaboratorsForUser(
|
|
|
|
this.user_id,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should return the number of collaborators the user is allowed', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.callback
|
|
|
|
.calledWith(null, this.user.features.collaborators)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
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
|
|
|
|
this.CollaboratorsHandler.getInvitedCollaboratorCount = (
|
|
|
|
project_id,
|
|
|
|
callback
|
|
|
|
) => callback(null, this.current_number)
|
|
|
|
this.CollaboratorsInviteHandler.getInviteCount = (
|
|
|
|
project_id,
|
|
|
|
callback
|
|
|
|
) => callback(null, this.invite_count)
|
|
|
|
sinon.stub(
|
|
|
|
this.LimitationsManager,
|
|
|
|
'allowedNumberOfCollaboratorsInProject',
|
|
|
|
(project_id, callback) => {
|
|
|
|
return callback(null, this.allowed_number)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
this.callback = sinon.stub()
|
|
|
|
return this.LimitationsManager.canAddXCollaborators(
|
|
|
|
this.project_id,
|
|
|
|
1,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should return true', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.callback.calledWith(null, true).should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
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
|
|
|
|
this.CollaboratorsHandler.getInvitedCollaboratorCount = (
|
|
|
|
project_id,
|
|
|
|
callback
|
|
|
|
) => callback(null, this.current_number)
|
|
|
|
this.CollaboratorsInviteHandler.getInviteCount = (
|
|
|
|
project_id,
|
|
|
|
callback
|
|
|
|
) => callback(null, this.invite_count)
|
|
|
|
sinon.stub(
|
|
|
|
this.LimitationsManager,
|
|
|
|
'allowedNumberOfCollaboratorsInProject',
|
|
|
|
(project_id, callback) => {
|
|
|
|
return callback(null, this.allowed_number)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
this.callback = sinon.stub()
|
|
|
|
return this.LimitationsManager.canAddXCollaborators(
|
|
|
|
this.project_id,
|
|
|
|
1,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should return true', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
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() {
|
|
|
|
this.current_number = 1
|
|
|
|
this.allowed_number = 2
|
|
|
|
this.invite_count = 0
|
|
|
|
this.CollaboratorsHandler.getInvitedCollaboratorCount = (
|
|
|
|
project_id,
|
|
|
|
callback
|
|
|
|
) => callback(null, this.current_number)
|
|
|
|
this.CollaboratorsInviteHandler.getInviteCount = (
|
|
|
|
project_id,
|
|
|
|
callback
|
|
|
|
) => callback(null, this.invite_count)
|
|
|
|
sinon.stub(
|
|
|
|
this.LimitationsManager,
|
|
|
|
'allowedNumberOfCollaboratorsInProject',
|
|
|
|
(project_id, callback) => {
|
|
|
|
return callback(null, this.allowed_number)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
this.callback = sinon.stub()
|
|
|
|
return this.LimitationsManager.canAddXCollaborators(
|
|
|
|
this.project_id,
|
|
|
|
2,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should return false', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.callback.calledWith(null, false).should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when the project has more collaborators than allowed', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.current_number = 3
|
|
|
|
this.allowed_number = 2
|
|
|
|
this.invite_count = 0
|
|
|
|
this.CollaboratorsHandler.getInvitedCollaboratorCount = (
|
|
|
|
project_id,
|
|
|
|
callback
|
|
|
|
) => callback(null, this.current_number)
|
|
|
|
this.CollaboratorsInviteHandler.getInviteCount = (
|
|
|
|
project_id,
|
|
|
|
callback
|
|
|
|
) => callback(null, this.invite_count)
|
|
|
|
sinon.stub(
|
|
|
|
this.LimitationsManager,
|
|
|
|
'allowedNumberOfCollaboratorsInProject',
|
|
|
|
(project_id, callback) => {
|
|
|
|
return callback(null, this.allowed_number)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
this.callback = sinon.stub()
|
|
|
|
return this.LimitationsManager.canAddXCollaborators(
|
|
|
|
this.project_id,
|
|
|
|
1,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should return false', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.callback.calledWith(null, false).should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when the project has infinite collaborators', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.current_number = 100
|
|
|
|
this.allowed_number = -1
|
|
|
|
this.invite_count = 0
|
|
|
|
this.CollaboratorsHandler.getInvitedCollaboratorCount = (
|
|
|
|
project_id,
|
|
|
|
callback
|
|
|
|
) => callback(null, this.current_number)
|
|
|
|
this.CollaboratorsInviteHandler.getInviteCount = (
|
|
|
|
project_id,
|
|
|
|
callback
|
|
|
|
) => callback(null, this.invite_count)
|
|
|
|
sinon.stub(
|
|
|
|
this.LimitationsManager,
|
|
|
|
'allowedNumberOfCollaboratorsInProject',
|
|
|
|
(project_id, callback) => {
|
|
|
|
return callback(null, this.allowed_number)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
this.callback = sinon.stub()
|
|
|
|
return this.LimitationsManager.canAddXCollaborators(
|
|
|
|
this.project_id,
|
|
|
|
1,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should return true', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.callback.calledWith(null, true).should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when the project has more invites than allowed', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.current_number = 0
|
|
|
|
this.allowed_number = 2
|
|
|
|
this.invite_count = 2
|
|
|
|
this.CollaboratorsHandler.getInvitedCollaboratorCount = (
|
|
|
|
project_id,
|
|
|
|
callback
|
|
|
|
) => callback(null, this.current_number)
|
|
|
|
this.CollaboratorsInviteHandler.getInviteCount = (
|
|
|
|
project_id,
|
|
|
|
callback
|
|
|
|
) => callback(null, this.invite_count)
|
|
|
|
sinon.stub(
|
|
|
|
this.LimitationsManager,
|
|
|
|
'allowedNumberOfCollaboratorsInProject',
|
|
|
|
(project_id, callback) => {
|
|
|
|
return callback(null, this.allowed_number)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
this.callback = sinon.stub()
|
|
|
|
return this.LimitationsManager.canAddXCollaborators(
|
|
|
|
this.project_id,
|
|
|
|
1,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should return false', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.callback.calledWith(null, false).should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
describe('when the project has more invites and collaborators than allowed', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
beforeEach(function() {
|
|
|
|
this.current_number = 1
|
|
|
|
this.allowed_number = 2
|
|
|
|
this.invite_count = 1
|
|
|
|
this.CollaboratorsHandler.getInvitedCollaboratorCount = (
|
|
|
|
project_id,
|
|
|
|
callback
|
|
|
|
) => callback(null, this.current_number)
|
|
|
|
this.CollaboratorsInviteHandler.getInviteCount = (
|
|
|
|
project_id,
|
|
|
|
callback
|
|
|
|
) => callback(null, this.invite_count)
|
|
|
|
sinon.stub(
|
|
|
|
this.LimitationsManager,
|
|
|
|
'allowedNumberOfCollaboratorsInProject',
|
|
|
|
(project_id, callback) => {
|
|
|
|
return callback(null, this.allowed_number)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
this.callback = sinon.stub()
|
|
|
|
return this.LimitationsManager.canAddXCollaborators(
|
|
|
|
this.project_id,
|
|
|
|
1,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should return false', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.callback.calledWith(null, false).should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('userHasV2Subscription', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
return (this.SubscriptionLocator.getUsersSubscription = sinon.stub())
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return true if the recurly token is set', function(done) {
|
|
|
|
this.SubscriptionLocator.getUsersSubscription.callsArgWith(1, null, {
|
|
|
|
recurlySubscription_id: '1234'
|
|
|
|
})
|
2019-08-07 10:04:04 -04:00
|
|
|
return this.LimitationsManager.userHasV2Subscription(
|
|
|
|
this.user,
|
|
|
|
(err, hasSubscription) => {
|
|
|
|
hasSubscription.should.equal(true)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should return false if the recurly token is not set', function(done) {
|
|
|
|
this.SubscriptionLocator.getUsersSubscription.callsArgWith(1, null, {})
|
|
|
|
this.subscription = {}
|
2019-08-07 10:04:04 -04:00
|
|
|
return this.LimitationsManager.userHasV2Subscription(
|
|
|
|
this.user,
|
|
|
|
(err, hasSubscription) => {
|
|
|
|
hasSubscription.should.equal(false)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should return false if the subscription is undefined', function(done) {
|
|
|
|
this.SubscriptionLocator.getUsersSubscription.callsArgWith(1)
|
2019-08-07 10:04:04 -04:00
|
|
|
return this.LimitationsManager.userHasV2Subscription(
|
|
|
|
this.user,
|
|
|
|
(err, hasSubscription) => {
|
|
|
|
hasSubscription.should.equal(false)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should return the subscription', function(done) {
|
|
|
|
const stubbedSubscription = { freeTrial: {}, token: '' }
|
|
|
|
this.SubscriptionLocator.getUsersSubscription.callsArgWith(
|
|
|
|
1,
|
|
|
|
null,
|
|
|
|
stubbedSubscription
|
|
|
|
)
|
2019-08-07 10:04:04 -04:00
|
|
|
return this.LimitationsManager.userHasV2Subscription(
|
|
|
|
this.user,
|
|
|
|
(err, hasSubOrIsGroupMember, subscription) => {
|
|
|
|
subscription.should.deep.equal(stubbedSubscription)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
describe('when user has a custom account', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
beforeEach(function() {
|
|
|
|
this.fakeSubscription = { customAccount: true }
|
|
|
|
return this.SubscriptionLocator.getUsersSubscription.callsArgWith(
|
|
|
|
1,
|
|
|
|
null,
|
|
|
|
this.fakeSubscription
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return true', function(done) {
|
|
|
|
return this.LimitationsManager.userHasV2Subscription(
|
|
|
|
this.user,
|
2019-08-07 10:04:04 -04:00
|
|
|
(err, hasSubscription, subscription) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
hasSubscription.should.equal(true)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should return the subscription', function(done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.LimitationsManager.userHasV2Subscription(
|
|
|
|
this.user,
|
|
|
|
(err, hasSubscription, subscription) => {
|
|
|
|
subscription.should.deep.equal(this.fakeSubscription)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('userIsMemberOfGroupSubscription', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
return (this.SubscriptionLocator.getMemberSubscriptions = sinon.stub())
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return false if there are no groups subcriptions', function(done) {
|
|
|
|
this.SubscriptionLocator.getMemberSubscriptions.callsArgWith(1, null, [])
|
|
|
|
return this.LimitationsManager.userIsMemberOfGroupSubscription(
|
|
|
|
this.user,
|
2019-08-07 10:04:04 -04:00
|
|
|
(err, isMember) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
isMember.should.equal(false)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should return true if there are no groups subcriptions', function(done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
let subscriptions
|
|
|
|
this.SubscriptionLocator.getMemberSubscriptions.callsArgWith(
|
|
|
|
1,
|
|
|
|
null,
|
|
|
|
(subscriptions = ['mock-subscription'])
|
|
|
|
)
|
|
|
|
return this.LimitationsManager.userIsMemberOfGroupSubscription(
|
|
|
|
this.user,
|
2019-08-07 10:04:04 -04:00
|
|
|
(err, isMember, retSubscriptions) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
isMember.should.equal(true)
|
|
|
|
retSubscriptions.should.equal(subscriptions)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('hasPaidSubscription', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.LimitationsManager.userIsMemberOfGroupSubscription = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, false)
|
|
|
|
this.LimitationsManager.userHasV2Subscription = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, false)
|
|
|
|
return (this.LimitationsManager.userHasV1Subscription = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, false))
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return true if userIsMemberOfGroupSubscription', function(done) {
|
|
|
|
this.LimitationsManager.userIsMemberOfGroupSubscription = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, true)
|
2019-08-07 10:04:04 -04:00
|
|
|
return this.LimitationsManager.hasPaidSubscription(
|
|
|
|
this.user,
|
|
|
|
(err, hasSubOrIsGroupMember) => {
|
|
|
|
hasSubOrIsGroupMember.should.equal(true)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should return true if userHasV2Subscription', function(done) {
|
|
|
|
this.LimitationsManager.userHasV2Subscription = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, true)
|
2019-08-07 10:04:04 -04:00
|
|
|
return this.LimitationsManager.hasPaidSubscription(
|
|
|
|
this.user,
|
|
|
|
(err, hasSubOrIsGroupMember) => {
|
|
|
|
hasSubOrIsGroupMember.should.equal(true)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should return true if userHasV1Subscription', function(done) {
|
|
|
|
this.LimitationsManager.userHasV1Subscription = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, true)
|
2019-08-07 10:04:04 -04:00
|
|
|
return this.LimitationsManager.hasPaidSubscription(
|
|
|
|
this.user,
|
|
|
|
(err, hasSubOrIsGroupMember) => {
|
|
|
|
hasSubOrIsGroupMember.should.equal(true)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should return false if none are true', function(done) {
|
2019-08-07 10:04:04 -04:00
|
|
|
return this.LimitationsManager.hasPaidSubscription(
|
|
|
|
this.user,
|
|
|
|
(err, hasSubOrIsGroupMember) => {
|
|
|
|
hasSubOrIsGroupMember.should.equal(false)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should have userHasSubscriptionOrIsGroupMember alias', function(done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.LimitationsManager.userHasSubscriptionOrIsGroupMember(
|
|
|
|
this.user,
|
2019-08-07 10:04:04 -04:00
|
|
|
(err, hasSubOrIsGroupMember) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
hasSubOrIsGroupMember.should.equal(false)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('userHasV1OrV2Subscription', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.LimitationsManager.userHasV2Subscription = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, false)
|
|
|
|
return (this.LimitationsManager.userHasV1Subscription = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, false))
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return true if userHasV2Subscription', function(done) {
|
|
|
|
this.LimitationsManager.userHasV2Subscription = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, true)
|
|
|
|
return this.LimitationsManager.userHasV1OrV2Subscription(
|
|
|
|
this.user,
|
2019-08-07 10:04:04 -04:00
|
|
|
(err, hasSub) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
hasSub.should.equal(true)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return true if userHasV1Subscription', function(done) {
|
|
|
|
this.LimitationsManager.userHasV1Subscription = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, true)
|
|
|
|
return this.LimitationsManager.userHasV1OrV2Subscription(
|
|
|
|
this.user,
|
2019-08-07 10:04:04 -04:00
|
|
|
(err, hasSub) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
hasSub.should.equal(true)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should return false if none are true', function(done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.LimitationsManager.userHasV1OrV2Subscription(
|
|
|
|
this.user,
|
2019-08-07 10:04:04 -04:00
|
|
|
(err, hasSub) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
hasSub.should.equal(false)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('hasGroupMembersLimitReached', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.subscriptionId = '12312'
|
|
|
|
return (this.subscription = {
|
|
|
|
membersLimit: 3,
|
|
|
|
member_ids: ['', ''],
|
|
|
|
teamInvites: [
|
|
|
|
{ email: 'bob@example.com', sentAt: new Date(), token: 'hey' }
|
|
|
|
]
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return true if the limit is hit (including members and invites)', function(done) {
|
|
|
|
this.SubscriptionLocator.getSubscription.callsArgWith(
|
|
|
|
1,
|
|
|
|
null,
|
|
|
|
this.subscription
|
|
|
|
)
|
|
|
|
return this.LimitationsManager.hasGroupMembersLimitReached(
|
|
|
|
this.subscriptionId,
|
2019-08-07 10:04:04 -04:00
|
|
|
(err, limitReached) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
limitReached.should.equal(true)
|
|
|
|
return 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,
|
|
|
|
null,
|
|
|
|
this.subscription
|
|
|
|
)
|
|
|
|
return this.LimitationsManager.hasGroupMembersLimitReached(
|
|
|
|
this.subscriptionId,
|
2019-08-07 10:04:04 -04:00
|
|
|
(err, limitReached) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
limitReached.should.equal(false)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should return true if the limit has been exceded (including members and invites)', function(done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.subscription.membersLimit = 2
|
|
|
|
this.SubscriptionLocator.getSubscription.callsArgWith(
|
|
|
|
1,
|
|
|
|
null,
|
|
|
|
this.subscription
|
|
|
|
)
|
|
|
|
return this.LimitationsManager.hasGroupMembersLimitReached(
|
|
|
|
this.subscriptionId,
|
2019-08-07 10:04:04 -04:00
|
|
|
(err, limitReached) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
limitReached.should.equal(true)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
describe('userHasV1Subscription', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
it('should return true if v1 returns has_subscription = true', function(done) {
|
|
|
|
this.V1SubscriptionManager.getSubscriptionsFromV1 = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, { has_subscription: true })
|
|
|
|
return this.LimitationsManager.userHasV1Subscription(
|
|
|
|
this.user,
|
|
|
|
(error, result) => {
|
|
|
|
this.V1SubscriptionManager.getSubscriptionsFromV1
|
|
|
|
.calledWith(this.user_id)
|
|
|
|
.should.equal(true)
|
|
|
|
result.should.equal(true)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return false if v1 returns has_subscription = false', function(done) {
|
|
|
|
this.V1SubscriptionManager.getSubscriptionsFromV1 = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, { has_subscription: false })
|
|
|
|
return this.LimitationsManager.userHasV1Subscription(
|
|
|
|
this.user,
|
|
|
|
(error, result) => {
|
|
|
|
this.V1SubscriptionManager.getSubscriptionsFromV1
|
|
|
|
.calledWith(this.user_id)
|
|
|
|
.should.equal(true)
|
|
|
|
result.should.equal(false)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should return false if v1 returns nothing', function(done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.V1SubscriptionManager.getSubscriptionsFromV1 = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, null)
|
|
|
|
return this.LimitationsManager.userHasV1Subscription(
|
|
|
|
this.user,
|
|
|
|
(error, result) => {
|
|
|
|
this.V1SubscriptionManager.getSubscriptionsFromV1
|
|
|
|
.calledWith(this.user_id)
|
|
|
|
.should.equal(true)
|
|
|
|
result.should.equal(false)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|