|
@@ -8,30 +8,57 @@ const modulePath = require('path').join(
|
|
|
|
|
|
|
|
describe('LimitationsManager', function () {
|
|
describe('LimitationsManager', function () {
|
|
|
beforeEach(function () {
|
|
beforeEach(function () {
|
|
|
- this.project = { _id: (this.projectId = 'project-id') }
|
|
|
|
|
- this.user = { _id: (this.userId = 'user-id'), features: {} }
|
|
|
|
|
|
|
+ this.user = {
|
|
|
|
|
+ _id: (this.userId = 'user-id'),
|
|
|
|
|
+ features: { collaborators: 1 },
|
|
|
|
|
+ }
|
|
|
|
|
+ this.project = {
|
|
|
|
|
+ _id: (this.projectId = 'project-id'),
|
|
|
|
|
+ owner_ref: this.userId,
|
|
|
|
|
+ }
|
|
|
this.ProjectGetter = {
|
|
this.ProjectGetter = {
|
|
|
- getProject: (projectId, fields, callback) => {
|
|
|
|
|
- if (projectId === this.projectId) {
|
|
|
|
|
- callback(null, this.project)
|
|
|
|
|
- } else {
|
|
|
|
|
- callback(null, null)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ promises: {
|
|
|
|
|
+ getProject: sinon.stub().callsFake(async (projectId, fields) => {
|
|
|
|
|
+ if (projectId === this.projectId) {
|
|
|
|
|
+ return this.project
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return null
|
|
|
|
|
+ }
|
|
|
|
|
+ }),
|
|
|
},
|
|
},
|
|
|
}
|
|
}
|
|
|
this.UserGetter = {
|
|
this.UserGetter = {
|
|
|
- getUser: (userId, filter, callback) => {
|
|
|
|
|
- if (userId === this.userId) {
|
|
|
|
|
- callback(null, this.user)
|
|
|
|
|
- } else {
|
|
|
|
|
- callback(null, null)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ promises: {
|
|
|
|
|
+ getUser: sinon.stub().callsFake(async (userId, filter) => {
|
|
|
|
|
+ if (userId === this.userId) {
|
|
|
|
|
+ return this.user
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return null
|
|
|
|
|
+ }
|
|
|
|
|
+ }),
|
|
|
},
|
|
},
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
this.SubscriptionLocator = {
|
|
this.SubscriptionLocator = {
|
|
|
- getUsersSubscription: sinon.stub(),
|
|
|
|
|
- getSubscription: sinon.stub(),
|
|
|
|
|
|
|
+ promises: {
|
|
|
|
|
+ getUsersSubscription: sinon.stub().resolves(),
|
|
|
|
|
+ getSubscription: sinon.stub().resolves(),
|
|
|
|
|
+ getMemberSubscriptions: sinon.stub().resolves(),
|
|
|
|
|
+ },
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ this.V1SubscriptionManager = {
|
|
|
|
|
+ promises: {
|
|
|
|
|
+ getSubscriptionsFromV1: sinon.stub().resolves(),
|
|
|
|
|
+ },
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ this.CollaboratorsGetter = {
|
|
|
|
|
+ promises: { getInvitedCollaboratorCount: sinon.stub().resolves() },
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ this.CollaboratorsInviteHandler = {
|
|
|
|
|
+ promises: { getInviteCount: sinon.stub().resolves() },
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
this.LimitationsManager = SandboxedModule.require(modulePath, {
|
|
this.LimitationsManager = SandboxedModule.require(modulePath, {
|
|
@@ -40,21 +67,21 @@ describe('LimitationsManager', function () {
|
|
|
'../User/UserGetter': this.UserGetter,
|
|
'../User/UserGetter': this.UserGetter,
|
|
|
'./SubscriptionLocator': this.SubscriptionLocator,
|
|
'./SubscriptionLocator': this.SubscriptionLocator,
|
|
|
'@overleaf/settings': (this.Settings = {}),
|
|
'@overleaf/settings': (this.Settings = {}),
|
|
|
- '../Collaborators/CollaboratorsGetter': (this.CollaboratorsGetter = {}),
|
|
|
|
|
|
|
+ '../Collaborators/CollaboratorsGetter': this.CollaboratorsGetter,
|
|
|
'../Collaborators/CollaboratorsInviteHandler':
|
|
'../Collaborators/CollaboratorsInviteHandler':
|
|
|
- (this.CollaboratorsInviteHandler = {}),
|
|
|
|
|
- './V1SubscriptionManager': (this.V1SubscriptionManager = {}),
|
|
|
|
|
|
|
+ this.CollaboratorsInviteHandler,
|
|
|
|
|
+ './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 (done) {
|
|
|
this.Settings.defaultFeatures = { collaborators: 23 }
|
|
this.Settings.defaultFeatures = { collaborators: 23 }
|
|
|
this.project.owner_ref = this.userId
|
|
this.project.owner_ref = this.userId
|
|
|
delete this.user.features
|
|
delete this.user.features
|
|
|
- this.callback = sinon.stub()
|
|
|
|
|
|
|
+ this.callback = sinon.stub().callsFake(() => done())
|
|
|
this.LimitationsManager.allowedNumberOfCollaboratorsInProject(
|
|
this.LimitationsManager.allowedNumberOfCollaboratorsInProject(
|
|
|
this.projectId,
|
|
this.projectId,
|
|
|
this.callback
|
|
this.callback
|
|
@@ -69,10 +96,10 @@ 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 (done) {
|
|
|
this.project.owner_ref = this.userId
|
|
this.project.owner_ref = this.userId
|
|
|
this.user.features = { collaborators: 21 }
|
|
this.user.features = { collaborators: 21 }
|
|
|
- this.callback = sinon.stub()
|
|
|
|
|
|
|
+ this.callback = sinon.stub().callsFake(() => done())
|
|
|
this.LimitationsManager.allowedNumberOfCollaboratorsInProject(
|
|
this.LimitationsManager.allowedNumberOfCollaboratorsInProject(
|
|
|
this.projectId,
|
|
this.projectId,
|
|
|
this.callback
|
|
this.callback
|
|
@@ -89,10 +116,10 @@ describe('LimitationsManager', function () {
|
|
|
|
|
|
|
|
describe('allowedNumberOfCollaboratorsForUser', function () {
|
|
describe('allowedNumberOfCollaboratorsForUser', function () {
|
|
|
describe('when the user has no features', function () {
|
|
describe('when the user has no features', function () {
|
|
|
- beforeEach(function () {
|
|
|
|
|
|
|
+ beforeEach(function (done) {
|
|
|
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().callsFake(() => done())
|
|
|
this.LimitationsManager.allowedNumberOfCollaboratorsForUser(
|
|
this.LimitationsManager.allowedNumberOfCollaboratorsForUser(
|
|
|
this.userId,
|
|
this.userId,
|
|
|
this.callback
|
|
this.callback
|
|
@@ -107,9 +134,9 @@ describe('LimitationsManager', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
describe('when the user has features', function () {
|
|
describe('when the user has features', function () {
|
|
|
- beforeEach(function () {
|
|
|
|
|
|
|
+ beforeEach(function (done) {
|
|
|
this.user.features = { collaborators: 21 }
|
|
this.user.features = { collaborators: 21 }
|
|
|
- this.callback = sinon.stub()
|
|
|
|
|
|
|
+ this.callback = sinon.stub().callsFake(() => done())
|
|
|
this.LimitationsManager.allowedNumberOfCollaboratorsForUser(
|
|
this.LimitationsManager.allowedNumberOfCollaboratorsForUser(
|
|
|
this.userId,
|
|
this.userId,
|
|
|
this.callback
|
|
this.callback
|
|
@@ -126,27 +153,17 @@ describe('LimitationsManager', function () {
|
|
|
|
|
|
|
|
describe('canAddXCollaborators', function () {
|
|
describe('canAddXCollaborators', function () {
|
|
|
describe('when the project has fewer collaborators than allowed', function () {
|
|
describe('when the project has fewer collaborators than allowed', function () {
|
|
|
- beforeEach(function () {
|
|
|
|
|
|
|
+ beforeEach(function (done) {
|
|
|
this.current_number = 1
|
|
this.current_number = 1
|
|
|
- this.allowed_number = 2
|
|
|
|
|
|
|
+ this.user.features.collaborators = 2
|
|
|
this.invite_count = 0
|
|
this.invite_count = 0
|
|
|
- this.CollaboratorsGetter.getInvitedCollaboratorCount = (
|
|
|
|
|
- projectId,
|
|
|
|
|
- callback
|
|
|
|
|
- ) => callback(null, this.current_number)
|
|
|
|
|
- this.CollaboratorsInviteHandler.getInviteCount = (
|
|
|
|
|
- projectId,
|
|
|
|
|
- callback
|
|
|
|
|
- ) => callback(null, this.invite_count)
|
|
|
|
|
- sinon
|
|
|
|
|
- .stub(
|
|
|
|
|
- this.LimitationsManager,
|
|
|
|
|
- 'allowedNumberOfCollaboratorsInProject'
|
|
|
|
|
- )
|
|
|
|
|
- .callsFake((projectId, callback) => {
|
|
|
|
|
- callback(null, this.allowed_number)
|
|
|
|
|
- })
|
|
|
|
|
- this.callback = sinon.stub()
|
|
|
|
|
|
|
+ this.CollaboratorsGetter.promises.getInvitedCollaboratorCount = sinon
|
|
|
|
|
+ .stub()
|
|
|
|
|
+ .resolves(this.current_number)
|
|
|
|
|
+ this.CollaboratorsInviteHandler.promises.getInviteCount = sinon
|
|
|
|
|
+ .stub()
|
|
|
|
|
+ .resolves(this.invite_count)
|
|
|
|
|
+ this.callback = sinon.stub().callsFake(() => done())
|
|
|
this.LimitationsManager.canAddXCollaborators(
|
|
this.LimitationsManager.canAddXCollaborators(
|
|
|
this.projectId,
|
|
this.projectId,
|
|
|
1,
|
|
1,
|
|
@@ -160,27 +177,17 @@ describe('LimitationsManager', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
describe('when the project has fewer collaborators and invites than allowed', function () {
|
|
describe('when the project has fewer collaborators and invites than allowed', function () {
|
|
|
- beforeEach(function () {
|
|
|
|
|
|
|
+ beforeEach(function (done) {
|
|
|
this.current_number = 1
|
|
this.current_number = 1
|
|
|
- this.allowed_number = 4
|
|
|
|
|
|
|
+ this.user.features.collaborators = 4
|
|
|
this.invite_count = 1
|
|
this.invite_count = 1
|
|
|
- this.CollaboratorsGetter.getInvitedCollaboratorCount = (
|
|
|
|
|
- projectId,
|
|
|
|
|
- callback
|
|
|
|
|
- ) => callback(null, this.current_number)
|
|
|
|
|
- this.CollaboratorsInviteHandler.getInviteCount = (
|
|
|
|
|
- projectId,
|
|
|
|
|
- callback
|
|
|
|
|
- ) => callback(null, this.invite_count)
|
|
|
|
|
- sinon
|
|
|
|
|
- .stub(
|
|
|
|
|
- this.LimitationsManager,
|
|
|
|
|
- 'allowedNumberOfCollaboratorsInProject'
|
|
|
|
|
- )
|
|
|
|
|
- .callsFake((projectId, callback) => {
|
|
|
|
|
- callback(null, this.allowed_number)
|
|
|
|
|
- })
|
|
|
|
|
- this.callback = sinon.stub()
|
|
|
|
|
|
|
+ this.CollaboratorsGetter.promises.getInvitedCollaboratorCount = sinon
|
|
|
|
|
+ .stub()
|
|
|
|
|
+ .resolves(this.current_number)
|
|
|
|
|
+ this.CollaboratorsInviteHandler.promises.getInviteCount = sinon
|
|
|
|
|
+ .stub()
|
|
|
|
|
+ .resolves(this.invite_count)
|
|
|
|
|
+ this.callback = sinon.stub().callsFake(() => done())
|
|
|
this.LimitationsManager.canAddXCollaborators(
|
|
this.LimitationsManager.canAddXCollaborators(
|
|
|
this.projectId,
|
|
this.projectId,
|
|
|
1,
|
|
1,
|
|
@@ -194,27 +201,17 @@ describe('LimitationsManager', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
describe('when the project has fewer collaborators than allowed but I want to add more than allowed', function () {
|
|
describe('when the project has fewer collaborators than allowed but I want to add more than allowed', function () {
|
|
|
- beforeEach(function () {
|
|
|
|
|
|
|
+ beforeEach(function (done) {
|
|
|
this.current_number = 1
|
|
this.current_number = 1
|
|
|
- this.allowed_number = 2
|
|
|
|
|
|
|
+ this.user.features.collaborators = 2
|
|
|
this.invite_count = 0
|
|
this.invite_count = 0
|
|
|
- this.CollaboratorsGetter.getInvitedCollaboratorCount = (
|
|
|
|
|
- projectId,
|
|
|
|
|
- callback
|
|
|
|
|
- ) => callback(null, this.current_number)
|
|
|
|
|
- this.CollaboratorsInviteHandler.getInviteCount = (
|
|
|
|
|
- projectId,
|
|
|
|
|
- callback
|
|
|
|
|
- ) => callback(null, this.invite_count)
|
|
|
|
|
- sinon
|
|
|
|
|
- .stub(
|
|
|
|
|
- this.LimitationsManager,
|
|
|
|
|
- 'allowedNumberOfCollaboratorsInProject'
|
|
|
|
|
- )
|
|
|
|
|
- .callsFake((projectId, callback) => {
|
|
|
|
|
- callback(null, this.allowed_number)
|
|
|
|
|
- })
|
|
|
|
|
- this.callback = sinon.stub()
|
|
|
|
|
|
|
+ this.CollaboratorsGetter.promises.getInvitedCollaboratorCount = sinon
|
|
|
|
|
+ .stub()
|
|
|
|
|
+ .resolves(this.current_number)
|
|
|
|
|
+ this.CollaboratorsInviteHandler.promises.getInviteCount = sinon
|
|
|
|
|
+ .stub()
|
|
|
|
|
+ .resolves(this.invite_count)
|
|
|
|
|
+ this.callback = sinon.stub().callsFake(() => done())
|
|
|
this.LimitationsManager.canAddXCollaborators(
|
|
this.LimitationsManager.canAddXCollaborators(
|
|
|
this.projectId,
|
|
this.projectId,
|
|
|
2,
|
|
2,
|
|
@@ -228,27 +225,17 @@ describe('LimitationsManager', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
describe('when the project has more collaborators than allowed', function () {
|
|
describe('when the project has more collaborators than allowed', function () {
|
|
|
- beforeEach(function () {
|
|
|
|
|
|
|
+ beforeEach(function (done) {
|
|
|
this.current_number = 3
|
|
this.current_number = 3
|
|
|
- this.allowed_number = 2
|
|
|
|
|
|
|
+ this.user.features.collaborators = 2
|
|
|
this.invite_count = 0
|
|
this.invite_count = 0
|
|
|
- this.CollaboratorsGetter.getInvitedCollaboratorCount = (
|
|
|
|
|
- projectId,
|
|
|
|
|
- callback
|
|
|
|
|
- ) => callback(null, this.current_number)
|
|
|
|
|
- this.CollaboratorsInviteHandler.getInviteCount = (
|
|
|
|
|
- projectId,
|
|
|
|
|
- callback
|
|
|
|
|
- ) => callback(null, this.invite_count)
|
|
|
|
|
- sinon
|
|
|
|
|
- .stub(
|
|
|
|
|
- this.LimitationsManager,
|
|
|
|
|
- 'allowedNumberOfCollaboratorsInProject'
|
|
|
|
|
- )
|
|
|
|
|
- .callsFake((projectId, callback) => {
|
|
|
|
|
- callback(null, this.allowed_number)
|
|
|
|
|
- })
|
|
|
|
|
- this.callback = sinon.stub()
|
|
|
|
|
|
|
+ this.CollaboratorsGetter.promises.getInvitedCollaboratorCount = sinon
|
|
|
|
|
+ .stub()
|
|
|
|
|
+ .resolves(this.current_number)
|
|
|
|
|
+ this.CollaboratorsInviteHandler.promises.getInviteCount = sinon
|
|
|
|
|
+ .stub()
|
|
|
|
|
+ .resolves(this.invite_count)
|
|
|
|
|
+ this.callback = sinon.stub().callsFake(() => done())
|
|
|
this.LimitationsManager.canAddXCollaborators(
|
|
this.LimitationsManager.canAddXCollaborators(
|
|
|
this.projectId,
|
|
this.projectId,
|
|
|
1,
|
|
1,
|
|
@@ -262,27 +249,17 @@ describe('LimitationsManager', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
describe('when the project has infinite collaborators', function () {
|
|
describe('when the project has infinite collaborators', function () {
|
|
|
- beforeEach(function () {
|
|
|
|
|
|
|
+ beforeEach(function (done) {
|
|
|
this.current_number = 100
|
|
this.current_number = 100
|
|
|
- this.allowed_number = -1
|
|
|
|
|
|
|
+ this.user.features.collaborators = -1
|
|
|
this.invite_count = 0
|
|
this.invite_count = 0
|
|
|
- this.CollaboratorsGetter.getInvitedCollaboratorCount = (
|
|
|
|
|
- projectId,
|
|
|
|
|
- callback
|
|
|
|
|
- ) => callback(null, this.current_number)
|
|
|
|
|
- this.CollaboratorsInviteHandler.getInviteCount = (
|
|
|
|
|
- projectId,
|
|
|
|
|
- callback
|
|
|
|
|
- ) => callback(null, this.invite_count)
|
|
|
|
|
- sinon
|
|
|
|
|
- .stub(
|
|
|
|
|
- this.LimitationsManager,
|
|
|
|
|
- 'allowedNumberOfCollaboratorsInProject'
|
|
|
|
|
- )
|
|
|
|
|
- .callsFake((projectId, callback) => {
|
|
|
|
|
- callback(null, this.allowed_number)
|
|
|
|
|
- })
|
|
|
|
|
- this.callback = sinon.stub()
|
|
|
|
|
|
|
+ this.CollaboratorsGetter.promises.getInvitedCollaboratorCount = sinon
|
|
|
|
|
+ .stub()
|
|
|
|
|
+ .resolves(this.current_number)
|
|
|
|
|
+ this.CollaboratorsInviteHandler.promises.getInviteCount = sinon
|
|
|
|
|
+ .stub()
|
|
|
|
|
+ .resolves(this.invite_count)
|
|
|
|
|
+ this.callback = sinon.stub().callsFake(() => done())
|
|
|
this.LimitationsManager.canAddXCollaborators(
|
|
this.LimitationsManager.canAddXCollaborators(
|
|
|
this.projectId,
|
|
this.projectId,
|
|
|
1,
|
|
1,
|
|
@@ -296,27 +273,17 @@ describe('LimitationsManager', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
describe('when the project has more invites than allowed', function () {
|
|
describe('when the project has more invites than allowed', function () {
|
|
|
- beforeEach(function () {
|
|
|
|
|
|
|
+ beforeEach(function (done) {
|
|
|
this.current_number = 0
|
|
this.current_number = 0
|
|
|
- this.allowed_number = 2
|
|
|
|
|
|
|
+ this.user.features.collaborators = 2
|
|
|
this.invite_count = 2
|
|
this.invite_count = 2
|
|
|
- this.CollaboratorsGetter.getInvitedCollaboratorCount = (
|
|
|
|
|
- projectId,
|
|
|
|
|
- callback
|
|
|
|
|
- ) => callback(null, this.current_number)
|
|
|
|
|
- this.CollaboratorsInviteHandler.getInviteCount = (
|
|
|
|
|
- projectId,
|
|
|
|
|
- callback
|
|
|
|
|
- ) => callback(null, this.invite_count)
|
|
|
|
|
- sinon
|
|
|
|
|
- .stub(
|
|
|
|
|
- this.LimitationsManager,
|
|
|
|
|
- 'allowedNumberOfCollaboratorsInProject'
|
|
|
|
|
- )
|
|
|
|
|
- .callsFake((projectId, callback) => {
|
|
|
|
|
- callback(null, this.allowed_number)
|
|
|
|
|
- })
|
|
|
|
|
- this.callback = sinon.stub()
|
|
|
|
|
|
|
+ this.CollaboratorsGetter.promises.getInvitedCollaboratorCount = sinon
|
|
|
|
|
+ .stub()
|
|
|
|
|
+ .resolves(this.current_number)
|
|
|
|
|
+ this.CollaboratorsInviteHandler.promises.getInviteCount = sinon
|
|
|
|
|
+ .stub()
|
|
|
|
|
+ .resolves(this.invite_count)
|
|
|
|
|
+ this.callback = sinon.stub().callsFake(() => done())
|
|
|
this.LimitationsManager.canAddXCollaborators(
|
|
this.LimitationsManager.canAddXCollaborators(
|
|
|
this.projectId,
|
|
this.projectId,
|
|
|
1,
|
|
1,
|
|
@@ -330,27 +297,17 @@ describe('LimitationsManager', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
describe('when the project has more invites and collaborators than allowed', function () {
|
|
describe('when the project has more invites and collaborators than allowed', function () {
|
|
|
- beforeEach(function () {
|
|
|
|
|
|
|
+ beforeEach(function (done) {
|
|
|
this.current_number = 1
|
|
this.current_number = 1
|
|
|
- this.allowed_number = 2
|
|
|
|
|
|
|
+ this.user.features.collaborators = 2
|
|
|
this.invite_count = 1
|
|
this.invite_count = 1
|
|
|
- this.CollaboratorsGetter.getInvitedCollaboratorCount = (
|
|
|
|
|
- projectId,
|
|
|
|
|
- callback
|
|
|
|
|
- ) => callback(null, this.current_number)
|
|
|
|
|
- this.CollaboratorsInviteHandler.getInviteCount = (
|
|
|
|
|
- projectId,
|
|
|
|
|
- callback
|
|
|
|
|
- ) => callback(null, this.invite_count)
|
|
|
|
|
- sinon
|
|
|
|
|
- .stub(
|
|
|
|
|
- this.LimitationsManager,
|
|
|
|
|
- 'allowedNumberOfCollaboratorsInProject'
|
|
|
|
|
- )
|
|
|
|
|
- .callsFake((projectId, callback) => {
|
|
|
|
|
- callback(null, this.allowed_number)
|
|
|
|
|
- })
|
|
|
|
|
- this.callback = sinon.stub()
|
|
|
|
|
|
|
+ this.CollaboratorsGetter.promises.getInvitedCollaboratorCount = sinon
|
|
|
|
|
+ .stub()
|
|
|
|
|
+ .resolves(this.current_number)
|
|
|
|
|
+ this.CollaboratorsInviteHandler.promises.getInviteCount = sinon
|
|
|
|
|
+ .stub()
|
|
|
|
|
+ .resolves(this.invite_count)
|
|
|
|
|
+ this.callback = sinon.stub().callsFake(() => done())
|
|
|
this.LimitationsManager.canAddXCollaborators(
|
|
this.LimitationsManager.canAddXCollaborators(
|
|
|
this.projectId,
|
|
this.projectId,
|
|
|
1,
|
|
1,
|
|
@@ -366,13 +323,17 @@ describe('LimitationsManager', function () {
|
|
|
|
|
|
|
|
describe('userHasV2Subscription', function () {
|
|
describe('userHasV2Subscription', function () {
|
|
|
beforeEach(function () {
|
|
beforeEach(function () {
|
|
|
- this.SubscriptionLocator.getUsersSubscription = sinon.stub()
|
|
|
|
|
|
|
+ this.SubscriptionLocator.promises.getUsersSubscription = sinon
|
|
|
|
|
+ .stub()
|
|
|
|
|
+ .resolves()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should return true if the recurly token is set', function (done) {
|
|
it('should return true if the recurly token is set', function (done) {
|
|
|
- this.SubscriptionLocator.getUsersSubscription.callsArgWith(1, null, {
|
|
|
|
|
- recurlySubscription_id: '1234',
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ this.SubscriptionLocator.promises.getUsersSubscription = sinon
|
|
|
|
|
+ .stub()
|
|
|
|
|
+ .resolves({
|
|
|
|
|
+ recurlySubscription_id: '1234',
|
|
|
|
|
+ })
|
|
|
this.LimitationsManager.userHasV2Subscription(
|
|
this.LimitationsManager.userHasV2Subscription(
|
|
|
this.user,
|
|
this.user,
|
|
|
(err, hasSubscription) => {
|
|
(err, hasSubscription) => {
|
|
@@ -384,7 +345,7 @@ describe('LimitationsManager', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should return false if the recurly token is not set', function (done) {
|
|
it('should return false if the recurly token is not set', function (done) {
|
|
|
- this.SubscriptionLocator.getUsersSubscription.callsArgWith(1, null, {})
|
|
|
|
|
|
|
+ this.SubscriptionLocator.promises.getUsersSubscription.resolves({})
|
|
|
this.subscription = {}
|
|
this.subscription = {}
|
|
|
this.LimitationsManager.userHasV2Subscription(
|
|
this.LimitationsManager.userHasV2Subscription(
|
|
|
this.user,
|
|
this.user,
|
|
@@ -397,7 +358,7 @@ describe('LimitationsManager', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should return false if the subscription is undefined', function (done) {
|
|
it('should return false if the subscription is undefined', function (done) {
|
|
|
- this.SubscriptionLocator.getUsersSubscription.callsArgWith(1)
|
|
|
|
|
|
|
+ this.SubscriptionLocator.promises.getUsersSubscription.resolves()
|
|
|
this.LimitationsManager.userHasV2Subscription(
|
|
this.LimitationsManager.userHasV2Subscription(
|
|
|
this.user,
|
|
this.user,
|
|
|
(err, hasSubscription) => {
|
|
(err, hasSubscription) => {
|
|
@@ -410,9 +371,7 @@ describe('LimitationsManager', function () {
|
|
|
|
|
|
|
|
it('should return the subscription', function (done) {
|
|
it('should return the subscription', function (done) {
|
|
|
const stubbedSubscription = { freeTrial: {}, token: '' }
|
|
const stubbedSubscription = { freeTrial: {}, token: '' }
|
|
|
- this.SubscriptionLocator.getUsersSubscription.callsArgWith(
|
|
|
|
|
- 1,
|
|
|
|
|
- null,
|
|
|
|
|
|
|
+ this.SubscriptionLocator.promises.getUsersSubscription.resolves(
|
|
|
stubbedSubscription
|
|
stubbedSubscription
|
|
|
)
|
|
)
|
|
|
this.LimitationsManager.userHasV2Subscription(
|
|
this.LimitationsManager.userHasV2Subscription(
|
|
@@ -428,9 +387,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 }
|
|
|
- this.SubscriptionLocator.getUsersSubscription.callsArgWith(
|
|
|
|
|
- 1,
|
|
|
|
|
- null,
|
|
|
|
|
|
|
+ this.SubscriptionLocator.promises.getUsersSubscription.resolves(
|
|
|
this.fakeSubscription
|
|
this.fakeSubscription
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
@@ -461,11 +418,13 @@ describe('LimitationsManager', function () {
|
|
|
|
|
|
|
|
describe('userIsMemberOfGroupSubscription', function () {
|
|
describe('userIsMemberOfGroupSubscription', function () {
|
|
|
beforeEach(function () {
|
|
beforeEach(function () {
|
|
|
- this.SubscriptionLocator.getMemberSubscriptions = sinon.stub()
|
|
|
|
|
|
|
+ this.SubscriptionLocator.promises.getMemberSubscriptions = sinon
|
|
|
|
|
+ .stub()
|
|
|
|
|
+ .resolves()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
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.promises.getMemberSubscriptions.resolves([])
|
|
|
this.LimitationsManager.userIsMemberOfGroupSubscription(
|
|
this.LimitationsManager.userIsMemberOfGroupSubscription(
|
|
|
this.user,
|
|
this.user,
|
|
|
(err, isMember) => {
|
|
(err, isMember) => {
|
|
@@ -478,9 +437,7 @@ describe('LimitationsManager', function () {
|
|
|
|
|
|
|
|
it('should return true if there are no groups subcriptions', function (done) {
|
|
it('should return true if there are no groups subcriptions', function (done) {
|
|
|
let subscriptions
|
|
let subscriptions
|
|
|
- this.SubscriptionLocator.getMemberSubscriptions.callsArgWith(
|
|
|
|
|
- 1,
|
|
|
|
|
- null,
|
|
|
|
|
|
|
+ this.SubscriptionLocator.promises.getMemberSubscriptions.resolves(
|
|
|
(subscriptions = ['mock-subscription'])
|
|
(subscriptions = ['mock-subscription'])
|
|
|
)
|
|
)
|
|
|
this.LimitationsManager.userIsMemberOfGroupSubscription(
|
|
this.LimitationsManager.userIsMemberOfGroupSubscription(
|
|
@@ -497,21 +454,21 @@ describe('LimitationsManager', function () {
|
|
|
|
|
|
|
|
describe('hasPaidSubscription', function () {
|
|
describe('hasPaidSubscription', function () {
|
|
|
beforeEach(function () {
|
|
beforeEach(function () {
|
|
|
- this.LimitationsManager.userIsMemberOfGroupSubscription = sinon
|
|
|
|
|
|
|
+ this.SubscriptionLocator.promises.getMemberSubscriptions = sinon
|
|
|
.stub()
|
|
.stub()
|
|
|
- .yields(null, false)
|
|
|
|
|
- this.LimitationsManager.userHasV2Subscription = sinon
|
|
|
|
|
|
|
+ .resolves([])
|
|
|
|
|
+ this.SubscriptionLocator.promises.getUsersSubscription = sinon
|
|
|
.stub()
|
|
.stub()
|
|
|
- .yields(null, false)
|
|
|
|
|
- this.LimitationsManager.userHasV1Subscription = sinon
|
|
|
|
|
|
|
+ .resolves(null)
|
|
|
|
|
+ this.V1SubscriptionManager.promises.userHasV1Subscription = sinon
|
|
|
.stub()
|
|
.stub()
|
|
|
- .yields(null, false)
|
|
|
|
|
|
|
+ .yields(null, null)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should return true if userIsMemberOfGroupSubscription', function (done) {
|
|
it('should return true if userIsMemberOfGroupSubscription', function (done) {
|
|
|
- this.LimitationsManager.userIsMemberOfGroupSubscription = sinon
|
|
|
|
|
|
|
+ this.SubscriptionLocator.promises.getMemberSubscriptions = sinon
|
|
|
.stub()
|
|
.stub()
|
|
|
- .yields(null, true)
|
|
|
|
|
|
|
+ .resolves([{ _id: '123' }])
|
|
|
this.LimitationsManager.hasPaidSubscription(
|
|
this.LimitationsManager.hasPaidSubscription(
|
|
|
this.user,
|
|
this.user,
|
|
|
(err, hasSubOrIsGroupMember) => {
|
|
(err, hasSubOrIsGroupMember) => {
|
|
@@ -523,9 +480,9 @@ describe('LimitationsManager', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should return true if userHasV2Subscription', function (done) {
|
|
it('should return true if userHasV2Subscription', function (done) {
|
|
|
- this.LimitationsManager.userHasV2Subscription = sinon
|
|
|
|
|
|
|
+ this.SubscriptionLocator.promises.getUsersSubscription = sinon
|
|
|
.stub()
|
|
.stub()
|
|
|
- .yields(null, true)
|
|
|
|
|
|
|
+ .resolves({ recurlySubscription_id: '123' })
|
|
|
this.LimitationsManager.hasPaidSubscription(
|
|
this.LimitationsManager.hasPaidSubscription(
|
|
|
this.user,
|
|
this.user,
|
|
|
(err, hasSubOrIsGroupMember) => {
|
|
(err, hasSubOrIsGroupMember) => {
|
|
@@ -537,9 +494,9 @@ describe('LimitationsManager', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should return true if userHasV1Subscription', function (done) {
|
|
it('should return true if userHasV1Subscription', function (done) {
|
|
|
- this.LimitationsManager.userHasV1Subscription = sinon
|
|
|
|
|
|
|
+ this.V1SubscriptionManager.promises.getSubscriptionsFromV1 = sinon
|
|
|
.stub()
|
|
.stub()
|
|
|
- .yields(null, true)
|
|
|
|
|
|
|
+ .resolves({ has_subscription: true })
|
|
|
this.LimitationsManager.hasPaidSubscription(
|
|
this.LimitationsManager.hasPaidSubscription(
|
|
|
this.user,
|
|
this.user,
|
|
|
(err, hasSubOrIsGroupMember) => {
|
|
(err, hasSubOrIsGroupMember) => {
|
|
@@ -575,18 +532,18 @@ describe('LimitationsManager', function () {
|
|
|
|
|
|
|
|
describe('userHasV1OrV2Subscription', function () {
|
|
describe('userHasV1OrV2Subscription', function () {
|
|
|
beforeEach(function () {
|
|
beforeEach(function () {
|
|
|
- this.LimitationsManager.userHasV2Subscription = sinon
|
|
|
|
|
|
|
+ this.SubscriptionLocator.promises.getUsersSubscription = sinon
|
|
|
.stub()
|
|
.stub()
|
|
|
- .yields(null, false)
|
|
|
|
|
- this.LimitationsManager.userHasV1Subscription = sinon
|
|
|
|
|
|
|
+ .resolves()
|
|
|
|
|
+ this.V1SubscriptionManager.promises.userHasV1Subscription = sinon
|
|
|
.stub()
|
|
.stub()
|
|
|
- .yields(null, false)
|
|
|
|
|
|
|
+ .resolves()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should return true if userHasV2Subscription', function (done) {
|
|
it('should return true if userHasV2Subscription', function (done) {
|
|
|
- this.LimitationsManager.userHasV2Subscription = sinon
|
|
|
|
|
|
|
+ this.SubscriptionLocator.promises.getUsersSubscription = sinon
|
|
|
.stub()
|
|
.stub()
|
|
|
- .yields(null, true)
|
|
|
|
|
|
|
+ .resolves({ recurlySubscription_id: '123' })
|
|
|
this.LimitationsManager.userHasV1OrV2Subscription(
|
|
this.LimitationsManager.userHasV1OrV2Subscription(
|
|
|
this.user,
|
|
this.user,
|
|
|
(err, hasSub) => {
|
|
(err, hasSub) => {
|
|
@@ -598,9 +555,9 @@ describe('LimitationsManager', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should return true if userHasV1Subscription', function (done) {
|
|
it('should return true if userHasV1Subscription', function (done) {
|
|
|
- this.LimitationsManager.userHasV1Subscription = sinon
|
|
|
|
|
|
|
+ this.V1SubscriptionManager.promises.getSubscriptionsFromV1 = sinon
|
|
|
.stub()
|
|
.stub()
|
|
|
- .yields(null, true)
|
|
|
|
|
|
|
+ .resolves({ has_subscription: true })
|
|
|
this.LimitationsManager.userHasV1OrV2Subscription(
|
|
this.LimitationsManager.userHasV1OrV2Subscription(
|
|
|
this.user,
|
|
this.user,
|
|
|
(err, hasSub) => {
|
|
(err, hasSub) => {
|
|
@@ -636,9 +593,7 @@ describe('LimitationsManager', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should return true if the limit is hit (including members and invites)', function (done) {
|
|
it('should return true if the limit is hit (including members and invites)', function (done) {
|
|
|
- this.SubscriptionLocator.getSubscription.callsArgWith(
|
|
|
|
|
- 1,
|
|
|
|
|
- null,
|
|
|
|
|
|
|
+ this.SubscriptionLocator.promises.getSubscription.resolves(
|
|
|
this.subscription
|
|
this.subscription
|
|
|
)
|
|
)
|
|
|
this.LimitationsManager.hasGroupMembersLimitReached(
|
|
this.LimitationsManager.hasGroupMembersLimitReached(
|
|
@@ -653,9 +608,7 @@ describe('LimitationsManager', function () {
|
|
|
|
|
|
|
|
it('should return false if the limit is not hit (including members and invites)', function (done) {
|
|
it('should return false if the limit is not hit (including members and invites)', function (done) {
|
|
|
this.subscription.membersLimit = 4
|
|
this.subscription.membersLimit = 4
|
|
|
- this.SubscriptionLocator.getSubscription.callsArgWith(
|
|
|
|
|
- 1,
|
|
|
|
|
- null,
|
|
|
|
|
|
|
+ this.SubscriptionLocator.promises.getSubscription.resolves(
|
|
|
this.subscription
|
|
this.subscription
|
|
|
)
|
|
)
|
|
|
this.LimitationsManager.hasGroupMembersLimitReached(
|
|
this.LimitationsManager.hasGroupMembersLimitReached(
|
|
@@ -670,9 +623,7 @@ describe('LimitationsManager', function () {
|
|
|
|
|
|
|
|
it('should return true if the limit has been exceded (including members and invites)', function (done) {
|
|
it('should return true if the limit has been exceded (including members and invites)', function (done) {
|
|
|
this.subscription.membersLimit = 2
|
|
this.subscription.membersLimit = 2
|
|
|
- this.SubscriptionLocator.getSubscription.callsArgWith(
|
|
|
|
|
- 1,
|
|
|
|
|
- null,
|
|
|
|
|
|
|
+ this.SubscriptionLocator.promises.getSubscription.resolves(
|
|
|
this.subscription
|
|
this.subscription
|
|
|
)
|
|
)
|
|
|
this.LimitationsManager.hasGroupMembersLimitReached(
|
|
this.LimitationsManager.hasGroupMembersLimitReached(
|
|
@@ -688,14 +639,14 @@ describe('LimitationsManager', function () {
|
|
|
|
|
|
|
|
describe('userHasV1Subscription', function () {
|
|
describe('userHasV1Subscription', function () {
|
|
|
it('should return true if v1 returns has_subscription = true', function (done) {
|
|
it('should return true if v1 returns has_subscription = true', function (done) {
|
|
|
- this.V1SubscriptionManager.getSubscriptionsFromV1 = sinon
|
|
|
|
|
|
|
+ this.V1SubscriptionManager.promises.getSubscriptionsFromV1 = sinon
|
|
|
.stub()
|
|
.stub()
|
|
|
- .yields(null, { has_subscription: true })
|
|
|
|
|
|
|
+ .resolves({ has_subscription: true })
|
|
|
this.LimitationsManager.userHasV1Subscription(
|
|
this.LimitationsManager.userHasV1Subscription(
|
|
|
this.user,
|
|
this.user,
|
|
|
(error, result) => {
|
|
(error, result) => {
|
|
|
assert.equal(error, null)
|
|
assert.equal(error, null)
|
|
|
- this.V1SubscriptionManager.getSubscriptionsFromV1
|
|
|
|
|
|
|
+ this.V1SubscriptionManager.promises.getSubscriptionsFromV1
|
|
|
.calledWith(this.userId)
|
|
.calledWith(this.userId)
|
|
|
.should.equal(true)
|
|
.should.equal(true)
|
|
|
result.should.equal(true)
|
|
result.should.equal(true)
|
|
@@ -705,14 +656,14 @@ describe('LimitationsManager', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should return false if v1 returns has_subscription = false', function (done) {
|
|
it('should return false if v1 returns has_subscription = false', function (done) {
|
|
|
- this.V1SubscriptionManager.getSubscriptionsFromV1 = sinon
|
|
|
|
|
|
|
+ this.V1SubscriptionManager.promises.getSubscriptionsFromV1 = sinon
|
|
|
.stub()
|
|
.stub()
|
|
|
- .yields(null, { has_subscription: false })
|
|
|
|
|
|
|
+ .resolves({ has_subscription: false })
|
|
|
this.LimitationsManager.userHasV1Subscription(
|
|
this.LimitationsManager.userHasV1Subscription(
|
|
|
this.user,
|
|
this.user,
|
|
|
(error, result) => {
|
|
(error, result) => {
|
|
|
assert.equal(error, null)
|
|
assert.equal(error, null)
|
|
|
- this.V1SubscriptionManager.getSubscriptionsFromV1
|
|
|
|
|
|
|
+ this.V1SubscriptionManager.promises.getSubscriptionsFromV1
|
|
|
.calledWith(this.userId)
|
|
.calledWith(this.userId)
|
|
|
.should.equal(true)
|
|
.should.equal(true)
|
|
|
result.should.equal(false)
|
|
result.should.equal(false)
|
|
@@ -722,14 +673,14 @@ describe('LimitationsManager', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should return false if v1 returns nothing', function (done) {
|
|
it('should return false if v1 returns nothing', function (done) {
|
|
|
- this.V1SubscriptionManager.getSubscriptionsFromV1 = sinon
|
|
|
|
|
|
|
+ this.V1SubscriptionManager.promises.getSubscriptionsFromV1 = sinon
|
|
|
.stub()
|
|
.stub()
|
|
|
- .yields(null, null)
|
|
|
|
|
|
|
+ .resolves({ has_subscription: false })
|
|
|
this.LimitationsManager.userHasV1Subscription(
|
|
this.LimitationsManager.userHasV1Subscription(
|
|
|
this.user,
|
|
this.user,
|
|
|
(error, result) => {
|
|
(error, result) => {
|
|
|
assert.equal(error, null)
|
|
assert.equal(error, null)
|
|
|
- this.V1SubscriptionManager.getSubscriptionsFromV1
|
|
|
|
|
|
|
+ this.V1SubscriptionManager.promises.getSubscriptionsFromV1
|
|
|
.calledWith(this.userId)
|
|
.calledWith(this.userId)
|
|
|
.should.equal(true)
|
|
.should.equal(true)
|
|
|
result.should.equal(false)
|
|
result.should.equal(false)
|