2019-05-29 05:21:06 -04:00
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
const path = require('path')
|
|
|
|
const sinon = require('sinon')
|
2019-09-30 10:46:15 -04:00
|
|
|
const { expect } = require('chai')
|
|
|
|
const { ObjectId } = require('mongodb')
|
|
|
|
|
|
|
|
const MODULE_PATH = path.join(
|
2019-05-29 05:21:06 -04:00
|
|
|
__dirname,
|
|
|
|
'../../../../app/src/Features/Project/ProjectController'
|
|
|
|
)
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('ProjectController', function () {
|
|
|
|
beforeEach(function () {
|
2023-12-18 05:54:01 -05:00
|
|
|
this.project_id = new ObjectId('abcdefabcdefabcdefabcdef')
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
|
|
this.user = {
|
2023-12-18 05:54:01 -05:00
|
|
|
_id: new ObjectId('123456123456123456123456'),
|
2019-10-21 12:02:01 -04:00
|
|
|
email: 'test@overleaf.com',
|
2019-05-29 05:21:06 -04:00
|
|
|
first_name: 'bjkdsjfk',
|
2019-10-21 12:02:01 -04:00
|
|
|
features: {},
|
2021-04-27 03:52:58 -04:00
|
|
|
emails: [{ email: 'test@overleaf.com' }],
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
this.settings = {
|
|
|
|
apis: {
|
|
|
|
chat: {
|
2021-04-27 03:52:58 -04:00
|
|
|
url: 'chat.com',
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
2021-10-20 06:17:59 -04:00
|
|
|
siteUrl: 'https://overleaf.com',
|
2021-04-27 03:52:58 -04:00
|
|
|
algolia: {},
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
this.brandVariationDetails = {
|
|
|
|
id: '12',
|
|
|
|
active: true,
|
|
|
|
brand_name: 'The journal',
|
|
|
|
home_url: 'http://www.thejournal.com/',
|
2021-04-27 03:52:58 -04:00
|
|
|
publish_menu_link_html: 'Submit your paper to the <em>The Journal</em>',
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
this.token = 'some-token'
|
|
|
|
this.ProjectDeleter = {
|
|
|
|
deleteProject: sinon.stub().callsArg(2),
|
|
|
|
restoreProject: sinon.stub().callsArg(1),
|
2021-04-27 03:52:58 -04:00
|
|
|
findArchivedProjects: sinon.stub(),
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
this.ProjectDuplicator = {
|
2023-09-28 06:12:18 -04:00
|
|
|
duplicate: sinon.stub().callsArgWith(4, null, { _id: this.project_id }),
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
this.ProjectCreationHandler = {
|
|
|
|
createExampleProject: sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(2, null, { _id: this.project_id }),
|
|
|
|
createBasicProject: sinon
|
|
|
|
.stub()
|
2021-04-27 03:52:58 -04:00
|
|
|
.callsArgWith(2, null, { _id: this.project_id }),
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
this.SubscriptionLocator = { getUsersSubscription: sinon.stub() }
|
2022-04-28 11:08:38 -04:00
|
|
|
this.LimitationsManager = {
|
|
|
|
hasPaidSubscription: sinon.stub(),
|
|
|
|
userIsMemberOfGroupSubscription: sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(1, null, false),
|
|
|
|
}
|
2023-09-28 06:12:18 -04:00
|
|
|
this.TagsHandler = {
|
|
|
|
getTagsForProject: sinon.stub().callsArgWith(2, null, [
|
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
project_ids: [this.project_id],
|
|
|
|
},
|
|
|
|
]),
|
|
|
|
addProjectToTags: sinon.stub(),
|
|
|
|
}
|
2021-12-14 08:26:16 -05:00
|
|
|
this.UserModel = { findById: sinon.stub(), updateOne: sinon.stub() }
|
2019-10-18 05:32:19 -04:00
|
|
|
this.AuthorizationManager = {
|
|
|
|
getPrivilegeLevelForProject: sinon.stub(),
|
2021-04-27 03:52:58 -04:00
|
|
|
isRestrictedUser: sinon.stub().returns(false),
|
2019-10-18 05:32:19 -04:00
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
this.EditorController = { renameProject: sinon.stub() }
|
|
|
|
this.InactiveProjectManager = { reactivateProjectIfRequired: sinon.stub() }
|
|
|
|
this.ProjectUpdateHandler = { markAsOpened: sinon.stub() }
|
|
|
|
this.ProjectGetter = {
|
|
|
|
findAllUsersProjects: sinon.stub(),
|
2021-04-27 03:52:58 -04:00
|
|
|
getProject: sinon.stub(),
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-08-09 05:40:11 -04:00
|
|
|
this.ProjectHelper = {
|
2019-08-27 06:38:17 -04:00
|
|
|
isArchived: sinon.stub(),
|
|
|
|
isTrashed: sinon.stub(),
|
2020-06-30 08:04:59 -04:00
|
|
|
isArchivedOrTrashed: sinon.stub(),
|
2021-04-27 03:52:58 -04:00
|
|
|
getAllowedImagesForUser: sinon.stub().returns([]),
|
2019-08-09 05:40:11 -04:00
|
|
|
}
|
2021-07-28 04:51:20 -04:00
|
|
|
this.SessionManager = {
|
2019-05-29 05:21:06 -04:00
|
|
|
getLoggedInUser: sinon.stub().callsArgWith(1, null, this.user),
|
|
|
|
getLoggedInUserId: sinon.stub().returns(this.user._id),
|
|
|
|
getSessionUser: sinon.stub().returns(this.user),
|
2021-04-27 03:52:58 -04:00
|
|
|
isUserLoggedIn: sinon.stub().returns(true),
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-12-10 03:10:05 -05:00
|
|
|
this.UserController = {
|
2021-04-27 03:52:58 -04:00
|
|
|
logout: sinon.stub(),
|
2019-12-10 03:10:05 -05:00
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
this.TokenAccessHandler = {
|
|
|
|
getRequestToken: sinon.stub().returns(this.token),
|
|
|
|
}
|
2019-10-07 04:30:51 -04:00
|
|
|
this.CollaboratorsGetter = {
|
2021-04-27 03:52:58 -04:00
|
|
|
userIsTokenMember: sinon.stub().callsArgWith(2, null, false),
|
2022-09-27 07:23:36 -04:00
|
|
|
isUserInvitedMemberOfProject: sinon.stub().callsArgWith(2, null, true),
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
this.ProjectEntityHandler = {}
|
|
|
|
this.UserGetter = {
|
2021-02-02 09:24:42 -05:00
|
|
|
getUserFullEmails: sinon.stub().yields(null, []),
|
2019-05-29 05:21:06 -04:00
|
|
|
getUser: sinon
|
|
|
|
.stub()
|
2021-04-27 03:52:58 -04:00
|
|
|
.callsArgWith(2, null, { lastLoginIp: '192.170.18.2' }),
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-10-21 12:02:01 -04:00
|
|
|
this.Features = {
|
2021-04-27 03:52:58 -04:00
|
|
|
hasFeature: sinon.stub(),
|
2019-10-21 12:02:01 -04:00
|
|
|
}
|
2021-10-26 09:31:24 -04:00
|
|
|
this.FeaturesUpdater = {
|
|
|
|
featuresEpochIsCurrent: sinon.stub().returns(true),
|
|
|
|
refreshFeatures: sinon.stub().yields(null, this.user),
|
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
this.BrandVariationsHandler = {
|
|
|
|
getBrandVariationById: sinon
|
|
|
|
.stub()
|
2021-04-27 03:52:58 -04:00
|
|
|
.callsArgWith(1, null, this.brandVariationDetails),
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-11-26 08:11:19 -05:00
|
|
|
this.TpdsProjectFlusher = {
|
2021-04-27 03:52:58 -04:00
|
|
|
flushProjectToTpdsIfNeeded: sinon.stub().yields(),
|
2019-11-26 08:11:19 -05:00
|
|
|
}
|
2020-04-02 06:01:41 -04:00
|
|
|
this.Metrics = {
|
|
|
|
Timer: class {
|
|
|
|
done() {}
|
|
|
|
},
|
2021-04-27 03:52:58 -04:00
|
|
|
inc: sinon.stub(),
|
2020-04-02 06:01:41 -04:00
|
|
|
}
|
2021-05-21 07:32:07 -04:00
|
|
|
this.SplitTestHandler = {
|
2021-08-19 11:42:49 -04:00
|
|
|
promises: {
|
2021-11-22 05:35:10 -05:00
|
|
|
getAssignment: sinon.stub().resolves({ variant: 'default' }),
|
2021-08-19 11:42:49 -04:00
|
|
|
},
|
2021-11-22 05:35:10 -05:00
|
|
|
getAssignment: sinon.stub().yields(null, { variant: 'default' }),
|
2024-04-18 09:54:16 -04:00
|
|
|
}
|
|
|
|
this.SplitTestSessionHandler = {
|
2023-09-13 07:07:00 -04:00
|
|
|
sessionMaintenance: sinon.stub().yields(),
|
2021-08-19 11:42:49 -04:00
|
|
|
}
|
2022-04-27 11:12:04 -04:00
|
|
|
this.InstitutionsFeatures = {
|
|
|
|
hasLicence: sinon.stub().callsArgWith(1, null, false),
|
|
|
|
}
|
2022-06-16 10:29:49 -04:00
|
|
|
this.SubscriptionViewModelBuilder = {
|
|
|
|
getBestSubscription: sinon.stub().yields(null, { type: 'free' }),
|
|
|
|
}
|
2022-06-22 05:34:25 -04:00
|
|
|
this.SurveyHandler = {
|
|
|
|
getSurvey: sinon.stub().yields(null, {}),
|
|
|
|
}
|
2022-12-12 08:09:15 -05:00
|
|
|
this.ProjectAuditLogHandler = {
|
|
|
|
addEntry: sinon.stub().yields(),
|
|
|
|
}
|
2023-12-05 07:59:55 -05:00
|
|
|
this.TutorialHandler = {
|
|
|
|
getInactiveTutorials: sinon.stub().returns([]),
|
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ProjectController = SandboxedModule.require(MODULE_PATH, {
|
2019-05-29 05:21:06 -04:00
|
|
|
requires: {
|
2020-10-05 04:23:21 -04:00
|
|
|
mongodb: { ObjectId },
|
2021-07-07 05:38:56 -04:00
|
|
|
'@overleaf/settings': this.settings,
|
2020-10-30 04:10:50 -04:00
|
|
|
'@overleaf/metrics': this.Metrics,
|
2021-05-21 07:32:07 -04:00
|
|
|
'../SplitTests/SplitTestHandler': this.SplitTestHandler,
|
2024-04-18 09:54:16 -04:00
|
|
|
'../SplitTests/SplitTestSessionHandler': this.SplitTestSessionHandler,
|
2019-05-29 05:21:06 -04:00
|
|
|
'./ProjectDeleter': this.ProjectDeleter,
|
|
|
|
'./ProjectDuplicator': this.ProjectDuplicator,
|
|
|
|
'./ProjectCreationHandler': this.ProjectCreationHandler,
|
|
|
|
'../Editor/EditorController': this.EditorController,
|
2019-12-10 03:10:05 -05:00
|
|
|
'../User/UserController': this.UserController,
|
2019-08-09 05:40:11 -04:00
|
|
|
'./ProjectHelper': this.ProjectHelper,
|
2019-05-29 05:21:06 -04:00
|
|
|
'../Subscription/SubscriptionLocator': this.SubscriptionLocator,
|
|
|
|
'../Subscription/LimitationsManager': this.LimitationsManager,
|
|
|
|
'../Tags/TagsHandler': this.TagsHandler,
|
2019-11-26 08:11:19 -05:00
|
|
|
'../../models/User': { User: this.UserModel },
|
2019-05-29 05:21:06 -04:00
|
|
|
'../Authorization/AuthorizationManager': this.AuthorizationManager,
|
|
|
|
'../InactiveData/InactiveProjectManager': this.InactiveProjectManager,
|
|
|
|
'./ProjectUpdateHandler': this.ProjectUpdateHandler,
|
|
|
|
'./ProjectGetter': this.ProjectGetter,
|
2019-09-30 10:46:15 -04:00
|
|
|
'./ProjectDetailsHandler': this.ProjectDetailsHandler,
|
2021-07-28 04:51:20 -04:00
|
|
|
'../Authentication/SessionManager': this.SessionManager,
|
2019-05-29 05:21:06 -04:00
|
|
|
'../TokenAccess/TokenAccessHandler': this.TokenAccessHandler,
|
2019-10-07 04:30:51 -04:00
|
|
|
'../Collaborators/CollaboratorsGetter': this.CollaboratorsGetter,
|
2019-05-29 05:21:06 -04:00
|
|
|
'./ProjectEntityHandler': this.ProjectEntityHandler,
|
|
|
|
'../../infrastructure/Features': this.Features,
|
2021-10-26 09:31:24 -04:00
|
|
|
'../Subscription/FeaturesUpdater': this.FeaturesUpdater,
|
2019-05-29 05:21:06 -04:00
|
|
|
'../User/UserGetter': this.UserGetter,
|
2022-01-10 05:23:05 -05:00
|
|
|
'../BrandVariations/BrandVariationsHandler':
|
|
|
|
this.BrandVariationsHandler,
|
2019-11-26 08:11:19 -05:00
|
|
|
'../ThirdPartyDataStore/TpdsProjectFlusher': this.TpdsProjectFlusher,
|
2020-07-20 09:23:20 -04:00
|
|
|
'../../models/Project': {},
|
2021-09-10 04:30:01 -04:00
|
|
|
'../Analytics/AnalyticsManager': { recordEventForUser: () => {} },
|
2022-06-16 10:29:49 -04:00
|
|
|
'../Subscription/SubscriptionViewModelBuilder':
|
|
|
|
this.SubscriptionViewModelBuilder,
|
2022-01-04 06:07:10 -05:00
|
|
|
'../Spelling/SpellingHandler': {
|
2022-01-06 05:41:31 -05:00
|
|
|
getUserDictionary: sinon.stub().yields(null, []),
|
2022-01-04 06:07:10 -05:00
|
|
|
},
|
2022-04-27 11:12:04 -04:00
|
|
|
'../Institutions/InstitutionsFeatures': this.InstitutionsFeatures,
|
2022-06-22 05:34:25 -04:00
|
|
|
'../Survey/SurveyHandler': this.SurveyHandler,
|
2022-12-12 08:09:15 -05:00
|
|
|
'./ProjectAuditLogHandler': this.ProjectAuditLogHandler,
|
2023-12-05 07:59:55 -05:00
|
|
|
'../Tutorial/TutorialHandler': this.TutorialHandler,
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
this.projectName = '£12321jkj9ujkljds'
|
|
|
|
this.req = {
|
2021-05-27 05:29:55 -04:00
|
|
|
query: {},
|
2019-05-29 05:21:06 -04:00
|
|
|
params: {
|
2021-04-27 03:52:58 -04:00
|
|
|
Project_id: this.project_id,
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
headers: {},
|
|
|
|
connection: {
|
2021-04-27 03:52:58 -04:00
|
|
|
remoteAddress: '192.170.18.1',
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
session: {
|
2021-04-27 03:52:58 -04:00
|
|
|
user: this.user,
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
body: {
|
2021-04-27 03:52:58 -04:00
|
|
|
projectName: this.projectName,
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
i18n: {
|
2021-04-27 03:52:58 -04:00
|
|
|
translate() {},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
2021-04-27 03:52:58 -04:00
|
|
|
ip: '192.170.18.1',
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
this.res = {
|
2019-05-29 05:21:06 -04:00
|
|
|
locals: {
|
2021-04-27 03:52:58 -04:00
|
|
|
jsPath: 'js path here',
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
2021-04-27 03:52:58 -04:00
|
|
|
setTimeout: sinon.stub(),
|
2019-09-30 10:46:15 -04:00
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('updateProjectSettings', function () {
|
|
|
|
it('should update the name', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.EditorController.renameProject = sinon.stub().callsArg(2)
|
|
|
|
this.req.body = { name: (this.name = 'New name') }
|
|
|
|
this.res.sendStatus = code => {
|
|
|
|
this.EditorController.renameProject
|
|
|
|
.calledWith(this.project_id, this.name)
|
|
|
|
.should.equal(true)
|
|
|
|
code.should.equal(204)
|
2019-09-30 10:46:15 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ProjectController.updateProjectSettings(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should update the compiler', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.EditorController.setCompiler = sinon.stub().callsArg(2)
|
|
|
|
this.req.body = { compiler: (this.compiler = 'pdflatex') }
|
|
|
|
this.res.sendStatus = code => {
|
|
|
|
this.EditorController.setCompiler
|
|
|
|
.calledWith(this.project_id, this.compiler)
|
|
|
|
.should.equal(true)
|
|
|
|
code.should.equal(204)
|
2019-09-30 10:46:15 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ProjectController.updateProjectSettings(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should update the imageName', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.EditorController.setImageName = sinon.stub().callsArg(2)
|
|
|
|
this.req.body = { imageName: (this.imageName = 'texlive-1234.5') }
|
|
|
|
this.res.sendStatus = code => {
|
|
|
|
this.EditorController.setImageName
|
|
|
|
.calledWith(this.project_id, this.imageName)
|
|
|
|
.should.equal(true)
|
|
|
|
code.should.equal(204)
|
2019-09-30 10:46:15 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ProjectController.updateProjectSettings(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should update the spell check language', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.EditorController.setSpellCheckLanguage = sinon.stub().callsArg(2)
|
|
|
|
this.req.body = { spellCheckLanguage: (this.languageCode = 'fr') }
|
|
|
|
this.res.sendStatus = code => {
|
|
|
|
this.EditorController.setSpellCheckLanguage
|
|
|
|
.calledWith(this.project_id, this.languageCode)
|
|
|
|
.should.equal(true)
|
|
|
|
code.should.equal(204)
|
2019-09-30 10:46:15 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ProjectController.updateProjectSettings(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should update the root doc', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.EditorController.setRootDoc = sinon.stub().callsArg(2)
|
|
|
|
this.req.body = { rootDocId: (this.rootDocId = 'root-doc-id') }
|
|
|
|
this.res.sendStatus = code => {
|
|
|
|
this.EditorController.setRootDoc
|
|
|
|
.calledWith(this.project_id, this.rootDocId)
|
|
|
|
.should.equal(true)
|
|
|
|
code.should.equal(204)
|
2019-09-30 10:46:15 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ProjectController.updateProjectSettings(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('updateProjectAdminSettings', function () {
|
|
|
|
it('should update the public access level', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.EditorController.setPublicAccessLevel = sinon.stub().callsArg(2)
|
|
|
|
this.req.body = {
|
2022-12-12 08:09:15 -05:00
|
|
|
publicAccessLevel: 'readOnly',
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
this.res.sendStatus = code => {
|
|
|
|
this.EditorController.setPublicAccessLevel
|
2022-12-12 08:09:15 -05:00
|
|
|
.calledWith(this.project_id, 'readOnly')
|
2019-05-29 05:21:06 -04:00
|
|
|
.should.equal(true)
|
|
|
|
code.should.equal(204)
|
2019-09-30 10:46:15 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ProjectController.updateProjectAdminSettings(this.req, this.res)
|
2019-08-07 10:04:04 -04:00
|
|
|
})
|
2022-12-12 08:09:15 -05:00
|
|
|
|
|
|
|
it('should record the change in the project audit log', function (done) {
|
|
|
|
this.EditorController.setPublicAccessLevel = sinon.stub().callsArg(2)
|
|
|
|
this.req.body = {
|
|
|
|
publicAccessLevel: 'readOnly',
|
|
|
|
}
|
|
|
|
this.res.sendStatus = code => {
|
|
|
|
this.ProjectAuditLogHandler.addEntry
|
2023-10-10 08:10:39 -04:00
|
|
|
.calledWith(
|
|
|
|
this.project_id,
|
|
|
|
'toggle-access-level',
|
|
|
|
this.user._id,
|
|
|
|
this.req.ip,
|
|
|
|
{
|
|
|
|
publicAccessLevel: 'readOnly',
|
|
|
|
status: 'OK',
|
|
|
|
}
|
|
|
|
)
|
2022-12-12 08:09:15 -05:00
|
|
|
.should.equal(true)
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
this.ProjectController.updateProjectAdminSettings(this.req, this.res)
|
|
|
|
})
|
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('deleteProject', function () {
|
|
|
|
it('should call the project deleter', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.res.sendStatus = code => {
|
|
|
|
this.ProjectDeleter.deleteProject
|
|
|
|
.calledWith(this.project_id, {
|
|
|
|
deleterUser: this.user,
|
2021-04-27 03:52:58 -04:00
|
|
|
ipAddress: this.req.ip,
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
.should.equal(true)
|
|
|
|
code.should.equal(200)
|
2019-09-30 10:46:15 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ProjectController.deleteProject(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('restoreProject', function () {
|
|
|
|
it('should tell the project deleter', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.res.sendStatus = code => {
|
|
|
|
this.ProjectDeleter.restoreProject
|
|
|
|
.calledWith(this.project_id)
|
|
|
|
.should.equal(true)
|
|
|
|
code.should.equal(200)
|
2019-09-30 10:46:15 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ProjectController.restoreProject(this.req, this.res)
|
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('cloneProject', function () {
|
|
|
|
it('should call the project duplicator', function (done) {
|
2022-01-17 05:19:53 -05:00
|
|
|
this.res.json = json => {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.ProjectDuplicator.duplicate
|
|
|
|
.calledWith(this.user, this.project_id, this.projectName)
|
|
|
|
.should.equal(true)
|
|
|
|
json.project_id.should.equal(this.project_id)
|
2019-09-30 10:46:15 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ProjectController.cloneProject(this.req, this.res)
|
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('newProject', function () {
|
|
|
|
it('should call the projectCreationHandler with createExampleProject', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.req.body.template = 'example'
|
2022-01-17 05:19:53 -05:00
|
|
|
this.res.json = json => {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.ProjectCreationHandler.createExampleProject
|
|
|
|
.calledWith(this.user._id, this.projectName)
|
|
|
|
.should.equal(true)
|
|
|
|
this.ProjectCreationHandler.createBasicProject.called.should.equal(
|
|
|
|
false
|
|
|
|
)
|
2019-09-30 10:46:15 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ProjectController.newProject(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should call the projectCreationHandler with createBasicProject', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.req.body.template = 'basic'
|
2022-01-17 05:19:53 -05:00
|
|
|
this.res.json = json => {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.ProjectCreationHandler.createExampleProject.called.should.equal(
|
|
|
|
false
|
|
|
|
)
|
|
|
|
this.ProjectCreationHandler.createBasicProject
|
|
|
|
.calledWith(this.user._id, this.projectName)
|
|
|
|
.should.equal(true)
|
2019-09-30 10:46:15 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ProjectController.newProject(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('renameProject', function () {
|
|
|
|
beforeEach(function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.newProjectName = 'my supper great new project'
|
2019-09-30 10:46:15 -04:00
|
|
|
this.req.body.newProjectName = this.newProjectName
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should call the editor controller', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.EditorController.renameProject.callsArgWith(2)
|
|
|
|
this.res.sendStatus = code => {
|
|
|
|
code.should.equal(200)
|
|
|
|
this.EditorController.renameProject
|
|
|
|
.calledWith(this.project_id, this.newProjectName)
|
|
|
|
.should.equal(true)
|
2019-09-30 10:46:15 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ProjectController.renameProject(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should send an error to next() if there is a problem', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
let error
|
|
|
|
this.EditorController.renameProject.callsArgWith(
|
|
|
|
2,
|
|
|
|
(error = new Error('problem'))
|
|
|
|
)
|
|
|
|
const next = e => {
|
|
|
|
e.should.equal(error)
|
2019-09-30 10:46:15 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ProjectController.renameProject(this.req, this.res, next)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('loadEditor', function () {
|
|
|
|
beforeEach(function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.settings.editorIsOpen = true
|
|
|
|
this.project = {
|
|
|
|
name: 'my proj',
|
|
|
|
_id: '213123kjlkj',
|
2021-04-27 03:52:58 -04:00
|
|
|
owner_ref: '59fc84d5fbea77482d436e1b',
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
this.brandedProject = {
|
|
|
|
name: 'my branded proj',
|
|
|
|
_id: '3252332',
|
|
|
|
owner_ref: '59fc84d5fbea77482d436e1b',
|
2021-04-27 03:52:58 -04:00
|
|
|
brandVariationId: '12',
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
this.user = {
|
2021-12-14 08:26:16 -05:00
|
|
|
_id: this.user._id,
|
2019-05-29 05:21:06 -04:00
|
|
|
ace: {
|
|
|
|
fontSize: 'massive',
|
2021-04-27 03:52:58 -04:00
|
|
|
theme: 'sexy',
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
2021-04-21 04:23:46 -04:00
|
|
|
email: 'bob@bob.com',
|
|
|
|
refProviders: {
|
|
|
|
mendeley: { encrypted: 'aaaa' },
|
2021-04-27 03:52:58 -04:00
|
|
|
zotero: { encrypted: 'bbbb' },
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
this.ProjectGetter.getProject.callsArgWith(2, null, this.project)
|
2020-07-16 02:48:02 -04:00
|
|
|
this.UserModel.findById.callsArgWith(2, null, this.user)
|
2019-05-29 05:21:06 -04:00
|
|
|
this.SubscriptionLocator.getUsersSubscription.callsArgWith(1, null, {})
|
|
|
|
this.AuthorizationManager.getPrivilegeLevelForProject.callsArgWith(
|
|
|
|
3,
|
|
|
|
null,
|
|
|
|
'owner'
|
|
|
|
)
|
|
|
|
this.ProjectDeleter.unmarkAsDeletedByExternalSource = sinon.stub()
|
|
|
|
this.InactiveProjectManager.reactivateProjectIfRequired.callsArgWith(1)
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ProjectUpdateHandler.markAsOpened.callsArgWith(1)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should render the project/editor page', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.res.render = (pageName, opts) => {
|
|
|
|
pageName.should.equal('project/editor')
|
2019-09-30 10:46:15 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ProjectController.loadEditor(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should add user', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.res.render = (pageName, opts) => {
|
|
|
|
opts.user.email.should.equal(this.user.email)
|
2019-09-30 10:46:15 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ProjectController.loadEditor(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-21 04:23:46 -04:00
|
|
|
it('should sanitize refProviders', function (done) {
|
|
|
|
this.res.render = (_pageName, opts) => {
|
|
|
|
expect(opts.user.refProviders).to.deep.equal({
|
|
|
|
mendeley: true,
|
2021-04-27 03:52:58 -04:00
|
|
|
zotero: true,
|
2021-04-21 04:23:46 -04:00
|
|
|
})
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
this.ProjectController.loadEditor(this.req, this.res)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should add on userSettings', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.res.render = (pageName, opts) => {
|
|
|
|
opts.userSettings.fontSize.should.equal(this.user.ace.fontSize)
|
|
|
|
opts.userSettings.editorTheme.should.equal(this.user.ace.theme)
|
2019-09-30 10:46:15 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ProjectController.loadEditor(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should add isRestrictedTokenMember', function (done) {
|
2022-09-27 07:23:36 -04:00
|
|
|
this.AuthorizationManager.isRestrictedUser.returns(false)
|
2019-09-18 06:01:13 -04:00
|
|
|
this.res.render = (pageName, opts) => {
|
|
|
|
opts.isRestrictedTokenMember.should.exist
|
|
|
|
opts.isRestrictedTokenMember.should.equal(false)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
return this.ProjectController.loadEditor(this.req, this.res)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should set isRestrictedTokenMember when appropriate', function (done) {
|
2019-10-18 05:32:19 -04:00
|
|
|
this.AuthorizationManager.isRestrictedUser.returns(true)
|
2019-09-18 06:01:13 -04:00
|
|
|
this.res.render = (pageName, opts) => {
|
|
|
|
opts.isRestrictedTokenMember.should.exist
|
|
|
|
opts.isRestrictedTokenMember.should.equal(true)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
return this.ProjectController.loadEditor(this.req, this.res)
|
|
|
|
})
|
|
|
|
|
2023-09-13 07:07:00 -04:00
|
|
|
it('should invoke the session maintenance for logged in user', function (done) {
|
|
|
|
this.res.render = () => {
|
2024-04-18 09:54:16 -04:00
|
|
|
this.SplitTestSessionHandler.sessionMaintenance.should.have.been.calledWith(
|
2023-09-13 07:07:00 -04:00
|
|
|
this.req,
|
|
|
|
this.user
|
|
|
|
)
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
this.ProjectController.loadEditor(this.req, this.res)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should invoke the session maintenance for anonymous user', function (done) {
|
|
|
|
this.SessionManager.getLoggedInUserId.returns(null)
|
|
|
|
this.res.render = () => {
|
2024-04-18 09:54:16 -04:00
|
|
|
this.SplitTestSessionHandler.sessionMaintenance.should.have.been.calledWith(
|
2023-09-13 07:07:00 -04:00
|
|
|
this.req
|
|
|
|
)
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
this.ProjectController.loadEditor(this.req, this.res)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should render the closed page if the editor is closed', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.settings.editorIsOpen = false
|
|
|
|
this.res.render = (pageName, opts) => {
|
|
|
|
pageName.should.equal('general/closed')
|
2019-09-30 10:46:15 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ProjectController.loadEditor(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should not render the page if the project can not be accessed', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.AuthorizationManager.getPrivilegeLevelForProject = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(3, null, null)
|
|
|
|
this.res.sendStatus = (resCode, opts) => {
|
|
|
|
resCode.should.equal(401)
|
2019-09-30 10:46:15 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ProjectController.loadEditor(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should reactivateProjectIfRequired', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.res.render = (pageName, opts) => {
|
|
|
|
this.InactiveProjectManager.reactivateProjectIfRequired
|
|
|
|
.calledWith(this.project_id)
|
|
|
|
.should.equal(true)
|
2019-09-30 10:46:15 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ProjectController.loadEditor(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-12-14 08:26:16 -05:00
|
|
|
it('should mark user as active', function (done) {
|
|
|
|
this.res.render = (pageName, opts) => {
|
|
|
|
expect(this.UserModel.updateOne).to.have.been.calledOnce
|
|
|
|
expect(this.UserModel.updateOne.args[0][0]).to.deep.equal({
|
2023-12-18 05:54:01 -05:00
|
|
|
_id: new ObjectId(this.user._id),
|
2021-12-14 08:26:16 -05:00
|
|
|
})
|
|
|
|
expect(this.UserModel.updateOne.args[0][1].$set.lastActive).to.exist
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
this.ProjectController.loadEditor(this.req, this.res)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should mark project as opened', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.res.render = (pageName, opts) => {
|
|
|
|
this.ProjectUpdateHandler.markAsOpened
|
|
|
|
.calledWith(this.project_id)
|
|
|
|
.should.equal(true)
|
2019-09-30 10:46:15 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ProjectController.loadEditor(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should call the brand variations handler for branded projects', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.ProjectGetter.getProject.callsArgWith(2, null, this.brandedProject)
|
|
|
|
this.res.render = (pageName, opts) => {
|
|
|
|
this.BrandVariationsHandler.getBrandVariationById
|
|
|
|
.calledWith()
|
|
|
|
.should.equal(true)
|
2019-09-30 10:46:15 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ProjectController.loadEditor(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should not call the brand variations handler for unbranded projects', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.res.render = (pageName, opts) => {
|
|
|
|
this.BrandVariationsHandler.getBrandVariationById.called.should.equal(
|
|
|
|
false
|
|
|
|
)
|
2019-09-30 10:46:15 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ProjectController.loadEditor(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should expose the brand variation details as locals for branded projects', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.ProjectGetter.getProject.callsArgWith(2, null, this.brandedProject)
|
|
|
|
this.res.render = (pageName, opts) => {
|
|
|
|
opts.brandVariation.should.deep.equal(this.brandVariationDetails)
|
2019-09-30 10:46:15 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ProjectController.loadEditor(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
2019-11-26 08:11:19 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('flushes the project to TPDS if a flush is pending', function (done) {
|
2019-11-26 08:11:19 -05:00
|
|
|
this.res.render = () => {
|
|
|
|
this.TpdsProjectFlusher.flushProjectToTpdsIfNeeded.should.have.been.calledWith(
|
|
|
|
this.project_id
|
|
|
|
)
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
this.ProjectController.loadEditor(this.req, this.res)
|
|
|
|
})
|
2020-04-02 06:01:41 -04:00
|
|
|
|
2021-10-26 09:31:24 -04:00
|
|
|
it('should refresh the user features if the epoch is outdated', function (done) {
|
|
|
|
this.FeaturesUpdater.featuresEpochIsCurrent = sinon.stub().returns(false)
|
|
|
|
this.res.render = () => {
|
|
|
|
this.FeaturesUpdater.refreshFeatures.should.have.been.calledWith(
|
|
|
|
this.user._id,
|
|
|
|
'load-editor'
|
|
|
|
)
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
this.ProjectController.loadEditor(this.req, this.res)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('wsUrl', function () {
|
2020-04-02 06:01:41 -04:00
|
|
|
function checkLoadEditorWsMetric(metric) {
|
2021-04-14 09:17:21 -04:00
|
|
|
it(`should inc metric ${metric}`, function (done) {
|
2020-04-02 06:01:41 -04:00
|
|
|
this.res.render = () => {
|
|
|
|
this.Metrics.inc.calledWith(metric).should.equal(true)
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
this.ProjectController.loadEditor(this.req, this.res)
|
|
|
|
})
|
|
|
|
}
|
2020-05-26 06:32:05 -04:00
|
|
|
function checkWsFallback(isBeta, isV2) {
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('with ws=fallback', function () {
|
|
|
|
beforeEach(function () {
|
2020-04-02 06:01:41 -04:00
|
|
|
this.req.query = {}
|
|
|
|
this.req.query.ws = 'fallback'
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should unset the wsUrl', function (done) {
|
2020-04-02 06:01:41 -04:00
|
|
|
this.res.render = (pageName, opts) => {
|
|
|
|
;(opts.wsUrl || '/socket.io').should.equal('/socket.io')
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
this.ProjectController.loadEditor(this.req, this.res)
|
|
|
|
})
|
|
|
|
checkLoadEditorWsMetric(
|
2020-05-26 06:32:05 -04:00
|
|
|
`load-editor-ws${isBeta ? '-beta' : ''}${
|
|
|
|
isV2 ? '-v2' : ''
|
|
|
|
}-fallback`
|
2020-04-02 06:01:41 -04:00
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
beforeEach(function () {
|
2020-04-02 06:01:41 -04:00
|
|
|
this.settings.wsUrl = '/other.socket.io'
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should set the custom wsUrl', function (done) {
|
2020-04-02 06:01:41 -04:00
|
|
|
this.res.render = (pageName, opts) => {
|
|
|
|
opts.wsUrl.should.equal('/other.socket.io')
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
this.ProjectController.loadEditor(this.req, this.res)
|
|
|
|
})
|
|
|
|
checkLoadEditorWsMetric('load-editor-ws')
|
|
|
|
checkWsFallback(false)
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('beta program', function () {
|
|
|
|
beforeEach(function () {
|
2020-04-02 06:01:41 -04:00
|
|
|
this.settings.wsUrlBeta = '/beta.socket.io'
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('for a normal user', function () {
|
|
|
|
it('should set the normal custom wsUrl', function (done) {
|
2020-04-02 06:01:41 -04:00
|
|
|
this.res.render = (pageName, opts) => {
|
|
|
|
opts.wsUrl.should.equal('/other.socket.io')
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
this.ProjectController.loadEditor(this.req, this.res)
|
|
|
|
})
|
|
|
|
checkLoadEditorWsMetric('load-editor-ws')
|
|
|
|
checkWsFallback(false)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('for a beta user', function () {
|
|
|
|
beforeEach(function () {
|
2020-04-02 06:01:41 -04:00
|
|
|
this.user.betaProgram = true
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should set the beta wsUrl', function (done) {
|
2020-04-02 06:01:41 -04:00
|
|
|
this.res.render = (pageName, opts) => {
|
|
|
|
opts.wsUrl.should.equal('/beta.socket.io')
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
this.ProjectController.loadEditor(this.req, this.res)
|
|
|
|
})
|
|
|
|
checkLoadEditorWsMetric('load-editor-ws-beta')
|
|
|
|
checkWsFallback(true)
|
|
|
|
})
|
|
|
|
})
|
2020-05-26 06:32:05 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('v2-rollout', function () {
|
|
|
|
beforeEach(function () {
|
2020-05-26 06:32:05 -04:00
|
|
|
this.settings.wsUrlBeta = '/beta.socket.io'
|
|
|
|
this.settings.wsUrlV2 = '/socket.io.v2'
|
|
|
|
})
|
|
|
|
|
|
|
|
function checkNonMatch() {
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should set the normal custom wsUrl', function (done) {
|
2020-05-26 06:32:05 -04:00
|
|
|
this.res.render = (pageName, opts) => {
|
|
|
|
opts.wsUrl.should.equal('/other.socket.io')
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
this.ProjectController.loadEditor(this.req, this.res)
|
|
|
|
})
|
|
|
|
checkLoadEditorWsMetric('load-editor-ws')
|
|
|
|
checkWsFallback(false)
|
|
|
|
}
|
|
|
|
function checkMatch() {
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should set the v2 wsUrl', function (done) {
|
2020-05-26 06:32:05 -04:00
|
|
|
this.res.render = (pageName, opts) => {
|
|
|
|
opts.wsUrl.should.equal('/socket.io.v2')
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
this.ProjectController.loadEditor(this.req, this.res)
|
|
|
|
})
|
|
|
|
checkLoadEditorWsMetric('load-editor-ws-v2')
|
|
|
|
checkWsFallback(false, true)
|
|
|
|
}
|
|
|
|
function checkForBetaUser() {
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('for a beta user', function () {
|
|
|
|
beforeEach(function () {
|
2020-05-26 06:32:05 -04:00
|
|
|
this.user.betaProgram = true
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should set the beta wsUrl', function (done) {
|
2020-05-26 06:32:05 -04:00
|
|
|
this.res.render = (pageName, opts) => {
|
|
|
|
opts.wsUrl.should.equal('/beta.socket.io')
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
this.ProjectController.loadEditor(this.req, this.res)
|
|
|
|
})
|
|
|
|
checkLoadEditorWsMetric('load-editor-ws-beta')
|
|
|
|
checkWsFallback(true)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when the roll out percentage is 0', function () {
|
|
|
|
beforeEach(function () {
|
2020-05-26 06:32:05 -04:00
|
|
|
this.settings.wsUrlV2Percentage = 0
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when the projectId does not match (0)', function () {
|
|
|
|
beforeEach(function () {
|
2020-05-26 06:32:05 -04:00
|
|
|
this.req.params.Project_id = ObjectId.createFromTime(0)
|
|
|
|
})
|
|
|
|
checkNonMatch()
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when the projectId does not match (42)', function () {
|
|
|
|
beforeEach(function () {
|
2020-05-26 06:32:05 -04:00
|
|
|
this.req.params.Project_id = ObjectId.createFromTime(42)
|
|
|
|
})
|
|
|
|
checkNonMatch()
|
|
|
|
})
|
|
|
|
checkForBetaUser()
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when the roll out percentage is 1', function () {
|
|
|
|
beforeEach(function () {
|
2020-05-26 06:32:05 -04:00
|
|
|
this.settings.wsUrlV2Percentage = 1
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when the projectId matches (0)', function () {
|
|
|
|
beforeEach(function () {
|
2020-05-26 06:32:05 -04:00
|
|
|
this.req.params.Project_id = ObjectId.createFromTime(0)
|
|
|
|
})
|
|
|
|
checkMatch()
|
|
|
|
checkForBetaUser()
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when the projectId does not match (1)', function () {
|
|
|
|
beforeEach(function () {
|
2020-05-26 06:32:05 -04:00
|
|
|
this.req.params.Project_id = ObjectId.createFromTime(1)
|
|
|
|
})
|
|
|
|
checkNonMatch()
|
|
|
|
checkForBetaUser()
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when the projectId does not match (42)', function () {
|
|
|
|
beforeEach(function () {
|
2020-05-26 06:32:05 -04:00
|
|
|
this.req.params.Project_id = ObjectId.createFromTime(42)
|
|
|
|
})
|
|
|
|
checkNonMatch()
|
|
|
|
})
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when the roll out percentage is 10', function () {
|
|
|
|
beforeEach(function () {
|
2020-05-26 06:32:05 -04:00
|
|
|
this.settings.wsUrlV2Percentage = 10
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when the projectId matches (0)', function () {
|
|
|
|
beforeEach(function () {
|
2020-05-26 06:32:05 -04:00
|
|
|
this.req.params.Project_id = ObjectId.createFromTime(0)
|
|
|
|
})
|
|
|
|
checkMatch()
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when the projectId matches (9)', function () {
|
|
|
|
beforeEach(function () {
|
2020-05-26 06:32:05 -04:00
|
|
|
this.req.params.Project_id = ObjectId.createFromTime(9)
|
|
|
|
})
|
|
|
|
checkMatch()
|
|
|
|
checkForBetaUser()
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when the projectId does not match (10)', function () {
|
|
|
|
beforeEach(function () {
|
2020-05-26 06:32:05 -04:00
|
|
|
this.req.params.Project_id = ObjectId.createFromTime(10)
|
|
|
|
})
|
|
|
|
checkNonMatch()
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when the projectId does not match (42)', function () {
|
|
|
|
beforeEach(function () {
|
2020-05-26 06:32:05 -04:00
|
|
|
this.req.params.Project_id = ObjectId.createFromTime(42)
|
|
|
|
})
|
|
|
|
checkNonMatch()
|
|
|
|
checkForBetaUser()
|
|
|
|
})
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when the roll out percentage is 100', function () {
|
|
|
|
beforeEach(function () {
|
2020-05-26 06:32:05 -04:00
|
|
|
this.settings.wsUrlV2Percentage = 100
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when the projectId matches (0)', function () {
|
|
|
|
beforeEach(function () {
|
2020-05-26 06:32:05 -04:00
|
|
|
this.req.params.Project_id = ObjectId.createFromTime(0)
|
|
|
|
})
|
|
|
|
checkMatch()
|
|
|
|
checkForBetaUser()
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when the projectId matches (10)', function () {
|
|
|
|
beforeEach(function () {
|
2020-05-26 06:32:05 -04:00
|
|
|
this.req.params.Project_id = ObjectId.createFromTime(10)
|
|
|
|
})
|
|
|
|
checkMatch()
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when the projectId matches (42)', function () {
|
|
|
|
beforeEach(function () {
|
2020-05-26 06:32:05 -04:00
|
|
|
this.req.params.Project_id = ObjectId.createFromTime(42)
|
|
|
|
})
|
|
|
|
checkMatch()
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when the projectId matches (99)', function () {
|
|
|
|
beforeEach(function () {
|
2020-05-26 06:32:05 -04:00
|
|
|
this.req.params.Project_id = ObjectId.createFromTime(99)
|
|
|
|
})
|
|
|
|
checkMatch()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2020-04-02 06:01:41 -04:00
|
|
|
})
|
2021-11-03 09:21:24 -04:00
|
|
|
|
2022-07-26 10:29:54 -04:00
|
|
|
describe('upgrade prompt (on header and share project modal)', function () {
|
2022-04-27 11:12:04 -04:00
|
|
|
beforeEach(function () {
|
2022-07-20 06:52:56 -04:00
|
|
|
// default to saas enabled
|
|
|
|
this.Features.hasFeature.withArgs('saas').returns(true)
|
2022-04-27 11:12:04 -04:00
|
|
|
// default to without a subscription
|
|
|
|
this.SubscriptionLocator.getUsersSubscription = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(1, null, null)
|
|
|
|
})
|
2022-07-20 06:52:56 -04:00
|
|
|
it('should not show without the saas feature', function (done) {
|
|
|
|
this.Features.hasFeature.withArgs('saas').returns(false)
|
|
|
|
this.res.render = (pageName, opts) => {
|
2022-07-26 10:29:54 -04:00
|
|
|
expect(opts.showUpgradePrompt).to.equal(false)
|
2022-07-20 06:52:56 -04:00
|
|
|
done()
|
|
|
|
}
|
|
|
|
this.ProjectController.loadEditor(this.req, this.res)
|
|
|
|
})
|
2022-06-01 09:18:19 -04:00
|
|
|
it('should show for a user without a subscription or only non-paid affiliations', function (done) {
|
|
|
|
this.res.render = (pageName, opts) => {
|
2022-07-26 10:29:54 -04:00
|
|
|
expect(opts.showUpgradePrompt).to.equal(true)
|
2022-06-01 09:18:19 -04:00
|
|
|
done()
|
|
|
|
}
|
|
|
|
this.ProjectController.loadEditor(this.req, this.res)
|
2022-04-27 11:12:04 -04:00
|
|
|
})
|
2022-06-01 09:18:19 -04:00
|
|
|
it('should not show for a user with a personal subscription', function (done) {
|
|
|
|
this.SubscriptionLocator.getUsersSubscription = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(1, null, {})
|
|
|
|
this.res.render = (pageName, opts) => {
|
2022-07-26 10:29:54 -04:00
|
|
|
expect(opts.showUpgradePrompt).to.equal(false)
|
2022-06-01 09:18:19 -04:00
|
|
|
done()
|
|
|
|
}
|
|
|
|
this.ProjectController.loadEditor(this.req, this.res)
|
|
|
|
})
|
|
|
|
it('should not show for a user who is a member of a group subscription', function (done) {
|
|
|
|
this.LimitationsManager.userIsMemberOfGroupSubscription = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(1, null, true)
|
|
|
|
this.res.render = (pageName, opts) => {
|
2022-07-26 10:29:54 -04:00
|
|
|
expect(opts.showUpgradePrompt).to.equal(false)
|
2022-06-01 09:18:19 -04:00
|
|
|
done()
|
|
|
|
}
|
|
|
|
this.ProjectController.loadEditor(this.req, this.res)
|
|
|
|
})
|
|
|
|
it('should not show for a user with an affiliated paid university', function (done) {
|
|
|
|
this.InstitutionsFeatures.hasLicence = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(1, null, true)
|
|
|
|
this.res.render = (pageName, opts) => {
|
2022-07-26 10:29:54 -04:00
|
|
|
expect(opts.showUpgradePrompt).to.equal(false)
|
2022-06-01 09:18:19 -04:00
|
|
|
done()
|
|
|
|
}
|
|
|
|
this.ProjectController.loadEditor(this.req, this.res)
|
2022-04-27 11:12:04 -04:00
|
|
|
})
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('userProjectsJson', function () {
|
|
|
|
beforeEach(function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
const projects = [
|
|
|
|
{
|
|
|
|
archived: true,
|
2019-08-27 06:38:17 -04:00
|
|
|
trashed: true,
|
2019-05-29 05:21:06 -04:00
|
|
|
id: 'a',
|
|
|
|
name: 'A',
|
|
|
|
accessLevel: 'a',
|
2021-04-27 03:52:58 -04:00
|
|
|
somethingElse: 1,
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
archived: false,
|
|
|
|
id: 'b',
|
|
|
|
name: 'B',
|
|
|
|
accessLevel: 'b',
|
2021-04-27 03:52:58 -04:00
|
|
|
somethingElse: 1,
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
archived: false,
|
2019-08-27 06:38:17 -04:00
|
|
|
trashed: true,
|
2019-05-29 05:21:06 -04:00
|
|
|
id: 'c',
|
|
|
|
name: 'C',
|
|
|
|
accessLevel: 'c',
|
2021-04-27 03:52:58 -04:00
|
|
|
somethingElse: 1,
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
archived: false,
|
2019-08-27 06:38:17 -04:00
|
|
|
trashed: false,
|
2019-05-29 05:21:06 -04:00
|
|
|
id: 'd',
|
|
|
|
name: 'D',
|
|
|
|
accessLevel: 'd',
|
2021-04-27 03:52:58 -04:00
|
|
|
somethingElse: 1,
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
]
|
2019-08-09 05:40:11 -04:00
|
|
|
|
2019-08-27 06:38:17 -04:00
|
|
|
this.ProjectHelper.isArchivedOrTrashed
|
2019-08-09 05:40:11 -04:00
|
|
|
.withArgs(projects[0], this.user._id)
|
|
|
|
.returns(true)
|
2019-08-27 06:38:17 -04:00
|
|
|
this.ProjectHelper.isArchivedOrTrashed
|
2019-08-09 05:40:11 -04:00
|
|
|
.withArgs(projects[1], this.user._id)
|
|
|
|
.returns(false)
|
2019-08-27 06:38:17 -04:00
|
|
|
this.ProjectHelper.isArchivedOrTrashed
|
2019-08-09 05:40:11 -04:00
|
|
|
.withArgs(projects[2], this.user._id)
|
2019-08-27 06:38:17 -04:00
|
|
|
.returns(true)
|
|
|
|
this.ProjectHelper.isArchivedOrTrashed
|
2019-08-09 05:40:11 -04:00
|
|
|
.withArgs(projects[3], this.user._id)
|
|
|
|
.returns(false)
|
|
|
|
|
2019-05-29 05:21:06 -04:00
|
|
|
this.ProjectGetter.findAllUsersProjects = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(2, null, [])
|
|
|
|
this.ProjectController._buildProjectList = sinon.stub().returns(projects)
|
2021-07-28 04:51:20 -04:00
|
|
|
this.SessionManager.getLoggedInUserId = sinon
|
2019-05-29 05:21:06 -04:00
|
|
|
.stub()
|
2019-08-09 05:40:11 -04:00
|
|
|
.returns(this.user._id)
|
2019-09-30 10:46:15 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should produce a list of projects', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.res.json = data => {
|
|
|
|
expect(data).to.deep.equal({
|
|
|
|
projects: [
|
|
|
|
{ _id: 'b', name: 'B', accessLevel: 'b' },
|
2021-04-27 03:52:58 -04:00
|
|
|
{ _id: 'd', name: 'D', accessLevel: 'd' },
|
|
|
|
],
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
2019-09-30 10:46:15 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ProjectController.userProjectsJson(this.req, this.res, this.next)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('projectEntitiesJson', function () {
|
|
|
|
beforeEach(function () {
|
2021-07-28 04:51:20 -04:00
|
|
|
this.SessionManager.getLoggedInUserId = sinon.stub().returns('abc')
|
2019-05-29 05:21:06 -04:00
|
|
|
this.req.params = { Project_id: 'abcd' }
|
|
|
|
this.project = { _id: 'abcd' }
|
|
|
|
this.docs = [
|
|
|
|
{ path: '/things/b.txt', doc: true },
|
2021-04-27 03:52:58 -04:00
|
|
|
{ path: '/main.tex', doc: true },
|
2019-05-29 05:21:06 -04:00
|
|
|
]
|
|
|
|
this.files = [{ path: '/things/a.txt' }]
|
|
|
|
this.ProjectGetter.getProject = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(1, null, this.project)
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ProjectEntityHandler.getAllEntitiesFromProject = sinon
|
2019-05-29 05:21:06 -04:00
|
|
|
.stub()
|
2021-12-06 10:27:12 -05:00
|
|
|
.returns({ docs: this.docs, files: this.files })
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should produce a list of entities', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.res.json = data => {
|
|
|
|
expect(data).to.deep.equal({
|
|
|
|
project_id: 'abcd',
|
|
|
|
entities: [
|
|
|
|
{ path: '/main.tex', type: 'doc' },
|
|
|
|
{ path: '/things/a.txt', type: 'file' },
|
2021-04-27 03:52:58 -04:00
|
|
|
{ path: '/things/b.txt', type: 'doc' },
|
|
|
|
],
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
expect(this.ProjectGetter.getProject.callCount).to.equal(1)
|
|
|
|
expect(
|
|
|
|
this.ProjectEntityHandler.getAllEntitiesFromProject.callCount
|
|
|
|
).to.equal(1)
|
2019-09-30 10:46:15 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ProjectController.projectEntitiesJson(this.req, this.res, this.next)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
2023-05-02 04:18:57 -04:00
|
|
|
|
|
|
|
it('should call next with an error if the project file tree is invalid', function (done) {
|
|
|
|
this.ProjectEntityHandler.getAllEntitiesFromProject = sinon
|
|
|
|
.stub()
|
|
|
|
.throws()
|
|
|
|
this.next = err => {
|
|
|
|
expect(err).to.be.an.instanceof(Error)
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
this.ProjectController.projectEntitiesJson(this.req, this.res, this.next)
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('_buildProjectViewModel', function () {
|
|
|
|
beforeEach(function () {
|
2019-09-18 06:01:13 -04:00
|
|
|
this.ProjectHelper.isArchived.returns(false)
|
2019-11-25 10:41:12 -05:00
|
|
|
this.ProjectHelper.isTrashed.returns(false)
|
|
|
|
|
2019-09-18 06:01:13 -04:00
|
|
|
this.project = {
|
|
|
|
_id: 'abcd',
|
|
|
|
name: 'netsenits',
|
|
|
|
lastUpdated: 1,
|
|
|
|
lastUpdatedBy: 2,
|
|
|
|
publicAccesLevel: 'private',
|
|
|
|
archived: false,
|
|
|
|
owner_ref: 'defg',
|
|
|
|
tokens: {
|
|
|
|
readAndWrite: '1abcd',
|
|
|
|
readAndWritePrefix: '1',
|
2021-04-27 03:52:58 -04:00
|
|
|
readOnly: 'neiotsranteoia',
|
|
|
|
},
|
2019-09-18 06:01:13 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('project not being archived or trashed', function () {
|
|
|
|
it('should produce a model of the project', function () {
|
2019-11-25 10:41:12 -05:00
|
|
|
const result = this.ProjectController._buildProjectViewModel(
|
|
|
|
this.project,
|
|
|
|
'readAndWrite',
|
|
|
|
'owner',
|
|
|
|
this.user._id
|
|
|
|
)
|
|
|
|
expect(result).to.exist
|
|
|
|
expect(result).to.be.an('object')
|
|
|
|
expect(result).to.deep.equal({
|
|
|
|
id: 'abcd',
|
|
|
|
name: 'netsenits',
|
|
|
|
lastUpdated: 1,
|
|
|
|
lastUpdatedBy: 2,
|
|
|
|
publicAccessLevel: 'private',
|
|
|
|
accessLevel: 'readAndWrite',
|
|
|
|
source: 'owner',
|
|
|
|
archived: false,
|
|
|
|
trashed: false,
|
|
|
|
owner_ref: 'defg',
|
2021-04-27 03:52:58 -04:00
|
|
|
isV1Project: false,
|
2019-11-25 10:41:12 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('project being simultaneously archived and trashed', function () {
|
|
|
|
beforeEach(function () {
|
2019-11-25 10:41:12 -05:00
|
|
|
this.ProjectHelper.isArchived.returns(true)
|
|
|
|
this.ProjectHelper.isTrashed.returns(true)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should produce a model of the project', function () {
|
2019-11-25 10:41:12 -05:00
|
|
|
const result = this.ProjectController._buildProjectViewModel(
|
|
|
|
this.project,
|
|
|
|
'readAndWrite',
|
|
|
|
'owner',
|
|
|
|
this.user._id
|
|
|
|
)
|
|
|
|
expect(result).to.exist
|
|
|
|
expect(result).to.be.an('object')
|
|
|
|
expect(result).to.deep.equal({
|
|
|
|
id: 'abcd',
|
|
|
|
name: 'netsenits',
|
|
|
|
lastUpdated: 1,
|
|
|
|
lastUpdatedBy: 2,
|
|
|
|
publicAccessLevel: 'private',
|
|
|
|
accessLevel: 'readAndWrite',
|
|
|
|
source: 'owner',
|
|
|
|
archived: true,
|
|
|
|
trashed: false,
|
|
|
|
owner_ref: 'defg',
|
2021-04-27 03:52:58 -04:00
|
|
|
isV1Project: false,
|
2019-11-25 10:41:12 -05:00
|
|
|
})
|
2019-09-18 06:01:13 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when token-read-only access', function () {
|
|
|
|
it('should redact the owner and last-updated data', function () {
|
2019-09-18 06:01:13 -04:00
|
|
|
const result = this.ProjectController._buildProjectViewModel(
|
|
|
|
this.project,
|
|
|
|
'readOnly',
|
|
|
|
'token',
|
|
|
|
this.user._id
|
|
|
|
)
|
|
|
|
expect(result).to.exist
|
2019-11-18 09:37:05 -05:00
|
|
|
expect(result).to.be.an('object')
|
2019-09-18 06:01:13 -04:00
|
|
|
expect(result).to.deep.equal({
|
|
|
|
id: 'abcd',
|
|
|
|
name: 'netsenits',
|
|
|
|
lastUpdated: 1,
|
|
|
|
lastUpdatedBy: null,
|
|
|
|
publicAccessLevel: 'private',
|
|
|
|
accessLevel: 'readOnly',
|
|
|
|
source: 'token',
|
|
|
|
archived: false,
|
2019-11-25 10:41:12 -05:00
|
|
|
trashed: false,
|
2019-09-18 06:01:13 -04:00
|
|
|
owner_ref: null,
|
2021-04-27 03:52:58 -04:00
|
|
|
isV1Project: false,
|
2019-09-18 06:01:13 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('_isInPercentageRollout', function () {
|
|
|
|
before(function () {
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ids = [
|
2019-05-29 05:21:06 -04:00
|
|
|
'5a05cd7621f9fe22be131740',
|
|
|
|
'5a05cd7821f9fe22be131741',
|
|
|
|
'5a05cd7921f9fe22be131742',
|
|
|
|
'5a05cd7a21f9fe22be131743',
|
|
|
|
'5a05cd7b21f9fe22be131744',
|
|
|
|
'5a05cd7c21f9fe22be131745',
|
|
|
|
'5a05cd7d21f9fe22be131746',
|
|
|
|
'5a05cd7e21f9fe22be131747',
|
|
|
|
'5a05cd7f21f9fe22be131748',
|
|
|
|
'5a05cd8021f9fe22be131749',
|
|
|
|
'5a05cd8021f9fe22be13174a',
|
|
|
|
'5a05cd8121f9fe22be13174b',
|
|
|
|
'5a05cd8221f9fe22be13174c',
|
|
|
|
'5a05cd8221f9fe22be13174d',
|
|
|
|
'5a05cd8321f9fe22be13174e',
|
|
|
|
'5a05cd8321f9fe22be13174f',
|
|
|
|
'5a05cd8421f9fe22be131750',
|
|
|
|
'5a05cd8421f9fe22be131751',
|
|
|
|
'5a05cd8421f9fe22be131752',
|
2021-04-27 03:52:58 -04:00
|
|
|
'5a05cd8521f9fe22be131753',
|
2019-09-30 10:46:15 -04:00
|
|
|
]
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should produce the expected results', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
expect(
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ids.map(i =>
|
|
|
|
this.ProjectController._isInPercentageRollout('abcd', i, 50)
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
).to.deep.equal([
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
false,
|
2021-04-27 03:52:58 -04:00
|
|
|
true,
|
2019-05-29 05:21:06 -04:00
|
|
|
])
|
2019-09-30 10:46:15 -04:00
|
|
|
expect(
|
|
|
|
this.ids.map(i =>
|
|
|
|
this.ProjectController._isInPercentageRollout('efgh', i, 50)
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
).to.deep.equal([
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
false,
|
2021-04-27 03:52:58 -04:00
|
|
|
false,
|
2019-05-29 05:21:06 -04:00
|
|
|
])
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|