ProjectControllerTests.js 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363
  1. const SandboxedModule = require('sandboxed-module')
  2. const path = require('path')
  3. const sinon = require('sinon')
  4. const { expect } = require('chai')
  5. const { ObjectId } = require('mongodb')
  6. const MODULE_PATH = path.join(
  7. __dirname,
  8. '../../../../app/src/Features/Project/ProjectController'
  9. )
  10. describe('ProjectController', function () {
  11. beforeEach(function () {
  12. this.project_id = new ObjectId('abcdefabcdefabcdefabcdef')
  13. this.user = {
  14. _id: new ObjectId('123456123456123456123456'),
  15. email: 'test@overleaf.com',
  16. first_name: 'bjkdsjfk',
  17. features: {},
  18. emails: [{ email: 'test@overleaf.com' }],
  19. }
  20. this.settings = {
  21. apis: {
  22. chat: {
  23. url: 'chat.com',
  24. },
  25. },
  26. siteUrl: 'https://overleaf.com',
  27. algolia: {},
  28. }
  29. this.brandVariationDetails = {
  30. id: '12',
  31. active: true,
  32. brand_name: 'The journal',
  33. home_url: 'http://www.thejournal.com/',
  34. publish_menu_link_html: 'Submit your paper to the <em>The Journal</em>',
  35. }
  36. this.token = 'some-token'
  37. this.ProjectDeleter = {
  38. promises: {
  39. deleteProject: sinon.stub().resolves(),
  40. restoreProject: sinon.stub().resolves(),
  41. },
  42. findArchivedProjects: sinon.stub(),
  43. }
  44. this.ProjectDuplicator = {
  45. promises: {
  46. duplicate: sinon.stub().resolves({ _id: this.project_id }),
  47. },
  48. }
  49. this.ProjectCreationHandler = {
  50. promises: {
  51. createExampleProject: sinon.stub().resolves({ _id: this.project_id }),
  52. createBasicProject: sinon.stub().resolves({ _id: this.project_id }),
  53. },
  54. }
  55. this.SubscriptionLocator = {
  56. promises: {
  57. getUsersSubscription: sinon.stub().resolves(),
  58. },
  59. }
  60. this.LimitationsManager = {
  61. hasPaidSubscription: sinon.stub(),
  62. promises: {
  63. userIsMemberOfGroupSubscription: sinon.stub().resolves(false),
  64. },
  65. }
  66. this.TagsHandler = {
  67. promises: {
  68. getTagsForProject: sinon.stub().resolves([
  69. {
  70. name: 'test',
  71. project_ids: [this.project_id],
  72. },
  73. ]),
  74. },
  75. addProjectToTags: sinon.stub(),
  76. }
  77. this.UserModel = {
  78. findById: sinon.stub().returns({ exec: sinon.stub().resolves() }),
  79. updateOne: sinon.stub().returns({ exec: sinon.stub().resolves() }),
  80. }
  81. this.AuthorizationManager = {
  82. promises: {
  83. getPrivilegeLevelForProject: sinon.stub(),
  84. },
  85. isRestrictedUser: sinon.stub().returns(false),
  86. }
  87. this.EditorController = {
  88. promises: {
  89. renameProject: sinon.stub().resolves(),
  90. },
  91. }
  92. this.InactiveProjectManager = {
  93. promises: { reactivateProjectIfRequired: sinon.stub() },
  94. }
  95. this.ProjectUpdateHandler = {
  96. promises: {
  97. markAsOpened: sinon.stub().resolves(),
  98. },
  99. }
  100. this.ProjectGetter = {
  101. promises: {
  102. findAllUsersProjects: sinon.stub().resolves(),
  103. getProject: sinon.stub().resolves(),
  104. },
  105. }
  106. this.ProjectHelper = {
  107. isArchived: sinon.stub(),
  108. isTrashed: sinon.stub(),
  109. isArchivedOrTrashed: sinon.stub(),
  110. getAllowedImagesForUser: sinon.stub().returns([]),
  111. }
  112. this.SessionManager = {
  113. getLoggedInUserId: sinon.stub().returns(this.user._id),
  114. getSessionUser: sinon.stub().returns(this.user),
  115. isUserLoggedIn: sinon.stub().returns(true),
  116. }
  117. this.UserController = {
  118. logout: sinon.stub(),
  119. }
  120. this.TokenAccessHandler = {
  121. getRequestToken: sinon.stub().returns(this.token),
  122. }
  123. this.CollaboratorsGetter = {
  124. promises: {
  125. userIsTokenMember: sinon.stub().resolves(false),
  126. isUserInvitedMemberOfProject: sinon.stub().resolves(true),
  127. userIsReadWriteTokenMember: sinon.stub().resolves(false),
  128. isUserInvitedReadWriteMemberOfProject: sinon.stub().resolves(true),
  129. },
  130. }
  131. this.ProjectEntityHandler = {}
  132. this.UserGetter = {
  133. getUserFullEmails: sinon.stub().yields(null, []),
  134. getUser: sinon.stub().resolves({ lastLoginIp: '192.170.18.2' }),
  135. }
  136. this.Features = {
  137. hasFeature: sinon.stub(),
  138. }
  139. this.FeaturesUpdater = {
  140. featuresEpochIsCurrent: sinon.stub().returns(true),
  141. promises: {
  142. refreshFeatures: sinon.stub().resolves(this.user),
  143. },
  144. }
  145. this.BrandVariationsHandler = {
  146. promises: {
  147. getBrandVariationById: sinon
  148. .stub()
  149. .resolves(this.brandVariationDetails),
  150. },
  151. }
  152. this.TpdsProjectFlusher = {
  153. promises: {
  154. flushProjectToTpdsIfNeeded: sinon.stub().resolves(),
  155. },
  156. }
  157. this.Metrics = {
  158. Timer: class {
  159. done() {}
  160. },
  161. inc: sinon.stub(),
  162. }
  163. this.SplitTestHandler = {
  164. promises: {
  165. getAssignment: sinon.stub().resolves({ variant: 'default' }),
  166. getAssignmentForUser: sinon.stub().resolves({ variant: 'default' }),
  167. },
  168. getAssignment: sinon.stub().yields(null, { variant: 'default' }),
  169. }
  170. this.SplitTestSessionHandler = {
  171. promises: {
  172. sessionMaintenance: sinon.stub().resolves(),
  173. },
  174. }
  175. this.InstitutionsFeatures = {
  176. promises: {
  177. hasLicence: sinon.stub().resolves(false),
  178. },
  179. }
  180. this.SubscriptionViewModelBuilder = {
  181. getBestSubscription: sinon.stub().yields(null, { type: 'free' }),
  182. }
  183. this.SurveyHandler = {
  184. getSurvey: sinon.stub().yields(null, {}),
  185. }
  186. this.ProjectAuditLogHandler = {
  187. promises: {
  188. addEntry: sinon.stub().resolves(),
  189. },
  190. }
  191. this.TutorialHandler = {
  192. getInactiveTutorials: sinon.stub().returns([]),
  193. }
  194. this.ProjectController = SandboxedModule.require(MODULE_PATH, {
  195. requires: {
  196. mongodb: { ObjectId },
  197. '@overleaf/settings': this.settings,
  198. '@overleaf/metrics': this.Metrics,
  199. '../SplitTests/SplitTestHandler': this.SplitTestHandler,
  200. '../SplitTests/SplitTestSessionHandler': this.SplitTestSessionHandler,
  201. './ProjectDeleter': this.ProjectDeleter,
  202. './ProjectDuplicator': this.ProjectDuplicator,
  203. './ProjectCreationHandler': this.ProjectCreationHandler,
  204. '../Editor/EditorController': this.EditorController,
  205. '../User/UserController': this.UserController,
  206. './ProjectHelper': this.ProjectHelper,
  207. '../Subscription/SubscriptionLocator': this.SubscriptionLocator,
  208. '../Subscription/LimitationsManager': this.LimitationsManager,
  209. '../Tags/TagsHandler': this.TagsHandler,
  210. '../../models/User': { User: this.UserModel },
  211. '../Authorization/AuthorizationManager': this.AuthorizationManager,
  212. '../InactiveData/InactiveProjectManager': this.InactiveProjectManager,
  213. './ProjectUpdateHandler': this.ProjectUpdateHandler,
  214. './ProjectGetter': this.ProjectGetter,
  215. './ProjectDetailsHandler': this.ProjectDetailsHandler,
  216. '../Authentication/SessionManager': this.SessionManager,
  217. '../TokenAccess/TokenAccessHandler': this.TokenAccessHandler,
  218. '../Collaborators/CollaboratorsGetter': this.CollaboratorsGetter,
  219. './ProjectEntityHandler': this.ProjectEntityHandler,
  220. '../../infrastructure/Features': this.Features,
  221. '../Subscription/FeaturesUpdater': this.FeaturesUpdater,
  222. '../User/UserGetter': this.UserGetter,
  223. '../BrandVariations/BrandVariationsHandler':
  224. this.BrandVariationsHandler,
  225. '../ThirdPartyDataStore/TpdsProjectFlusher': this.TpdsProjectFlusher,
  226. '../../models/Project': {},
  227. '../Analytics/AnalyticsManager': {
  228. recordEventForUserInBackground: () => {},
  229. },
  230. '../Subscription/SubscriptionViewModelBuilder':
  231. this.SubscriptionViewModelBuilder,
  232. '../Spelling/SpellingHandler': {
  233. promises: {
  234. getUserDictionary: sinon.stub().resolves([]),
  235. },
  236. },
  237. '../Institutions/InstitutionsFeatures': this.InstitutionsFeatures,
  238. '../Survey/SurveyHandler': this.SurveyHandler,
  239. './ProjectAuditLogHandler': this.ProjectAuditLogHandler,
  240. '../Tutorial/TutorialHandler': this.TutorialHandler,
  241. '../User/UserUpdater': {
  242. promises: {
  243. updateUser: sinon.stub().resolves(),
  244. },
  245. },
  246. },
  247. })
  248. this.projectName = '£12321jkj9ujkljds'
  249. this.req = {
  250. query: {},
  251. params: {
  252. Project_id: this.project_id,
  253. },
  254. headers: {},
  255. connection: {
  256. remoteAddress: '192.170.18.1',
  257. },
  258. session: {
  259. user: this.user,
  260. },
  261. body: {
  262. projectName: this.projectName,
  263. },
  264. i18n: {
  265. translate() {},
  266. },
  267. ip: '192.170.18.1',
  268. }
  269. this.res = {
  270. locals: {
  271. jsPath: 'js path here',
  272. },
  273. setTimeout: sinon.stub(),
  274. }
  275. })
  276. describe('updateProjectSettings', function () {
  277. it('should update the name', function (done) {
  278. this.EditorController.promises.renameProject = sinon.stub().resolves()
  279. this.req.body = { name: (this.name = 'New name') }
  280. this.res.sendStatus = code => {
  281. this.EditorController.promises.renameProject
  282. .calledWith(this.project_id, this.name)
  283. .should.equal(true)
  284. code.should.equal(204)
  285. done()
  286. }
  287. this.ProjectController.updateProjectSettings(this.req, this.res)
  288. })
  289. it('should update the compiler', function (done) {
  290. this.EditorController.promises.setCompiler = sinon.stub().resolves()
  291. this.req.body = { compiler: (this.compiler = 'pdflatex') }
  292. this.res.sendStatus = code => {
  293. this.EditorController.promises.setCompiler
  294. .calledWith(this.project_id, this.compiler)
  295. .should.equal(true)
  296. code.should.equal(204)
  297. done()
  298. }
  299. this.ProjectController.updateProjectSettings(this.req, this.res)
  300. })
  301. it('should update the imageName', function (done) {
  302. this.EditorController.promises.setImageName = sinon.stub().resolves()
  303. this.req.body = { imageName: (this.imageName = 'texlive-1234.5') }
  304. this.res.sendStatus = code => {
  305. this.EditorController.promises.setImageName
  306. .calledWith(this.project_id, this.imageName)
  307. .should.equal(true)
  308. code.should.equal(204)
  309. done()
  310. }
  311. this.ProjectController.updateProjectSettings(this.req, this.res)
  312. })
  313. it('should update the spell check language', function (done) {
  314. this.EditorController.promises.setSpellCheckLanguage = sinon
  315. .stub()
  316. .resolves()
  317. this.req.body = { spellCheckLanguage: (this.languageCode = 'fr') }
  318. this.res.sendStatus = code => {
  319. this.EditorController.promises.setSpellCheckLanguage
  320. .calledWith(this.project_id, this.languageCode)
  321. .should.equal(true)
  322. code.should.equal(204)
  323. done()
  324. }
  325. this.ProjectController.updateProjectSettings(this.req, this.res)
  326. })
  327. it('should update the root doc', function (done) {
  328. this.EditorController.promises.setRootDoc = sinon.stub().resolves()
  329. this.req.body = { rootDocId: (this.rootDocId = 'root-doc-id') }
  330. this.res.sendStatus = code => {
  331. this.EditorController.promises.setRootDoc
  332. .calledWith(this.project_id, this.rootDocId)
  333. .should.equal(true)
  334. code.should.equal(204)
  335. done()
  336. }
  337. this.ProjectController.updateProjectSettings(this.req, this.res)
  338. })
  339. })
  340. describe('updateProjectAdminSettings', function () {
  341. it('should update the public access level', function (done) {
  342. this.EditorController.promises.setPublicAccessLevel = sinon
  343. .stub()
  344. .resolves()
  345. this.req.body = {
  346. publicAccessLevel: 'readOnly',
  347. }
  348. this.res.sendStatus = code => {
  349. this.EditorController.promises.setPublicAccessLevel
  350. .calledWith(this.project_id, 'readOnly')
  351. .should.equal(true)
  352. code.should.equal(204)
  353. done()
  354. }
  355. this.ProjectController.updateProjectAdminSettings(this.req, this.res)
  356. })
  357. it('should record the change in the project audit log', function (done) {
  358. this.EditorController.promises.setPublicAccessLevel = sinon
  359. .stub()
  360. .resolves()
  361. this.req.body = {
  362. publicAccessLevel: 'readOnly',
  363. }
  364. this.res.sendStatus = code => {
  365. this.ProjectAuditLogHandler.promises.addEntry
  366. .calledWith(
  367. this.project_id,
  368. 'toggle-access-level',
  369. this.user._id,
  370. this.req.ip,
  371. {
  372. publicAccessLevel: 'readOnly',
  373. status: 'OK',
  374. }
  375. )
  376. .should.equal(true)
  377. done()
  378. }
  379. this.ProjectController.updateProjectAdminSettings(this.req, this.res)
  380. })
  381. })
  382. describe('deleteProject', function () {
  383. it('should call the project deleter', function (done) {
  384. this.res.sendStatus = code => {
  385. this.ProjectDeleter.promises.deleteProject
  386. .calledWith(this.project_id, {
  387. deleterUser: this.user,
  388. ipAddress: this.req.ip,
  389. })
  390. .should.equal(true)
  391. code.should.equal(200)
  392. done()
  393. }
  394. this.ProjectController.deleteProject(this.req, this.res)
  395. })
  396. })
  397. describe('restoreProject', function () {
  398. it('should tell the project deleter', function (done) {
  399. this.res.sendStatus = code => {
  400. this.ProjectDeleter.promises.restoreProject
  401. .calledWith(this.project_id)
  402. .should.equal(true)
  403. code.should.equal(200)
  404. done()
  405. }
  406. this.ProjectController.restoreProject(this.req, this.res)
  407. })
  408. })
  409. describe('cloneProject', function () {
  410. it('should call the project duplicator', function (done) {
  411. this.res.json = json => {
  412. this.ProjectDuplicator.promises.duplicate
  413. .calledWith(this.user, this.project_id, this.projectName)
  414. .should.equal(true)
  415. json.project_id.should.equal(this.project_id)
  416. done()
  417. }
  418. this.ProjectController.cloneProject(this.req, this.res)
  419. })
  420. })
  421. describe('newProject', function () {
  422. it('should call the projectCreationHandler with createExampleProject', function (done) {
  423. this.req.body.template = 'example'
  424. this.res.json = json => {
  425. this.ProjectCreationHandler.promises.createExampleProject
  426. .calledWith(this.user._id, this.projectName)
  427. .should.equal(true)
  428. this.ProjectCreationHandler.promises.createBasicProject.called.should.equal(
  429. false
  430. )
  431. done()
  432. }
  433. this.ProjectController.newProject(this.req, this.res)
  434. })
  435. it('should call the projectCreationHandler with createBasicProject', function (done) {
  436. this.req.body.template = 'basic'
  437. this.res.json = json => {
  438. this.ProjectCreationHandler.promises.createExampleProject.called.should.equal(
  439. false
  440. )
  441. this.ProjectCreationHandler.promises.createBasicProject
  442. .calledWith(this.user._id, this.projectName)
  443. .should.equal(true)
  444. done()
  445. }
  446. this.ProjectController.newProject(this.req, this.res)
  447. })
  448. })
  449. describe('renameProject', function () {
  450. beforeEach(function () {
  451. this.newProjectName = 'my supper great new project'
  452. this.req.body.newProjectName = this.newProjectName
  453. })
  454. it('should call the editor controller', function (done) {
  455. this.EditorController.promises.renameProject.resolves()
  456. this.res.sendStatus = code => {
  457. code.should.equal(200)
  458. this.EditorController.promises.renameProject
  459. .calledWith(this.project_id, this.newProjectName)
  460. .should.equal(true)
  461. done()
  462. }
  463. this.ProjectController.renameProject(this.req, this.res)
  464. })
  465. it('should send an error to next() if there is a problem', function (done) {
  466. let error
  467. this.EditorController.promises.renameProject.rejects(
  468. (error = new Error('problem'))
  469. )
  470. const next = e => {
  471. e.should.equal(error)
  472. done()
  473. }
  474. this.ProjectController.renameProject(this.req, this.res, next)
  475. })
  476. })
  477. describe('loadEditor', function () {
  478. beforeEach(function () {
  479. this.settings.editorIsOpen = true
  480. this.project = {
  481. name: 'my proj',
  482. _id: '213123kjlkj',
  483. owner_ref: '59fc84d5fbea77482d436e1b',
  484. }
  485. this.brandedProject = {
  486. name: 'my branded proj',
  487. _id: '3252332',
  488. owner_ref: '59fc84d5fbea77482d436e1b',
  489. brandVariationId: '12',
  490. }
  491. this.user = {
  492. _id: this.user._id,
  493. ace: {
  494. fontSize: 'massive',
  495. theme: 'sexy',
  496. },
  497. email: 'bob@bob.com',
  498. refProviders: {
  499. mendeley: { encrypted: 'aaaa' },
  500. zotero: { encrypted: 'bbbb' },
  501. },
  502. }
  503. this.ProjectGetter.promises.getProject.resolves(this.project)
  504. this.UserModel.findById.returns({
  505. exec: sinon.stub().resolves(this.user),
  506. })
  507. this.SubscriptionLocator.promises.getUsersSubscription.resolves({})
  508. this.AuthorizationManager.promises.getPrivilegeLevelForProject.resolves(
  509. 'owner'
  510. )
  511. this.ProjectDeleter.unmarkAsDeletedByExternalSource = sinon.stub()
  512. this.InactiveProjectManager.promises.reactivateProjectIfRequired.resolves()
  513. this.ProjectUpdateHandler.promises.markAsOpened.resolves()
  514. })
  515. it('should render the project/ide-react page', function (done) {
  516. this.res.render = (pageName, opts) => {
  517. pageName.should.equal('project/ide-react')
  518. done()
  519. }
  520. this.ProjectController.loadEditor(this.req, this.res)
  521. })
  522. it('should add user', function (done) {
  523. this.res.render = (pageName, opts) => {
  524. opts.user.email.should.equal(this.user.email)
  525. done()
  526. }
  527. this.ProjectController.loadEditor(this.req, this.res)
  528. })
  529. it('should sanitize refProviders', function (done) {
  530. this.res.render = (_pageName, opts) => {
  531. expect(opts.user.refProviders).to.deep.equal({
  532. mendeley: true,
  533. zotero: true,
  534. })
  535. done()
  536. }
  537. this.ProjectController.loadEditor(this.req, this.res)
  538. })
  539. it('should add on userSettings', function (done) {
  540. this.res.render = (pageName, opts) => {
  541. opts.userSettings.fontSize.should.equal(this.user.ace.fontSize)
  542. opts.userSettings.editorTheme.should.equal(this.user.ace.theme)
  543. done()
  544. }
  545. this.ProjectController.loadEditor(this.req, this.res)
  546. })
  547. it('should add isRestrictedTokenMember', function (done) {
  548. this.AuthorizationManager.isRestrictedUser.returns(false)
  549. this.res.render = (pageName, opts) => {
  550. opts.isRestrictedTokenMember.should.exist
  551. opts.isRestrictedTokenMember.should.equal(false)
  552. return done()
  553. }
  554. this.ProjectController.loadEditor(this.req, this.res)
  555. })
  556. it('should set isRestrictedTokenMember when appropriate', function (done) {
  557. this.AuthorizationManager.isRestrictedUser.returns(true)
  558. this.res.render = (pageName, opts) => {
  559. opts.isRestrictedTokenMember.should.exist
  560. opts.isRestrictedTokenMember.should.equal(true)
  561. return done()
  562. }
  563. this.ProjectController.loadEditor(this.req, this.res)
  564. })
  565. it('should invoke the session maintenance for logged in user', function (done) {
  566. this.res.render = () => {
  567. this.SplitTestSessionHandler.promises.sessionMaintenance.should.have.been.calledWith(
  568. this.req,
  569. this.user
  570. )
  571. done()
  572. }
  573. this.ProjectController.loadEditor(this.req, this.res)
  574. })
  575. it('should invoke the session maintenance for anonymous user', function (done) {
  576. this.SessionManager.getLoggedInUserId.returns(null)
  577. this.res.render = () => {
  578. this.SplitTestSessionHandler.promises.sessionMaintenance.should.have.been.calledWith(
  579. this.req
  580. )
  581. done()
  582. }
  583. this.ProjectController.loadEditor(this.req, this.res)
  584. })
  585. it('should render the closed page if the editor is closed', function (done) {
  586. this.settings.editorIsOpen = false
  587. this.res.render = (pageName, opts) => {
  588. pageName.should.equal('general/closed')
  589. done()
  590. }
  591. this.ProjectController.loadEditor(this.req, this.res)
  592. })
  593. it('should not render the page if the project can not be accessed', function (done) {
  594. this.AuthorizationManager.promises.getPrivilegeLevelForProject = sinon
  595. .stub()
  596. .resolves(null)
  597. this.res.sendStatus = (resCode, opts) => {
  598. resCode.should.equal(401)
  599. this.AuthorizationManager.promises.getPrivilegeLevelForProject.should.have.been.calledWith(
  600. this.user._id,
  601. this.project_id,
  602. 'some-token'
  603. )
  604. done()
  605. }
  606. this.ProjectController.loadEditor(this.req, this.res)
  607. })
  608. it('should reactivateProjectIfRequired', function (done) {
  609. this.res.render = (pageName, opts) => {
  610. this.InactiveProjectManager.promises.reactivateProjectIfRequired
  611. .calledWith(this.project_id)
  612. .should.equal(true)
  613. done()
  614. }
  615. this.ProjectController.loadEditor(this.req, this.res)
  616. })
  617. it('should mark user as active', function (done) {
  618. this.res.render = (pageName, opts) => {
  619. expect(this.UserModel.updateOne).to.have.been.calledOnce
  620. expect(this.UserModel.updateOne.args[0][0]).to.deep.equal({
  621. _id: new ObjectId(this.user._id),
  622. })
  623. expect(this.UserModel.updateOne.args[0][1].$set.lastActive).to.exist
  624. done()
  625. }
  626. this.ProjectController.loadEditor(this.req, this.res)
  627. })
  628. it('should mark project as opened', function (done) {
  629. this.res.render = (pageName, opts) => {
  630. this.ProjectUpdateHandler.promises.markAsOpened
  631. .calledWith(this.project_id)
  632. .should.equal(true)
  633. done()
  634. }
  635. this.ProjectController.loadEditor(this.req, this.res)
  636. })
  637. it('should call the brand variations handler for branded projects', function (done) {
  638. this.ProjectGetter.promises.getProject.resolves(this.brandedProject)
  639. this.res.render = (pageName, opts) => {
  640. this.BrandVariationsHandler.promises.getBrandVariationById
  641. .calledWith()
  642. .should.equal(true)
  643. done()
  644. }
  645. this.ProjectController.loadEditor(this.req, this.res)
  646. })
  647. it('should not call the brand variations handler for unbranded projects', function (done) {
  648. this.res.render = (pageName, opts) => {
  649. this.BrandVariationsHandler.promises.getBrandVariationById.called.should.equal(
  650. false
  651. )
  652. done()
  653. }
  654. this.ProjectController.loadEditor(this.req, this.res)
  655. })
  656. it('should expose the brand variation details as locals for branded projects', function (done) {
  657. this.ProjectGetter.promises.getProject.resolves(this.brandedProject)
  658. this.res.render = (pageName, opts) => {
  659. opts.brandVariation.should.deep.equal(this.brandVariationDetails)
  660. done()
  661. }
  662. this.ProjectController.loadEditor(this.req, this.res)
  663. })
  664. it('flushes the project to TPDS if a flush is pending', function (done) {
  665. this.res.render = () => {
  666. this.TpdsProjectFlusher.promises.flushProjectToTpdsIfNeeded.should.have.been.calledWith(
  667. this.project_id
  668. )
  669. done()
  670. }
  671. this.ProjectController.loadEditor(this.req, this.res)
  672. })
  673. it('should refresh the user features if the epoch is outdated', function (done) {
  674. this.FeaturesUpdater.featuresEpochIsCurrent = sinon.stub().returns(false)
  675. this.res.render = () => {
  676. this.FeaturesUpdater.promises.refreshFeatures.should.have.been.calledWith(
  677. this.user._id,
  678. 'load-editor'
  679. )
  680. done()
  681. }
  682. this.ProjectController.loadEditor(this.req, this.res)
  683. })
  684. describe('wsUrl', function () {
  685. function checkLoadEditorWsMetric(metric) {
  686. it(`should inc metric ${metric}`, function (done) {
  687. this.res.render = () => {
  688. this.Metrics.inc.calledWith(metric).should.equal(true)
  689. done()
  690. }
  691. this.ProjectController.loadEditor(this.req, this.res)
  692. })
  693. }
  694. function checkWsFallback(isBeta, isV2) {
  695. describe('with ws=fallback', function () {
  696. beforeEach(function () {
  697. this.req.query = {}
  698. this.req.query.ws = 'fallback'
  699. })
  700. it('should unset the wsUrl', function (done) {
  701. this.res.render = (pageName, opts) => {
  702. ;(opts.wsUrl || '/socket.io').should.equal('/socket.io')
  703. done()
  704. }
  705. this.ProjectController.loadEditor(this.req, this.res)
  706. })
  707. checkLoadEditorWsMetric(
  708. `load-editor-ws${isBeta ? '-beta' : ''}${
  709. isV2 ? '-v2' : ''
  710. }-fallback`
  711. )
  712. })
  713. }
  714. beforeEach(function () {
  715. this.settings.wsUrl = '/other.socket.io'
  716. })
  717. it('should set the custom wsUrl', function (done) {
  718. this.res.render = (pageName, opts) => {
  719. opts.wsUrl.should.equal('/other.socket.io')
  720. done()
  721. }
  722. this.ProjectController.loadEditor(this.req, this.res)
  723. })
  724. checkLoadEditorWsMetric('load-editor-ws')
  725. checkWsFallback(false)
  726. describe('beta program', function () {
  727. beforeEach(function () {
  728. this.settings.wsUrlBeta = '/beta.socket.io'
  729. })
  730. describe('for a normal user', function () {
  731. it('should set the normal custom wsUrl', function (done) {
  732. this.res.render = (pageName, opts) => {
  733. opts.wsUrl.should.equal('/other.socket.io')
  734. done()
  735. }
  736. this.ProjectController.loadEditor(this.req, this.res)
  737. })
  738. checkLoadEditorWsMetric('load-editor-ws')
  739. checkWsFallback(false)
  740. })
  741. describe('for a beta user', function () {
  742. beforeEach(function () {
  743. this.user.betaProgram = true
  744. })
  745. it('should set the beta wsUrl', function (done) {
  746. this.res.render = (pageName, opts) => {
  747. opts.wsUrl.should.equal('/beta.socket.io')
  748. done()
  749. }
  750. this.ProjectController.loadEditor(this.req, this.res)
  751. })
  752. checkLoadEditorWsMetric('load-editor-ws-beta')
  753. checkWsFallback(true)
  754. })
  755. })
  756. describe('v2-rollout', function () {
  757. beforeEach(function () {
  758. this.settings.wsUrlBeta = '/beta.socket.io'
  759. this.settings.wsUrlV2 = '/socket.io.v2'
  760. })
  761. function checkNonMatch() {
  762. it('should set the normal custom wsUrl', function (done) {
  763. this.res.render = (pageName, opts) => {
  764. opts.wsUrl.should.equal('/other.socket.io')
  765. done()
  766. }
  767. this.ProjectController.loadEditor(this.req, this.res)
  768. })
  769. checkLoadEditorWsMetric('load-editor-ws')
  770. checkWsFallback(false)
  771. }
  772. function checkMatch() {
  773. it('should set the v2 wsUrl', function (done) {
  774. this.res.render = (pageName, opts) => {
  775. opts.wsUrl.should.equal('/socket.io.v2')
  776. done()
  777. }
  778. this.ProjectController.loadEditor(this.req, this.res)
  779. })
  780. checkLoadEditorWsMetric('load-editor-ws-v2')
  781. checkWsFallback(false, true)
  782. }
  783. function checkForBetaUser() {
  784. describe('for a beta user', function () {
  785. beforeEach(function () {
  786. this.user.betaProgram = true
  787. })
  788. it('should set the beta wsUrl', function (done) {
  789. this.res.render = (pageName, opts) => {
  790. opts.wsUrl.should.equal('/beta.socket.io')
  791. done()
  792. }
  793. this.ProjectController.loadEditor(this.req, this.res)
  794. })
  795. checkLoadEditorWsMetric('load-editor-ws-beta')
  796. checkWsFallback(true)
  797. })
  798. }
  799. describe('when the roll out percentage is 0', function () {
  800. beforeEach(function () {
  801. this.settings.wsUrlV2Percentage = 0
  802. })
  803. describe('when the projectId does not match (0)', function () {
  804. beforeEach(function () {
  805. this.req.params.Project_id = ObjectId.createFromTime(0)
  806. })
  807. checkNonMatch()
  808. })
  809. describe('when the projectId does not match (42)', function () {
  810. beforeEach(function () {
  811. this.req.params.Project_id = ObjectId.createFromTime(42)
  812. })
  813. checkNonMatch()
  814. })
  815. checkForBetaUser()
  816. })
  817. describe('when the roll out percentage is 1', function () {
  818. beforeEach(function () {
  819. this.settings.wsUrlV2Percentage = 1
  820. })
  821. describe('when the projectId matches (0)', function () {
  822. beforeEach(function () {
  823. this.req.params.Project_id = ObjectId.createFromTime(0)
  824. })
  825. checkMatch()
  826. checkForBetaUser()
  827. })
  828. describe('when the projectId does not match (1)', function () {
  829. beforeEach(function () {
  830. this.req.params.Project_id = ObjectId.createFromTime(1)
  831. })
  832. checkNonMatch()
  833. checkForBetaUser()
  834. })
  835. describe('when the projectId does not match (42)', function () {
  836. beforeEach(function () {
  837. this.req.params.Project_id = ObjectId.createFromTime(42)
  838. })
  839. checkNonMatch()
  840. })
  841. })
  842. describe('when the roll out percentage is 10', function () {
  843. beforeEach(function () {
  844. this.settings.wsUrlV2Percentage = 10
  845. })
  846. describe('when the projectId matches (0)', function () {
  847. beforeEach(function () {
  848. this.req.params.Project_id = ObjectId.createFromTime(0)
  849. })
  850. checkMatch()
  851. })
  852. describe('when the projectId matches (9)', function () {
  853. beforeEach(function () {
  854. this.req.params.Project_id = ObjectId.createFromTime(9)
  855. })
  856. checkMatch()
  857. checkForBetaUser()
  858. })
  859. describe('when the projectId does not match (10)', function () {
  860. beforeEach(function () {
  861. this.req.params.Project_id = ObjectId.createFromTime(10)
  862. })
  863. checkNonMatch()
  864. })
  865. describe('when the projectId does not match (42)', function () {
  866. beforeEach(function () {
  867. this.req.params.Project_id = ObjectId.createFromTime(42)
  868. })
  869. checkNonMatch()
  870. checkForBetaUser()
  871. })
  872. })
  873. describe('when the roll out percentage is 100', function () {
  874. beforeEach(function () {
  875. this.settings.wsUrlV2Percentage = 100
  876. })
  877. describe('when the projectId matches (0)', function () {
  878. beforeEach(function () {
  879. this.req.params.Project_id = ObjectId.createFromTime(0)
  880. })
  881. checkMatch()
  882. checkForBetaUser()
  883. })
  884. describe('when the projectId matches (10)', function () {
  885. beforeEach(function () {
  886. this.req.params.Project_id = ObjectId.createFromTime(10)
  887. })
  888. checkMatch()
  889. })
  890. describe('when the projectId matches (42)', function () {
  891. beforeEach(function () {
  892. this.req.params.Project_id = ObjectId.createFromTime(42)
  893. })
  894. checkMatch()
  895. })
  896. describe('when the projectId matches (99)', function () {
  897. beforeEach(function () {
  898. this.req.params.Project_id = ObjectId.createFromTime(99)
  899. })
  900. checkMatch()
  901. })
  902. })
  903. })
  904. })
  905. describe('upgrade prompt (on header and share project modal)', function () {
  906. beforeEach(function () {
  907. // default to saas enabled
  908. this.Features.hasFeature.withArgs('saas').returns(true)
  909. // default to without a subscription
  910. this.SubscriptionLocator.promises.getUsersSubscription = sinon
  911. .stub()
  912. .resolves(null)
  913. })
  914. it('should not show without the saas feature', function (done) {
  915. this.Features.hasFeature.withArgs('saas').returns(false)
  916. this.res.render = (pageName, opts) => {
  917. expect(opts.showUpgradePrompt).to.equal(false)
  918. done()
  919. }
  920. this.ProjectController.loadEditor(this.req, this.res)
  921. })
  922. it('should show for a user without a subscription or only non-paid affiliations', function (done) {
  923. this.res.render = (pageName, opts) => {
  924. expect(opts.showUpgradePrompt).to.equal(true)
  925. done()
  926. }
  927. this.ProjectController.loadEditor(this.req, this.res)
  928. })
  929. it('should not show for a user with a personal subscription', function (done) {
  930. this.SubscriptionLocator.promises.getUsersSubscription = sinon
  931. .stub()
  932. .resolves({})
  933. this.res.render = (pageName, opts) => {
  934. expect(opts.showUpgradePrompt).to.equal(false)
  935. done()
  936. }
  937. this.ProjectController.loadEditor(this.req, this.res)
  938. })
  939. it('should not show for a user who is a member of a group subscription', function (done) {
  940. this.LimitationsManager.promises.userIsMemberOfGroupSubscription = sinon
  941. .stub()
  942. .resolves(true)
  943. this.res.render = (pageName, opts) => {
  944. expect(opts.showUpgradePrompt).to.equal(false)
  945. done()
  946. }
  947. this.ProjectController.loadEditor(this.req, this.res)
  948. })
  949. it('should not show for a user with an affiliated paid university', function (done) {
  950. this.InstitutionsFeatures.promises.hasLicence = sinon
  951. .stub()
  952. .resolves(true)
  953. this.res.render = (pageName, opts) => {
  954. expect(opts.showUpgradePrompt).to.equal(false)
  955. done()
  956. }
  957. this.ProjectController.loadEditor(this.req, this.res)
  958. })
  959. })
  960. describe('link sharing changes active', function () {
  961. beforeEach(function () {
  962. this.SplitTestHandler.promises.getAssignmentForUser.resolves({
  963. variant: 'active',
  964. })
  965. })
  966. describe('when user is a read write token member (and not already a named editor)', function () {
  967. beforeEach(function () {
  968. this.CollaboratorsGetter.promises.userIsTokenMember.resolves(true)
  969. this.CollaboratorsGetter.promises.userIsReadWriteTokenMember.resolves(
  970. true
  971. )
  972. this.CollaboratorsGetter.promises.isUserInvitedReadWriteMemberOfProject.resolves(
  973. false
  974. )
  975. })
  976. it('should redirect to the sharing-updates page', function (done) {
  977. this.res.redirect = url => {
  978. expect(url).to.equal(`/project/${this.project_id}/sharing-updates`)
  979. done()
  980. }
  981. this.ProjectController.loadEditor(this.req, this.res)
  982. })
  983. })
  984. describe('when user is a read write token member but also a named editor', function () {
  985. beforeEach(function () {
  986. this.CollaboratorsGetter.promises.userIsTokenMember.resolves(true)
  987. this.CollaboratorsGetter.promises.userIsReadWriteTokenMember.resolves(
  988. true
  989. )
  990. this.CollaboratorsGetter.promises.isUserInvitedReadWriteMemberOfProject.resolves(
  991. true
  992. )
  993. })
  994. it('should not redirect to the sharing-updates page, and should load the editor', function (done) {
  995. this.res.render = (pageName, opts) => {
  996. done()
  997. }
  998. this.ProjectController.loadEditor(this.req, this.res)
  999. })
  1000. })
  1001. })
  1002. })
  1003. describe('userProjectsJson', function () {
  1004. beforeEach(function (done) {
  1005. const projects = [
  1006. {
  1007. archived: true,
  1008. trashed: true,
  1009. id: 'a',
  1010. name: 'A',
  1011. accessLevel: 'a',
  1012. somethingElse: 1,
  1013. },
  1014. {
  1015. archived: false,
  1016. id: 'b',
  1017. name: 'B',
  1018. accessLevel: 'b',
  1019. somethingElse: 1,
  1020. },
  1021. {
  1022. archived: false,
  1023. trashed: true,
  1024. id: 'c',
  1025. name: 'C',
  1026. accessLevel: 'c',
  1027. somethingElse: 1,
  1028. },
  1029. {
  1030. archived: false,
  1031. trashed: false,
  1032. id: 'd',
  1033. name: 'D',
  1034. accessLevel: 'd',
  1035. somethingElse: 1,
  1036. },
  1037. ]
  1038. this.ProjectHelper.isArchivedOrTrashed
  1039. .withArgs(projects[0], this.user._id)
  1040. .returns(true)
  1041. this.ProjectHelper.isArchivedOrTrashed
  1042. .withArgs(projects[1], this.user._id)
  1043. .returns(false)
  1044. this.ProjectHelper.isArchivedOrTrashed
  1045. .withArgs(projects[2], this.user._id)
  1046. .returns(true)
  1047. this.ProjectHelper.isArchivedOrTrashed
  1048. .withArgs(projects[3], this.user._id)
  1049. .returns(false)
  1050. this.ProjectGetter.promises.findAllUsersProjects = sinon
  1051. .stub()
  1052. .resolves([])
  1053. this.ProjectController._buildProjectList = sinon.stub().returns(projects)
  1054. this.SessionManager.getLoggedInUserId = sinon
  1055. .stub()
  1056. .returns(this.user._id)
  1057. done()
  1058. })
  1059. it('should produce a list of projects', function (done) {
  1060. this.res.json = data => {
  1061. expect(data).to.deep.equal({
  1062. projects: [
  1063. { _id: 'b', name: 'B', accessLevel: 'b' },
  1064. { _id: 'd', name: 'D', accessLevel: 'd' },
  1065. ],
  1066. })
  1067. done()
  1068. }
  1069. this.ProjectController.userProjectsJson(this.req, this.res, this.next)
  1070. })
  1071. })
  1072. describe('projectEntitiesJson', function () {
  1073. beforeEach(function () {
  1074. this.SessionManager.getLoggedInUserId = sinon.stub().returns('abc')
  1075. this.req.params = { Project_id: 'abcd' }
  1076. this.project = { _id: 'abcd' }
  1077. this.docs = [
  1078. { path: '/things/b.txt', doc: true },
  1079. { path: '/main.tex', doc: true },
  1080. ]
  1081. this.files = [{ path: '/things/a.txt' }]
  1082. this.ProjectGetter.promises.getProject = sinon
  1083. .stub()
  1084. .resolves(this.project)
  1085. this.ProjectEntityHandler.getAllEntitiesFromProject = sinon
  1086. .stub()
  1087. .returns({ docs: this.docs, files: this.files })
  1088. })
  1089. it('should produce a list of entities', function (done) {
  1090. this.res.json = data => {
  1091. expect(data).to.deep.equal({
  1092. project_id: 'abcd',
  1093. entities: [
  1094. { path: '/main.tex', type: 'doc' },
  1095. { path: '/things/a.txt', type: 'file' },
  1096. { path: '/things/b.txt', type: 'doc' },
  1097. ],
  1098. })
  1099. expect(this.ProjectGetter.promises.getProject.callCount).to.equal(1)
  1100. expect(
  1101. this.ProjectEntityHandler.getAllEntitiesFromProject.callCount
  1102. ).to.equal(1)
  1103. done()
  1104. }
  1105. this.ProjectController.projectEntitiesJson(this.req, this.res, this.next)
  1106. })
  1107. it('should call next with an error if the project file tree is invalid', function (done) {
  1108. this.ProjectEntityHandler.getAllEntitiesFromProject = sinon
  1109. .stub()
  1110. .throws()
  1111. this.next = err => {
  1112. expect(err).to.be.an.instanceof(Error)
  1113. done()
  1114. }
  1115. this.ProjectController.projectEntitiesJson(this.req, this.res, this.next)
  1116. })
  1117. })
  1118. describe('_buildProjectViewModel', function () {
  1119. beforeEach(function () {
  1120. this.ProjectHelper.isArchived.returns(false)
  1121. this.ProjectHelper.isTrashed.returns(false)
  1122. this.project = {
  1123. _id: 'abcd',
  1124. name: 'netsenits',
  1125. lastUpdated: 1,
  1126. lastUpdatedBy: 2,
  1127. publicAccesLevel: 'private',
  1128. archived: false,
  1129. owner_ref: 'defg',
  1130. tokens: {
  1131. readAndWrite: '1abcd',
  1132. readAndWritePrefix: '1',
  1133. readOnly: 'neiotsranteoia',
  1134. },
  1135. }
  1136. })
  1137. describe('project not being archived or trashed', function () {
  1138. it('should produce a model of the project', function () {
  1139. const result = this.ProjectController._buildProjectViewModel(
  1140. this.project,
  1141. 'readAndWrite',
  1142. 'owner',
  1143. this.user._id
  1144. )
  1145. expect(result).to.exist
  1146. expect(result).to.be.an('object')
  1147. expect(result).to.deep.equal({
  1148. id: 'abcd',
  1149. name: 'netsenits',
  1150. lastUpdated: 1,
  1151. lastUpdatedBy: 2,
  1152. publicAccessLevel: 'private',
  1153. accessLevel: 'readAndWrite',
  1154. source: 'owner',
  1155. archived: false,
  1156. trashed: false,
  1157. owner_ref: 'defg',
  1158. isV1Project: false,
  1159. })
  1160. })
  1161. })
  1162. describe('project being simultaneously archived and trashed', function () {
  1163. beforeEach(function () {
  1164. this.ProjectHelper.isArchived.returns(true)
  1165. this.ProjectHelper.isTrashed.returns(true)
  1166. })
  1167. it('should produce a model of the project', function () {
  1168. const result = this.ProjectController._buildProjectViewModel(
  1169. this.project,
  1170. 'readAndWrite',
  1171. 'owner',
  1172. this.user._id
  1173. )
  1174. expect(result).to.exist
  1175. expect(result).to.be.an('object')
  1176. expect(result).to.deep.equal({
  1177. id: 'abcd',
  1178. name: 'netsenits',
  1179. lastUpdated: 1,
  1180. lastUpdatedBy: 2,
  1181. publicAccessLevel: 'private',
  1182. accessLevel: 'readAndWrite',
  1183. source: 'owner',
  1184. archived: true,
  1185. trashed: false,
  1186. owner_ref: 'defg',
  1187. isV1Project: false,
  1188. })
  1189. })
  1190. })
  1191. describe('when token-read-only access', function () {
  1192. it('should redact the owner and last-updated data', function () {
  1193. const result = this.ProjectController._buildProjectViewModel(
  1194. this.project,
  1195. 'readOnly',
  1196. 'token',
  1197. this.user._id
  1198. )
  1199. expect(result).to.exist
  1200. expect(result).to.be.an('object')
  1201. expect(result).to.deep.equal({
  1202. id: 'abcd',
  1203. name: 'netsenits',
  1204. lastUpdated: 1,
  1205. lastUpdatedBy: null,
  1206. publicAccessLevel: 'private',
  1207. accessLevel: 'readOnly',
  1208. source: 'token',
  1209. archived: false,
  1210. trashed: false,
  1211. owner_ref: null,
  1212. isV1Project: false,
  1213. })
  1214. })
  1215. })
  1216. })
  1217. describe('_isInPercentageRollout', function () {
  1218. before(function () {
  1219. this.ids = [
  1220. '5a05cd7621f9fe22be131740',
  1221. '5a05cd7821f9fe22be131741',
  1222. '5a05cd7921f9fe22be131742',
  1223. '5a05cd7a21f9fe22be131743',
  1224. '5a05cd7b21f9fe22be131744',
  1225. '5a05cd7c21f9fe22be131745',
  1226. '5a05cd7d21f9fe22be131746',
  1227. '5a05cd7e21f9fe22be131747',
  1228. '5a05cd7f21f9fe22be131748',
  1229. '5a05cd8021f9fe22be131749',
  1230. '5a05cd8021f9fe22be13174a',
  1231. '5a05cd8121f9fe22be13174b',
  1232. '5a05cd8221f9fe22be13174c',
  1233. '5a05cd8221f9fe22be13174d',
  1234. '5a05cd8321f9fe22be13174e',
  1235. '5a05cd8321f9fe22be13174f',
  1236. '5a05cd8421f9fe22be131750',
  1237. '5a05cd8421f9fe22be131751',
  1238. '5a05cd8421f9fe22be131752',
  1239. '5a05cd8521f9fe22be131753',
  1240. ]
  1241. })
  1242. it('should produce the expected results', function () {
  1243. expect(
  1244. this.ids.map(i =>
  1245. this.ProjectController._isInPercentageRollout('abcd', i, 50)
  1246. )
  1247. ).to.deep.equal([
  1248. false,
  1249. false,
  1250. false,
  1251. false,
  1252. false,
  1253. false,
  1254. true,
  1255. false,
  1256. true,
  1257. true,
  1258. true,
  1259. true,
  1260. true,
  1261. true,
  1262. false,
  1263. false,
  1264. false,
  1265. true,
  1266. false,
  1267. true,
  1268. ])
  1269. expect(
  1270. this.ids.map(i =>
  1271. this.ProjectController._isInPercentageRollout('efgh', i, 50)
  1272. )
  1273. ).to.deep.equal([
  1274. false,
  1275. false,
  1276. false,
  1277. false,
  1278. true,
  1279. false,
  1280. false,
  1281. true,
  1282. false,
  1283. false,
  1284. true,
  1285. true,
  1286. true,
  1287. false,
  1288. true,
  1289. false,
  1290. true,
  1291. true,
  1292. false,
  1293. false,
  1294. ])
  1295. })
  1296. })
  1297. })