2019-05-29 05:21:06 -04:00
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
const sinon = require('sinon')
|
|
|
|
const modulePath = require('path').join(
|
|
|
|
__dirname,
|
|
|
|
'../../../../app/src/Features/Subscription/LimitationsManager'
|
|
|
|
)
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('LimitationsManager', function () {
|
|
|
|
beforeEach(function () {
|
2021-05-05 09:40:27 -04:00
|
|
|
this.project = { _id: (this.projectId = 'project-id') }
|
|
|
|
this.user = { _id: (this.userId = 'user-id'), features: {} }
|
2019-05-29 05:21:06 -04:00
|
|
|
this.ProjectGetter = {
|
2021-05-05 09:40:27 -04:00
|
|
|
getProject: (projectId, fields, callback) => {
|
|
|
|
if (projectId === this.projectId) {
|
|
|
|
callback(null, this.project)
|
2019-05-29 05:21:06 -04:00
|
|
|
} else {
|
2021-05-05 09:40:27 -04:00
|
|
|
callback(null, null)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
this.UserGetter = {
|
2021-05-05 09:40:27 -04:00
|
|
|
getUser: (userId, filter, callback) => {
|
|
|
|
if (userId === this.userId) {
|
|
|
|
callback(null, this.user)
|
2019-05-29 05:21:06 -04:00
|
|
|
} else {
|
2021-05-05 09:40:27 -04:00
|
|
|
callback(null, null)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
this.SubscriptionLocator = {
|
|
|
|
getUsersSubscription: sinon.stub(),
|
2021-04-27 03:52:58 -04:00
|
|
|
getSubscription: sinon.stub(),
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager = SandboxedModule.require(modulePath, {
|
2019-05-29 05:21:06 -04:00
|
|
|
requires: {
|
|
|
|
'../Project/ProjectGetter': this.ProjectGetter,
|
|
|
|
'../User/UserGetter': this.UserGetter,
|
|
|
|
'./SubscriptionLocator': this.SubscriptionLocator,
|
|
|
|
'settings-sharelatex': (this.Settings = {}),
|
2019-10-07 04:30:51 -04:00
|
|
|
'../Collaborators/CollaboratorsGetter': (this.CollaboratorsGetter = {}),
|
2019-05-29 05:21:06 -04:00
|
|
|
'../Collaborators/CollaboratorsInviteHandler': (this.CollaboratorsInviteHandler = {}),
|
2021-04-27 03:52:58 -04:00
|
|
|
'./V1SubscriptionManager': (this.V1SubscriptionManager = {}),
|
|
|
|
},
|
2021-05-05 09:40:27 -04:00
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('allowedNumberOfCollaboratorsInProject', function () {
|
|
|
|
describe('when the project is owned by a user without a subscription', function () {
|
|
|
|
beforeEach(function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.Settings.defaultFeatures = { collaborators: 23 }
|
2021-05-05 09:40:27 -04:00
|
|
|
this.project.owner_ref = this.userId
|
2019-05-29 05:21:06 -04:00
|
|
|
delete this.user.features
|
|
|
|
this.callback = sinon.stub()
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.allowedNumberOfCollaboratorsInProject(
|
|
|
|
this.projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return the default number', function () {
|
2021-05-05 09:40:27 -04:00
|
|
|
this.callback
|
2019-05-29 05:21:06 -04:00
|
|
|
.calledWith(null, this.Settings.defaultFeatures.collaborators)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when the project is owned by a user with a subscription', function () {
|
|
|
|
beforeEach(function () {
|
2021-05-05 09:40:27 -04:00
|
|
|
this.project.owner_ref = this.userId
|
2019-05-29 05:21:06 -04:00
|
|
|
this.user.features = { collaborators: 21 }
|
|
|
|
this.callback = sinon.stub()
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.allowedNumberOfCollaboratorsInProject(
|
|
|
|
this.projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return the number of collaborators the user is allowed', function () {
|
2021-05-05 09:40:27 -04:00
|
|
|
this.callback
|
2019-05-29 05:21:06 -04:00
|
|
|
.calledWith(null, this.user.features.collaborators)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('allowedNumberOfCollaboratorsForUser', function () {
|
|
|
|
describe('when the user has no features', function () {
|
|
|
|
beforeEach(function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.Settings.defaultFeatures = { collaborators: 23 }
|
|
|
|
delete this.user.features
|
|
|
|
this.callback = sinon.stub()
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.allowedNumberOfCollaboratorsForUser(
|
|
|
|
this.userId,
|
2019-05-29 05:21:06 -04:00
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return the default number', function () {
|
2021-05-05 09:40:27 -04:00
|
|
|
this.callback
|
2019-05-29 05:21:06 -04:00
|
|
|
.calledWith(null, this.Settings.defaultFeatures.collaborators)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when the user has features', function () {
|
|
|
|
beforeEach(function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.user.features = { collaborators: 21 }
|
|
|
|
this.callback = sinon.stub()
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.allowedNumberOfCollaboratorsForUser(
|
|
|
|
this.userId,
|
2019-05-29 05:21:06 -04:00
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return the number of collaborators the user is allowed', function () {
|
2021-05-05 09:40:27 -04:00
|
|
|
this.callback
|
2019-05-29 05:21:06 -04:00
|
|
|
.calledWith(null, this.user.features.collaborators)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('canAddXCollaborators', function () {
|
|
|
|
describe('when the project has fewer collaborators than allowed', function () {
|
|
|
|
beforeEach(function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.current_number = 1
|
|
|
|
this.allowed_number = 2
|
|
|
|
this.invite_count = 0
|
2019-10-07 04:30:51 -04:00
|
|
|
this.CollaboratorsGetter.getInvitedCollaboratorCount = (
|
2021-05-05 09:40:27 -04:00
|
|
|
projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
callback
|
|
|
|
) => callback(null, this.current_number)
|
|
|
|
this.CollaboratorsInviteHandler.getInviteCount = (
|
2021-05-05 09:40:27 -04:00
|
|
|
projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
callback
|
|
|
|
) => callback(null, this.invite_count)
|
2019-11-18 09:37:05 -05:00
|
|
|
sinon
|
|
|
|
.stub(
|
|
|
|
this.LimitationsManager,
|
|
|
|
'allowedNumberOfCollaboratorsInProject'
|
|
|
|
)
|
2021-05-05 09:40:27 -04:00
|
|
|
.callsFake((projectId, callback) => {
|
|
|
|
callback(null, this.allowed_number)
|
2019-11-18 09:37:05 -05:00
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
this.callback = sinon.stub()
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.canAddXCollaborators(
|
|
|
|
this.projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
1,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return true', function () {
|
2021-05-05 09:40:27 -04:00
|
|
|
this.callback.calledWith(null, true).should.equal(true)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when the project has fewer collaborators and invites than allowed', function () {
|
|
|
|
beforeEach(function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.current_number = 1
|
|
|
|
this.allowed_number = 4
|
|
|
|
this.invite_count = 1
|
2019-10-07 04:30:51 -04:00
|
|
|
this.CollaboratorsGetter.getInvitedCollaboratorCount = (
|
2021-05-05 09:40:27 -04:00
|
|
|
projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
callback
|
|
|
|
) => callback(null, this.current_number)
|
|
|
|
this.CollaboratorsInviteHandler.getInviteCount = (
|
2021-05-05 09:40:27 -04:00
|
|
|
projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
callback
|
|
|
|
) => callback(null, this.invite_count)
|
2019-11-18 09:37:05 -05:00
|
|
|
sinon
|
|
|
|
.stub(
|
|
|
|
this.LimitationsManager,
|
|
|
|
'allowedNumberOfCollaboratorsInProject'
|
|
|
|
)
|
2021-05-05 09:40:27 -04:00
|
|
|
.callsFake((projectId, callback) => {
|
|
|
|
callback(null, this.allowed_number)
|
2019-11-18 09:37:05 -05:00
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
this.callback = sinon.stub()
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.canAddXCollaborators(
|
|
|
|
this.projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
1,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return true', function () {
|
2021-05-05 09:40:27 -04:00
|
|
|
this.callback.calledWith(null, true).should.equal(true)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when the project has fewer collaborators than allowed but I want to add more than allowed', function () {
|
|
|
|
beforeEach(function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.current_number = 1
|
|
|
|
this.allowed_number = 2
|
|
|
|
this.invite_count = 0
|
2019-10-07 04:30:51 -04:00
|
|
|
this.CollaboratorsGetter.getInvitedCollaboratorCount = (
|
2021-05-05 09:40:27 -04:00
|
|
|
projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
callback
|
|
|
|
) => callback(null, this.current_number)
|
|
|
|
this.CollaboratorsInviteHandler.getInviteCount = (
|
2021-05-05 09:40:27 -04:00
|
|
|
projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
callback
|
|
|
|
) => callback(null, this.invite_count)
|
2019-11-18 09:37:05 -05:00
|
|
|
sinon
|
|
|
|
.stub(
|
|
|
|
this.LimitationsManager,
|
|
|
|
'allowedNumberOfCollaboratorsInProject'
|
|
|
|
)
|
2021-05-05 09:40:27 -04:00
|
|
|
.callsFake((projectId, callback) => {
|
|
|
|
callback(null, this.allowed_number)
|
2019-11-18 09:37:05 -05:00
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
this.callback = sinon.stub()
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.canAddXCollaborators(
|
|
|
|
this.projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
2,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return false', function () {
|
2021-05-05 09:40:27 -04:00
|
|
|
this.callback.calledWith(null, false).should.equal(true)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when the project has more collaborators than allowed', function () {
|
|
|
|
beforeEach(function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.current_number = 3
|
|
|
|
this.allowed_number = 2
|
|
|
|
this.invite_count = 0
|
2019-10-07 04:30:51 -04:00
|
|
|
this.CollaboratorsGetter.getInvitedCollaboratorCount = (
|
2021-05-05 09:40:27 -04:00
|
|
|
projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
callback
|
|
|
|
) => callback(null, this.current_number)
|
|
|
|
this.CollaboratorsInviteHandler.getInviteCount = (
|
2021-05-05 09:40:27 -04:00
|
|
|
projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
callback
|
|
|
|
) => callback(null, this.invite_count)
|
2019-11-18 09:37:05 -05:00
|
|
|
sinon
|
|
|
|
.stub(
|
|
|
|
this.LimitationsManager,
|
|
|
|
'allowedNumberOfCollaboratorsInProject'
|
|
|
|
)
|
2021-05-05 09:40:27 -04:00
|
|
|
.callsFake((projectId, callback) => {
|
|
|
|
callback(null, this.allowed_number)
|
2019-11-18 09:37:05 -05:00
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
this.callback = sinon.stub()
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.canAddXCollaborators(
|
|
|
|
this.projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
1,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return false', function () {
|
2021-05-05 09:40:27 -04:00
|
|
|
this.callback.calledWith(null, false).should.equal(true)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when the project has infinite collaborators', function () {
|
|
|
|
beforeEach(function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.current_number = 100
|
|
|
|
this.allowed_number = -1
|
|
|
|
this.invite_count = 0
|
2019-10-07 04:30:51 -04:00
|
|
|
this.CollaboratorsGetter.getInvitedCollaboratorCount = (
|
2021-05-05 09:40:27 -04:00
|
|
|
projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
callback
|
|
|
|
) => callback(null, this.current_number)
|
|
|
|
this.CollaboratorsInviteHandler.getInviteCount = (
|
2021-05-05 09:40:27 -04:00
|
|
|
projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
callback
|
|
|
|
) => callback(null, this.invite_count)
|
2019-11-18 09:37:05 -05:00
|
|
|
sinon
|
|
|
|
.stub(
|
|
|
|
this.LimitationsManager,
|
|
|
|
'allowedNumberOfCollaboratorsInProject'
|
|
|
|
)
|
2021-05-05 09:40:27 -04:00
|
|
|
.callsFake((projectId, callback) => {
|
|
|
|
callback(null, this.allowed_number)
|
2019-11-18 09:37:05 -05:00
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
this.callback = sinon.stub()
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.canAddXCollaborators(
|
|
|
|
this.projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
1,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return true', function () {
|
2021-05-05 09:40:27 -04:00
|
|
|
this.callback.calledWith(null, true).should.equal(true)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when the project has more invites than allowed', function () {
|
|
|
|
beforeEach(function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.current_number = 0
|
|
|
|
this.allowed_number = 2
|
|
|
|
this.invite_count = 2
|
2019-10-07 04:30:51 -04:00
|
|
|
this.CollaboratorsGetter.getInvitedCollaboratorCount = (
|
2021-05-05 09:40:27 -04:00
|
|
|
projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
callback
|
|
|
|
) => callback(null, this.current_number)
|
|
|
|
this.CollaboratorsInviteHandler.getInviteCount = (
|
2021-05-05 09:40:27 -04:00
|
|
|
projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
callback
|
|
|
|
) => callback(null, this.invite_count)
|
2019-11-18 09:37:05 -05:00
|
|
|
sinon
|
|
|
|
.stub(
|
|
|
|
this.LimitationsManager,
|
|
|
|
'allowedNumberOfCollaboratorsInProject'
|
|
|
|
)
|
2021-05-05 09:40:27 -04:00
|
|
|
.callsFake((projectId, callback) => {
|
|
|
|
callback(null, this.allowed_number)
|
2019-11-18 09:37:05 -05:00
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
this.callback = sinon.stub()
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.canAddXCollaborators(
|
|
|
|
this.projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
1,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return false', function () {
|
2021-05-05 09:40:27 -04:00
|
|
|
this.callback.calledWith(null, false).should.equal(true)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when the project has more invites and collaborators than allowed', function () {
|
|
|
|
beforeEach(function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.current_number = 1
|
|
|
|
this.allowed_number = 2
|
|
|
|
this.invite_count = 1
|
2019-10-07 04:30:51 -04:00
|
|
|
this.CollaboratorsGetter.getInvitedCollaboratorCount = (
|
2021-05-05 09:40:27 -04:00
|
|
|
projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
callback
|
|
|
|
) => callback(null, this.current_number)
|
|
|
|
this.CollaboratorsInviteHandler.getInviteCount = (
|
2021-05-05 09:40:27 -04:00
|
|
|
projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
callback
|
|
|
|
) => callback(null, this.invite_count)
|
2019-11-18 09:37:05 -05:00
|
|
|
sinon
|
|
|
|
.stub(
|
|
|
|
this.LimitationsManager,
|
|
|
|
'allowedNumberOfCollaboratorsInProject'
|
|
|
|
)
|
2021-05-05 09:40:27 -04:00
|
|
|
.callsFake((projectId, callback) => {
|
|
|
|
callback(null, this.allowed_number)
|
2019-11-18 09:37:05 -05:00
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
this.callback = sinon.stub()
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.canAddXCollaborators(
|
|
|
|
this.projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
1,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return false', function () {
|
2021-05-05 09:40:27 -04:00
|
|
|
this.callback.calledWith(null, false).should.equal(true)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('userHasV2Subscription', function () {
|
|
|
|
beforeEach(function () {
|
2021-05-05 09:40:27 -04:00
|
|
|
this.SubscriptionLocator.getUsersSubscription = sinon.stub()
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return true if the recurly token is set', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.SubscriptionLocator.getUsersSubscription.callsArgWith(1, null, {
|
2021-04-27 03:52:58 -04:00
|
|
|
recurlySubscription_id: '1234',
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.userHasV2Subscription(
|
2019-08-07 10:04:04 -04:00
|
|
|
this.user,
|
|
|
|
(err, hasSubscription) => {
|
|
|
|
hasSubscription.should.equal(true)
|
2021-05-05 09:40:27 -04:00
|
|
|
done()
|
2019-08-07 10:04:04 -04:00
|
|
|
}
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return false if the recurly token is not set', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.SubscriptionLocator.getUsersSubscription.callsArgWith(1, null, {})
|
|
|
|
this.subscription = {}
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.userHasV2Subscription(
|
2019-08-07 10:04:04 -04:00
|
|
|
this.user,
|
|
|
|
(err, hasSubscription) => {
|
|
|
|
hasSubscription.should.equal(false)
|
2021-05-05 09:40:27 -04:00
|
|
|
done()
|
2019-08-07 10:04:04 -04:00
|
|
|
}
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return false if the subscription is undefined', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.SubscriptionLocator.getUsersSubscription.callsArgWith(1)
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.userHasV2Subscription(
|
2019-08-07 10:04:04 -04:00
|
|
|
this.user,
|
|
|
|
(err, hasSubscription) => {
|
|
|
|
hasSubscription.should.equal(false)
|
2021-05-05 09:40:27 -04:00
|
|
|
done()
|
2019-08-07 10:04:04 -04:00
|
|
|
}
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return the subscription', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
const stubbedSubscription = { freeTrial: {}, token: '' }
|
|
|
|
this.SubscriptionLocator.getUsersSubscription.callsArgWith(
|
|
|
|
1,
|
|
|
|
null,
|
|
|
|
stubbedSubscription
|
|
|
|
)
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.userHasV2Subscription(
|
2019-08-07 10:04:04 -04:00
|
|
|
this.user,
|
|
|
|
(err, hasSubOrIsGroupMember, subscription) => {
|
|
|
|
subscription.should.deep.equal(stubbedSubscription)
|
2021-05-05 09:40:27 -04:00
|
|
|
done()
|
2019-08-07 10:04:04 -04:00
|
|
|
}
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when user has a custom account', function () {
|
|
|
|
beforeEach(function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.fakeSubscription = { customAccount: true }
|
2021-05-05 09:40:27 -04:00
|
|
|
this.SubscriptionLocator.getUsersSubscription.callsArgWith(
|
2019-05-29 05:21:06 -04:00
|
|
|
1,
|
|
|
|
null,
|
|
|
|
this.fakeSubscription
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return true', function (done) {
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.userHasV2Subscription(
|
2019-05-29 05:21:06 -04:00
|
|
|
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)
|
2021-05-05 09:40:27 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return the subscription', function (done) {
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.userHasV2Subscription(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.user,
|
|
|
|
(err, hasSubscription, subscription) => {
|
|
|
|
subscription.should.deep.equal(this.fakeSubscription)
|
2021-05-05 09:40:27 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('userIsMemberOfGroupSubscription', function () {
|
|
|
|
beforeEach(function () {
|
2021-05-05 09:40:27 -04:00
|
|
|
this.SubscriptionLocator.getMemberSubscriptions = sinon.stub()
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return false if there are no groups subcriptions', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.SubscriptionLocator.getMemberSubscriptions.callsArgWith(1, null, [])
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.userIsMemberOfGroupSubscription(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.user,
|
2019-08-07 10:04:04 -04:00
|
|
|
(err, isMember) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
isMember.should.equal(false)
|
2021-05-05 09:40:27 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -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'])
|
|
|
|
)
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.userIsMemberOfGroupSubscription(
|
2019-05-29 05:21:06 -04:00
|
|
|
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)
|
2021-05-05 09:40:27 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('hasPaidSubscription', function () {
|
|
|
|
beforeEach(function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.LimitationsManager.userIsMemberOfGroupSubscription = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, false)
|
|
|
|
this.LimitationsManager.userHasV2Subscription = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, false)
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.userHasV1Subscription = sinon
|
2019-05-29 05:21:06 -04:00
|
|
|
.stub()
|
2021-05-05 09:40:27 -04:00
|
|
|
.yields(null, false)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return true if userIsMemberOfGroupSubscription', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.LimitationsManager.userIsMemberOfGroupSubscription = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, true)
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.hasPaidSubscription(
|
2019-08-07 10:04:04 -04:00
|
|
|
this.user,
|
|
|
|
(err, hasSubOrIsGroupMember) => {
|
|
|
|
hasSubOrIsGroupMember.should.equal(true)
|
2021-05-05 09:40:27 -04:00
|
|
|
done()
|
2019-08-07 10:04:04 -04:00
|
|
|
}
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return true if userHasV2Subscription', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.LimitationsManager.userHasV2Subscription = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, true)
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.hasPaidSubscription(
|
2019-08-07 10:04:04 -04:00
|
|
|
this.user,
|
|
|
|
(err, hasSubOrIsGroupMember) => {
|
|
|
|
hasSubOrIsGroupMember.should.equal(true)
|
2021-05-05 09:40:27 -04:00
|
|
|
done()
|
2019-08-07 10:04:04 -04:00
|
|
|
}
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return true if userHasV1Subscription', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.LimitationsManager.userHasV1Subscription = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, true)
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.hasPaidSubscription(
|
2019-08-07 10:04:04 -04:00
|
|
|
this.user,
|
|
|
|
(err, hasSubOrIsGroupMember) => {
|
|
|
|
hasSubOrIsGroupMember.should.equal(true)
|
2021-05-05 09:40:27 -04:00
|
|
|
done()
|
2019-08-07 10:04:04 -04:00
|
|
|
}
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return false if none are true', function (done) {
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.hasPaidSubscription(
|
2019-08-07 10:04:04 -04:00
|
|
|
this.user,
|
|
|
|
(err, hasSubOrIsGroupMember) => {
|
|
|
|
hasSubOrIsGroupMember.should.equal(false)
|
2021-05-05 09:40:27 -04:00
|
|
|
done()
|
2019-08-07 10:04:04 -04:00
|
|
|
}
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should have userHasSubscriptionOrIsGroupMember alias', function (done) {
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.userHasSubscriptionOrIsGroupMember(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.user,
|
2019-08-07 10:04:04 -04:00
|
|
|
(err, hasSubOrIsGroupMember) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
hasSubOrIsGroupMember.should.equal(false)
|
2021-05-05 09:40:27 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('userHasV1OrV2Subscription', function () {
|
|
|
|
beforeEach(function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.LimitationsManager.userHasV2Subscription = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, false)
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.userHasV1Subscription = sinon
|
2019-05-29 05:21:06 -04:00
|
|
|
.stub()
|
2021-05-05 09:40:27 -04:00
|
|
|
.yields(null, false)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return true if userHasV2Subscription', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.LimitationsManager.userHasV2Subscription = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, true)
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.userHasV1OrV2Subscription(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.user,
|
2019-08-07 10:04:04 -04:00
|
|
|
(err, hasSub) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
hasSub.should.equal(true)
|
2021-05-05 09:40:27 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return true if userHasV1Subscription', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.LimitationsManager.userHasV1Subscription = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, true)
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.userHasV1OrV2Subscription(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.user,
|
2019-08-07 10:04:04 -04:00
|
|
|
(err, hasSub) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
hasSub.should.equal(true)
|
2021-05-05 09:40:27 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return false if none are true', function (done) {
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.userHasV1OrV2Subscription(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.user,
|
2019-08-07 10:04:04 -04:00
|
|
|
(err, hasSub) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
hasSub.should.equal(false)
|
2021-05-05 09:40:27 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('hasGroupMembersLimitReached', function () {
|
|
|
|
beforeEach(function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.subscriptionId = '12312'
|
2021-05-05 09:40:27 -04:00
|
|
|
this.subscription = {
|
2019-05-29 05:21:06 -04:00
|
|
|
membersLimit: 3,
|
|
|
|
member_ids: ['', ''],
|
|
|
|
teamInvites: [
|
2021-04-27 03:52:58 -04:00
|
|
|
{ email: 'bob@example.com', sentAt: new Date(), token: 'hey' },
|
|
|
|
],
|
2021-05-05 09:40:27 -04:00
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return true if the limit is hit (including members and invites)', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.SubscriptionLocator.getSubscription.callsArgWith(
|
|
|
|
1,
|
|
|
|
null,
|
|
|
|
this.subscription
|
|
|
|
)
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.hasGroupMembersLimitReached(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.subscriptionId,
|
2019-08-07 10:04:04 -04:00
|
|
|
(err, limitReached) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
limitReached.should.equal(true)
|
2021-05-05 09:40:27 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return false if the limit is not hit (including members and invites)', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.subscription.membersLimit = 4
|
|
|
|
this.SubscriptionLocator.getSubscription.callsArgWith(
|
|
|
|
1,
|
|
|
|
null,
|
|
|
|
this.subscription
|
|
|
|
)
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.hasGroupMembersLimitReached(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.subscriptionId,
|
2019-08-07 10:04:04 -04:00
|
|
|
(err, limitReached) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
limitReached.should.equal(false)
|
2021-05-05 09:40:27 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -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
|
|
|
|
)
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.hasGroupMembersLimitReached(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.subscriptionId,
|
2019-08-07 10:04:04 -04:00
|
|
|
(err, limitReached) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
limitReached.should.equal(true)
|
2021-05-05 09:40:27 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('userHasV1Subscription', function () {
|
|
|
|
it('should return true if v1 returns has_subscription = true', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.V1SubscriptionManager.getSubscriptionsFromV1 = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, { has_subscription: true })
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.userHasV1Subscription(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.user,
|
|
|
|
(error, result) => {
|
|
|
|
this.V1SubscriptionManager.getSubscriptionsFromV1
|
2021-05-05 09:40:27 -04:00
|
|
|
.calledWith(this.userId)
|
2019-05-29 05:21:06 -04:00
|
|
|
.should.equal(true)
|
|
|
|
result.should.equal(true)
|
2021-05-05 09:40:27 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return false if v1 returns has_subscription = false', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.V1SubscriptionManager.getSubscriptionsFromV1 = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, { has_subscription: false })
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.userHasV1Subscription(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.user,
|
|
|
|
(error, result) => {
|
|
|
|
this.V1SubscriptionManager.getSubscriptionsFromV1
|
2021-05-05 09:40:27 -04:00
|
|
|
.calledWith(this.userId)
|
2019-05-29 05:21:06 -04:00
|
|
|
.should.equal(true)
|
|
|
|
result.should.equal(false)
|
2021-05-05 09:40:27 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -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)
|
2021-05-05 09:40:27 -04:00
|
|
|
this.LimitationsManager.userHasV1Subscription(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.user,
|
|
|
|
(error, result) => {
|
|
|
|
this.V1SubscriptionManager.getSubscriptionsFromV1
|
2021-05-05 09:40:27 -04:00
|
|
|
.calledWith(this.userId)
|
2019-05-29 05:21:06 -04:00
|
|
|
.should.equal(true)
|
|
|
|
result.should.equal(false)
|
2021-05-05 09:40:27 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|