ProjectControllerTests.js 44 KB

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