ProjectControllerTests.js 44 KB

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