ProjectControllerTests.js 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954
  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 Errors = require('../../../../app/src/Features/Errors/Errors')
  7. const MODULE_PATH = path.join(
  8. __dirname,
  9. '../../../../app/src/Features/Project/ProjectController'
  10. )
  11. describe('ProjectController', function () {
  12. beforeEach(function () {
  13. this.project_id = ObjectId('abcdefabcdefabcdefabcdef')
  14. this.user = {
  15. _id: ObjectId('123456123456123456123456'),
  16. email: 'test@overleaf.com',
  17. first_name: 'bjkdsjfk',
  18. features: {},
  19. emails: [{ email: 'test@overleaf.com' }],
  20. }
  21. this.settings = {
  22. apis: {
  23. chat: {
  24. url: 'chat.com',
  25. },
  26. },
  27. siteUrl: 'https://overleaf.com',
  28. algolia: {},
  29. }
  30. this.brandVariationDetails = {
  31. id: '12',
  32. active: true,
  33. brand_name: 'The journal',
  34. home_url: 'http://www.thejournal.com/',
  35. publish_menu_link_html: 'Submit your paper to the <em>The Journal</em>',
  36. }
  37. this.token = 'some-token'
  38. this.ProjectDeleter = {
  39. deleteProject: sinon.stub().callsArg(2),
  40. restoreProject: sinon.stub().callsArg(1),
  41. findArchivedProjects: sinon.stub(),
  42. }
  43. this.ProjectDuplicator = {
  44. duplicate: sinon.stub().callsArgWith(3, null, { _id: this.project_id }),
  45. }
  46. this.ProjectCreationHandler = {
  47. createExampleProject: sinon
  48. .stub()
  49. .callsArgWith(2, null, { _id: this.project_id }),
  50. createBasicProject: sinon
  51. .stub()
  52. .callsArgWith(2, null, { _id: this.project_id }),
  53. }
  54. this.SubscriptionLocator = { getUsersSubscription: sinon.stub() }
  55. this.LimitationsManager = { hasPaidSubscription: sinon.stub() }
  56. this.TagsHandler = { getAllTags: sinon.stub() }
  57. this.NotificationsHandler = { getUserNotifications: sinon.stub() }
  58. this.UserModel = { findById: sinon.stub() }
  59. this.AuthorizationManager = {
  60. getPrivilegeLevelForProject: sinon.stub(),
  61. isRestrictedUser: sinon.stub().returns(false),
  62. }
  63. this.EditorController = { renameProject: sinon.stub() }
  64. this.InactiveProjectManager = { reactivateProjectIfRequired: sinon.stub() }
  65. this.ProjectUpdateHandler = { markAsOpened: sinon.stub() }
  66. this.ProjectGetter = {
  67. findAllUsersProjects: sinon.stub(),
  68. getProject: sinon.stub(),
  69. }
  70. this.ProjectHelper = {
  71. isArchived: sinon.stub(),
  72. isTrashed: sinon.stub(),
  73. isArchivedOrTrashed: sinon.stub(),
  74. getAllowedImagesForUser: sinon.stub().returns([]),
  75. }
  76. this.SessionManager = {
  77. getLoggedInUser: sinon.stub().callsArgWith(1, null, this.user),
  78. getLoggedInUserId: sinon.stub().returns(this.user._id),
  79. getSessionUser: sinon.stub().returns(this.user),
  80. isUserLoggedIn: sinon.stub().returns(true),
  81. }
  82. this.UserController = {
  83. logout: sinon.stub(),
  84. }
  85. this.TokenAccessHandler = {
  86. getRequestToken: sinon.stub().returns(this.token),
  87. protectTokens: sinon.stub(),
  88. }
  89. this.CollaboratorsGetter = {
  90. userIsTokenMember: sinon.stub().callsArgWith(2, null, false),
  91. }
  92. this.ProjectEntityHandler = {}
  93. this.NotificationBuilder = {
  94. ipMatcherAffiliation: sinon.stub().returns({ create: sinon.stub() }),
  95. }
  96. this.UserGetter = {
  97. getUserFullEmails: sinon.stub().yields(null, []),
  98. getUser: sinon
  99. .stub()
  100. .callsArgWith(2, null, { lastLoginIp: '192.170.18.2' }),
  101. }
  102. this.Features = {
  103. hasFeature: sinon.stub(),
  104. }
  105. this.FeaturesUpdater = {
  106. featuresEpochIsCurrent: sinon.stub().returns(true),
  107. refreshFeatures: sinon.stub().yields(null, this.user),
  108. }
  109. this.BrandVariationsHandler = {
  110. getBrandVariationById: sinon
  111. .stub()
  112. .callsArgWith(1, null, this.brandVariationDetails),
  113. }
  114. this.TpdsProjectFlusher = {
  115. flushProjectToTpdsIfNeeded: sinon.stub().yields(),
  116. }
  117. this.Metrics = {
  118. Timer: class {
  119. done() {}
  120. },
  121. inc: sinon.stub(),
  122. }
  123. this.NewLogsUIHelper = {
  124. getNewLogsUIVariantForUser: sinon
  125. .stub()
  126. .returns({ newLogsUI: false, subvariant: null }),
  127. }
  128. this.SplitTestHandler = {
  129. promises: {
  130. getTestSegmentation: sinon.stub().resolves({ enabled: false }),
  131. },
  132. getTestSegmentation: sinon.stub().yields(null, { enabled: false }),
  133. }
  134. this.SplitTestV2Handler = {
  135. promises: {
  136. getAssignment: sinon.stub().resolves({ variant: 'default' }),
  137. getAssignmentForSession: sinon.stub().resolves({ variant: 'default' }),
  138. assignInLocalsContext: sinon.stub().resolves({ variant: 'default' }),
  139. assignInLocalsContextForSession: sinon
  140. .stub()
  141. .resolves({ variant: 'default' }),
  142. },
  143. getAssignment: sinon.stub().yields(null, { variant: 'default' }),
  144. getAssignmentForSession: sinon
  145. .stub()
  146. .yields(null, { variant: 'default' }),
  147. assignInLocalsContext: sinon.stub().yields(null, { variant: 'default' }),
  148. assignInLocalsContextForSession: sinon
  149. .stub()
  150. .yields(null, { variant: 'default' }),
  151. }
  152. this.ProjectController = SandboxedModule.require(MODULE_PATH, {
  153. requires: {
  154. mongodb: { ObjectId },
  155. '@overleaf/settings': this.settings,
  156. '@overleaf/metrics': this.Metrics,
  157. '../SplitTests/SplitTestHandler': this.SplitTestHandler,
  158. '../SplitTests/SplitTestV2Handler': this.SplitTestV2Handler,
  159. './ProjectDeleter': this.ProjectDeleter,
  160. './ProjectDuplicator': this.ProjectDuplicator,
  161. './ProjectCreationHandler': this.ProjectCreationHandler,
  162. '../Editor/EditorController': this.EditorController,
  163. '../User/UserController': this.UserController,
  164. './ProjectHelper': this.ProjectHelper,
  165. '../Subscription/SubscriptionLocator': this.SubscriptionLocator,
  166. '../Subscription/LimitationsManager': this.LimitationsManager,
  167. '../Tags/TagsHandler': this.TagsHandler,
  168. '../Notifications/NotificationsHandler': this.NotificationsHandler,
  169. '../../models/User': { User: this.UserModel },
  170. '../Authorization/AuthorizationManager': this.AuthorizationManager,
  171. '../InactiveData/InactiveProjectManager': this.InactiveProjectManager,
  172. './ProjectUpdateHandler': this.ProjectUpdateHandler,
  173. './ProjectGetter': this.ProjectGetter,
  174. './ProjectDetailsHandler': this.ProjectDetailsHandler,
  175. '../Authentication/SessionManager': this.SessionManager,
  176. '../TokenAccess/TokenAccessHandler': this.TokenAccessHandler,
  177. '../Collaborators/CollaboratorsGetter': this.CollaboratorsGetter,
  178. './ProjectEntityHandler': this.ProjectEntityHandler,
  179. '../../infrastructure/Features': this.Features,
  180. '../Subscription/FeaturesUpdater': this.FeaturesUpdater,
  181. '../Notifications/NotificationsBuilder': this.NotificationBuilder,
  182. '../User/UserGetter': this.UserGetter,
  183. '../BrandVariations/BrandVariationsHandler': this
  184. .BrandVariationsHandler,
  185. '../ThirdPartyDataStore/TpdsProjectFlusher': this.TpdsProjectFlusher,
  186. '../../models/Project': {},
  187. '../Analytics/AnalyticsManager': { recordEventForUser: () => {} },
  188. '../../infrastructure/Modules': {
  189. hooks: { fire: sinon.stub().yields(null, []) },
  190. },
  191. '../Helpers/NewLogsUI': this.NewLogsUIHelper,
  192. },
  193. })
  194. this.projectName = '£12321jkj9ujkljds'
  195. this.req = {
  196. query: {},
  197. params: {
  198. Project_id: this.project_id,
  199. },
  200. headers: {},
  201. connection: {
  202. remoteAddress: '192.170.18.1',
  203. },
  204. session: {
  205. user: this.user,
  206. },
  207. body: {
  208. projectName: this.projectName,
  209. },
  210. i18n: {
  211. translate() {},
  212. },
  213. ip: '192.170.18.1',
  214. }
  215. this.res = {
  216. locals: {
  217. jsPath: 'js path here',
  218. },
  219. setTimeout: sinon.stub(),
  220. }
  221. })
  222. describe('updateProjectSettings', function () {
  223. it('should update the name', function (done) {
  224. this.EditorController.renameProject = sinon.stub().callsArg(2)
  225. this.req.body = { name: (this.name = 'New name') }
  226. this.res.sendStatus = code => {
  227. this.EditorController.renameProject
  228. .calledWith(this.project_id, this.name)
  229. .should.equal(true)
  230. code.should.equal(204)
  231. done()
  232. }
  233. this.ProjectController.updateProjectSettings(this.req, this.res)
  234. })
  235. it('should update the compiler', function (done) {
  236. this.EditorController.setCompiler = sinon.stub().callsArg(2)
  237. this.req.body = { compiler: (this.compiler = 'pdflatex') }
  238. this.res.sendStatus = code => {
  239. this.EditorController.setCompiler
  240. .calledWith(this.project_id, this.compiler)
  241. .should.equal(true)
  242. code.should.equal(204)
  243. done()
  244. }
  245. this.ProjectController.updateProjectSettings(this.req, this.res)
  246. })
  247. it('should update the imageName', function (done) {
  248. this.EditorController.setImageName = sinon.stub().callsArg(2)
  249. this.req.body = { imageName: (this.imageName = 'texlive-1234.5') }
  250. this.res.sendStatus = code => {
  251. this.EditorController.setImageName
  252. .calledWith(this.project_id, this.imageName)
  253. .should.equal(true)
  254. code.should.equal(204)
  255. done()
  256. }
  257. this.ProjectController.updateProjectSettings(this.req, this.res)
  258. })
  259. it('should update the spell check language', function (done) {
  260. this.EditorController.setSpellCheckLanguage = sinon.stub().callsArg(2)
  261. this.req.body = { spellCheckLanguage: (this.languageCode = 'fr') }
  262. this.res.sendStatus = code => {
  263. this.EditorController.setSpellCheckLanguage
  264. .calledWith(this.project_id, this.languageCode)
  265. .should.equal(true)
  266. code.should.equal(204)
  267. done()
  268. }
  269. this.ProjectController.updateProjectSettings(this.req, this.res)
  270. })
  271. it('should update the root doc', function (done) {
  272. this.EditorController.setRootDoc = sinon.stub().callsArg(2)
  273. this.req.body = { rootDocId: (this.rootDocId = 'root-doc-id') }
  274. this.res.sendStatus = code => {
  275. this.EditorController.setRootDoc
  276. .calledWith(this.project_id, this.rootDocId)
  277. .should.equal(true)
  278. code.should.equal(204)
  279. done()
  280. }
  281. this.ProjectController.updateProjectSettings(this.req, this.res)
  282. })
  283. })
  284. describe('updateProjectAdminSettings', function () {
  285. it('should update the public access level', function (done) {
  286. this.EditorController.setPublicAccessLevel = sinon.stub().callsArg(2)
  287. this.req.body = {
  288. publicAccessLevel: (this.publicAccessLevel = 'readonly'),
  289. }
  290. this.res.sendStatus = code => {
  291. this.EditorController.setPublicAccessLevel
  292. .calledWith(this.project_id, this.publicAccessLevel)
  293. .should.equal(true)
  294. code.should.equal(204)
  295. done()
  296. }
  297. this.ProjectController.updateProjectAdminSettings(this.req, this.res)
  298. })
  299. })
  300. describe('deleteProject', function () {
  301. it('should call the project deleter', function (done) {
  302. this.res.sendStatus = code => {
  303. this.ProjectDeleter.deleteProject
  304. .calledWith(this.project_id, {
  305. deleterUser: this.user,
  306. ipAddress: this.req.ip,
  307. })
  308. .should.equal(true)
  309. code.should.equal(200)
  310. done()
  311. }
  312. this.ProjectController.deleteProject(this.req, this.res)
  313. })
  314. })
  315. describe('restoreProject', function () {
  316. it('should tell the project deleter', function (done) {
  317. this.res.sendStatus = code => {
  318. this.ProjectDeleter.restoreProject
  319. .calledWith(this.project_id)
  320. .should.equal(true)
  321. code.should.equal(200)
  322. done()
  323. }
  324. this.ProjectController.restoreProject(this.req, this.res)
  325. })
  326. })
  327. describe('cloneProject', function () {
  328. it('should call the project duplicator', function (done) {
  329. this.res.send = json => {
  330. this.ProjectDuplicator.duplicate
  331. .calledWith(this.user, this.project_id, this.projectName)
  332. .should.equal(true)
  333. json.project_id.should.equal(this.project_id)
  334. done()
  335. }
  336. this.ProjectController.cloneProject(this.req, this.res)
  337. })
  338. })
  339. describe('newProject', function () {
  340. it('should call the projectCreationHandler with createExampleProject', function (done) {
  341. this.req.body.template = 'example'
  342. this.res.send = json => {
  343. this.ProjectCreationHandler.createExampleProject
  344. .calledWith(this.user._id, this.projectName)
  345. .should.equal(true)
  346. this.ProjectCreationHandler.createBasicProject.called.should.equal(
  347. false
  348. )
  349. done()
  350. }
  351. this.ProjectController.newProject(this.req, this.res)
  352. })
  353. it('should call the projectCreationHandler with createBasicProject', function (done) {
  354. this.req.body.template = 'basic'
  355. this.res.send = json => {
  356. this.ProjectCreationHandler.createExampleProject.called.should.equal(
  357. false
  358. )
  359. this.ProjectCreationHandler.createBasicProject
  360. .calledWith(this.user._id, this.projectName)
  361. .should.equal(true)
  362. done()
  363. }
  364. this.ProjectController.newProject(this.req, this.res)
  365. })
  366. })
  367. describe('projectListPage', function () {
  368. beforeEach(function () {
  369. this.tags = [
  370. { name: 1, project_ids: ['1', '2', '3'] },
  371. { name: 2, project_ids: ['a', '1'] },
  372. { name: 3, project_ids: ['a', 'b', 'c', 'd'] },
  373. ]
  374. this.notifications = [
  375. {
  376. _id: '1',
  377. user_id: '2',
  378. templateKey: '3',
  379. messageOpts: '4',
  380. key: '5',
  381. },
  382. ]
  383. this.projects = [
  384. { _id: 1, lastUpdated: 1, owner_ref: 'user-1' },
  385. {
  386. _id: 2,
  387. lastUpdated: 2,
  388. owner_ref: 'user-2',
  389. lastUpdatedBy: 'user-1',
  390. },
  391. ]
  392. this.collabertions = [{ _id: 5, lastUpdated: 5, owner_ref: 'user-1' }]
  393. this.readOnly = [{ _id: 3, lastUpdated: 3, owner_ref: 'user-1' }]
  394. this.tokenReadAndWrite = [{ _id: 6, lastUpdated: 5, owner_ref: 'user-4' }]
  395. this.tokenReadOnly = [{ _id: 7, lastUpdated: 4, owner_ref: 'user-5' }]
  396. this.allProjects = {
  397. owned: this.projects,
  398. readAndWrite: this.collabertions,
  399. readOnly: this.readOnly,
  400. tokenReadAndWrite: this.tokenReadAndWrite,
  401. tokenReadOnly: this.tokenReadOnly,
  402. }
  403. this.users = {
  404. 'user-1': {
  405. first_name: 'James',
  406. },
  407. 'user-2': {
  408. first_name: 'Henry',
  409. },
  410. }
  411. this.users[this.user._id] = this.user // Owner
  412. this.UserModel.findById = (id, fields, callback) => {
  413. callback(null, this.users[id])
  414. }
  415. this.UserGetter.getUser = (id, fields, callback) => {
  416. callback(null, this.users[id])
  417. }
  418. this.LimitationsManager.hasPaidSubscription.callsArgWith(1, null, false)
  419. this.TagsHandler.getAllTags.callsArgWith(1, null, this.tags)
  420. this.NotificationsHandler.getUserNotifications = sinon
  421. .stub()
  422. .callsArgWith(1, null, this.notifications, {})
  423. this.ProjectGetter.findAllUsersProjects.callsArgWith(
  424. 2,
  425. null,
  426. this.allProjects
  427. )
  428. })
  429. it('should render the project/list page', function (done) {
  430. this.res.render = (pageName, opts) => {
  431. pageName.should.equal('project/list')
  432. done()
  433. }
  434. this.ProjectController.projectListPage(this.req, this.res)
  435. })
  436. it('should send the tags', function (done) {
  437. this.res.render = (pageName, opts) => {
  438. opts.tags.length.should.equal(this.tags.length)
  439. done()
  440. }
  441. this.ProjectController.projectListPage(this.req, this.res)
  442. })
  443. it('should create trigger ip matcher notifications', function (done) {
  444. this.settings.overleaf = true
  445. this.res.render = (pageName, opts) => {
  446. this.NotificationBuilder.ipMatcherAffiliation.called.should.equal(true)
  447. done()
  448. }
  449. this.ProjectController.projectListPage(this.req, this.res)
  450. })
  451. it('should send the projects', function (done) {
  452. this.res.render = (pageName, opts) => {
  453. opts.projects.length.should.equal(
  454. this.projects.length +
  455. this.collabertions.length +
  456. this.readOnly.length +
  457. this.tokenReadAndWrite.length +
  458. this.tokenReadOnly.length
  459. )
  460. done()
  461. }
  462. this.ProjectController.projectListPage(this.req, this.res)
  463. })
  464. it('should send the user', function (done) {
  465. this.res.render = (pageName, opts) => {
  466. opts.user.should.deep.equal(this.user)
  467. done()
  468. }
  469. this.ProjectController.projectListPage(this.req, this.res)
  470. })
  471. it('should inject the users', function (done) {
  472. this.res.render = (pageName, opts) => {
  473. opts.projects[0].owner.should.equal(
  474. this.users[this.projects[0].owner_ref]
  475. )
  476. opts.projects[1].owner.should.equal(
  477. this.users[this.projects[1].owner_ref]
  478. )
  479. opts.projects[1].lastUpdatedBy.should.equal(
  480. this.users[this.projects[1].lastUpdatedBy]
  481. )
  482. done()
  483. }
  484. this.ProjectController.projectListPage(this.req, this.res)
  485. })
  486. it('should send hasSubscription == false when no subscription', function (done) {
  487. this.res.render = (pageName, opts) => {
  488. opts.hasSubscription.should.equal(false)
  489. done()
  490. }
  491. this.ProjectController.projectListPage(this.req, this.res)
  492. })
  493. it('should send hasSubscription == true when there is a subscription', function (done) {
  494. this.LimitationsManager.hasPaidSubscription = sinon
  495. .stub()
  496. .callsArgWith(1, null, true)
  497. this.res.render = (pageName, opts) => {
  498. opts.hasSubscription.should.equal(true)
  499. done()
  500. }
  501. this.ProjectController.projectListPage(this.req, this.res)
  502. })
  503. describe('front widget', function (done) {
  504. beforeEach(function () {
  505. this.settings.overleaf = {
  506. front_chat_widget_room_id: 'chat-room-id',
  507. }
  508. })
  509. it('should show for paid users', function (done) {
  510. this.user.features.github = true
  511. this.user.features.dropbox = true
  512. this.res.render = (pageName, opts) => {
  513. opts.frontChatWidgetRoomId.should.equal(
  514. this.settings.overleaf.front_chat_widget_room_id
  515. )
  516. done()
  517. }
  518. this.ProjectController.projectListPage(this.req, this.res)
  519. })
  520. it('should show for sample users', function (done) {
  521. this.user._id = ObjectId('588f3ddae8ebc1bac07c9f00') // last two digits
  522. this.res.render = (pageName, opts) => {
  523. opts.frontChatWidgetRoomId.should.equal(
  524. this.settings.overleaf.front_chat_widget_room_id
  525. )
  526. done()
  527. }
  528. this.ProjectController.projectListPage(this.req, this.res)
  529. })
  530. it('should not show for non sample users', function (done) {
  531. this.user._id = ObjectId('588f3ddae8ebc1bac07c9fff') // last two digits
  532. this.res.render = (pageName, opts) => {
  533. expect(opts.frontChatWidgetRoomId).to.equal(undefined)
  534. done()
  535. }
  536. this.ProjectController.projectListPage(this.req, this.res)
  537. })
  538. })
  539. describe('With Institution SSO feature', function () {
  540. beforeEach(function (done) {
  541. this.institutionEmail = 'test@overleaf.com'
  542. this.institutionName = 'Overleaf'
  543. this.Features.hasFeature.withArgs('saml').returns(true)
  544. this.Features.hasFeature.withArgs('affiliations').returns(true)
  545. this.Features.hasFeature.withArgs('overleaf-integration').returns(true)
  546. done()
  547. })
  548. it('should show institution SSO available notification for confirmed domains', function () {
  549. this.UserGetter.getUserFullEmails.yields(null, [
  550. {
  551. email: 'test@overleaf.com',
  552. affiliation: {
  553. institution: {
  554. id: 1,
  555. confirmed: true,
  556. name: 'Overleaf',
  557. ssoBeta: false,
  558. ssoEnabled: true,
  559. },
  560. },
  561. },
  562. ])
  563. this.res.render = (pageName, opts) => {
  564. expect(opts.notificationsInstitution).to.deep.include({
  565. email: this.institutionEmail,
  566. institutionId: 1,
  567. institutionName: this.institutionName,
  568. templateKey: 'notification_institution_sso_available',
  569. })
  570. }
  571. this.ProjectController.projectListPage(this.req, this.res)
  572. })
  573. it('should show a linked notification', function () {
  574. this.req.session.saml = {
  575. institutionEmail: this.institutionEmail,
  576. linked: {
  577. hasEntitlement: false,
  578. universityName: this.institutionName,
  579. },
  580. }
  581. this.res.render = (pageName, opts) => {
  582. expect(opts.notificationsInstitution).to.deep.include({
  583. email: this.institutionEmail,
  584. institutionName: this.institutionName,
  585. templateKey: 'notification_institution_sso_linked',
  586. })
  587. }
  588. this.ProjectController.projectListPage(this.req, this.res)
  589. })
  590. it('should show a linked another email notification', function () {
  591. // when they request to link an email but the institution returns
  592. // a different email
  593. this.res.render = (pageName, opts) => {
  594. expect(opts.notificationsInstitution).to.deep.include({
  595. institutionEmail: this.institutionEmail,
  596. requestedEmail: 'requested@overleaf.com',
  597. templateKey: 'notification_institution_sso_non_canonical',
  598. })
  599. }
  600. this.req.session.saml = {
  601. emailNonCanonical: this.institutionEmail,
  602. institutionEmail: this.institutionEmail,
  603. requestedEmail: 'requested@overleaf.com',
  604. linked: {
  605. hasEntitlement: false,
  606. universityName: this.institutionName,
  607. },
  608. }
  609. this.ProjectController.projectListPage(this.req, this.res)
  610. })
  611. it('should show a notification when intent was to register via SSO but account existed', function () {
  612. this.res.render = (pageName, opts) => {
  613. expect(opts.notificationsInstitution).to.deep.include({
  614. email: this.institutionEmail,
  615. templateKey: 'notification_institution_sso_already_registered',
  616. })
  617. }
  618. this.req.session.saml = {
  619. institutionEmail: this.institutionEmail,
  620. linked: {
  621. hasEntitlement: false,
  622. universityName: 'Overleaf',
  623. },
  624. registerIntercept: {
  625. id: 1,
  626. name: 'Example University',
  627. },
  628. }
  629. this.ProjectController.projectListPage(this.req, this.res)
  630. })
  631. it('should not show a register notification if the flow was abandoned', function () {
  632. // could initially start to register with an SSO email and then
  633. // abandon flow and login with an existing non-institution SSO email
  634. this.res.render = (pageName, opts) => {
  635. expect(opts.notificationsInstitution).to.deep.not.include({
  636. email: 'test@overleaf.com',
  637. templateKey: 'notification_institution_sso_already_registered',
  638. })
  639. }
  640. this.req.session.saml = {
  641. registerIntercept: {
  642. id: 1,
  643. name: 'Example University',
  644. },
  645. }
  646. this.ProjectController.projectListPage(this.req, this.res)
  647. })
  648. it('should show error notification', function () {
  649. this.res.render = (pageName, opts) => {
  650. expect(opts.notificationsInstitution.length).to.equal(1)
  651. expect(opts.notificationsInstitution[0].templateKey).to.equal(
  652. 'notification_institution_sso_error'
  653. )
  654. expect(opts.notificationsInstitution[0].error).to.be.instanceof(
  655. Errors.SAMLAlreadyLinkedError
  656. )
  657. }
  658. this.req.session.saml = {
  659. institutionEmail: this.institutionEmail,
  660. error: new Errors.SAMLAlreadyLinkedError(),
  661. }
  662. this.ProjectController.projectListPage(this.req, this.res)
  663. })
  664. describe('for an unconfirmed domain for an SSO institution', function () {
  665. beforeEach(function (done) {
  666. this.UserGetter.getUserFullEmails.yields(null, [
  667. {
  668. email: 'test@overleaf-uncofirmed.com',
  669. affiliation: {
  670. institution: {
  671. id: 1,
  672. confirmed: false,
  673. name: 'Overleaf',
  674. ssoBeta: false,
  675. ssoEnabled: true,
  676. },
  677. },
  678. },
  679. ])
  680. done()
  681. })
  682. it('should not show institution SSO available notification', function () {
  683. this.res.render = (pageName, opts) => {
  684. expect(opts.notificationsInstitution.length).to.equal(0)
  685. }
  686. this.ProjectController.projectListPage(this.req, this.res)
  687. })
  688. })
  689. describe('when linking/logging in initiated on institution side', function () {
  690. it('should not show a linked another email notification', function () {
  691. // this is only used when initated on Overleaf,
  692. // because we keep track of the requested email they tried to link
  693. this.res.render = (pageName, opts) => {
  694. expect(opts.notificationsInstitution).to.not.deep.include({
  695. institutionEmail: this.institutionEmail,
  696. requestedEmail: undefined,
  697. templateKey: 'notification_institution_sso_non_canonical',
  698. })
  699. }
  700. this.req.session.saml = {
  701. emailNonCanonical: this.institutionEmail,
  702. institutionEmail: this.institutionEmail,
  703. linked: {
  704. hasEntitlement: false,
  705. universityName: this.institutionName,
  706. },
  707. }
  708. this.ProjectController.projectListPage(this.req, this.res)
  709. })
  710. })
  711. describe('Institution with SSO beta testable', function () {
  712. beforeEach(function (done) {
  713. this.UserGetter.getUserFullEmails.yields(null, [
  714. {
  715. email: 'beta@beta.com',
  716. affiliation: {
  717. institution: {
  718. id: 2,
  719. confirmed: true,
  720. name: 'Beta University',
  721. ssoBeta: true,
  722. ssoEnabled: false,
  723. },
  724. },
  725. },
  726. ])
  727. done()
  728. })
  729. it('should show institution SSO available notification when on a beta testing session', function () {
  730. this.req.session.samlBeta = true
  731. this.res.render = (pageName, opts) => {
  732. expect(opts.notificationsInstitution).to.deep.include({
  733. email: 'beta@beta.com',
  734. institutionId: 2,
  735. institutionName: 'Beta University',
  736. templateKey: 'notification_institution_sso_available',
  737. })
  738. }
  739. this.ProjectController.projectListPage(this.req, this.res)
  740. })
  741. it('should not show institution SSO available notification when not on a beta testing session', function () {
  742. this.req.session.samlBeta = false
  743. this.res.render = (pageName, opts) => {
  744. expect(opts.notificationsInstitution).to.deep.not.include({
  745. email: 'test@overleaf.com',
  746. institutionId: 1,
  747. institutionName: 'Overleaf',
  748. templateKey: 'notification_institution_sso_available',
  749. })
  750. }
  751. this.ProjectController.projectListPage(this.req, this.res)
  752. })
  753. })
  754. })
  755. describe('Without Institution SSO feature', function () {
  756. beforeEach(function (done) {
  757. this.Features.hasFeature.withArgs('saml').returns(false)
  758. done()
  759. })
  760. it('should not show institution sso available notification', function () {
  761. this.res.render = (pageName, opts) => {
  762. expect(opts.notificationsInstitution).to.deep.not.include({
  763. email: 'test@overleaf.com',
  764. institutionId: 1,
  765. institutionName: 'Overleaf',
  766. templateKey: 'notification_institution_sso_available',
  767. })
  768. }
  769. this.ProjectController.projectListPage(this.req, this.res)
  770. })
  771. })
  772. })
  773. describe('projectListPage with duplicate projects', function () {
  774. beforeEach(function () {
  775. this.tags = [
  776. { name: 1, project_ids: ['1', '2', '3'] },
  777. { name: 2, project_ids: ['a', '1'] },
  778. { name: 3, project_ids: ['a', 'b', 'c', 'd'] },
  779. ]
  780. this.notifications = [
  781. {
  782. _id: '1',
  783. user_id: '2',
  784. templateKey: '3',
  785. messageOpts: '4',
  786. key: '5',
  787. },
  788. ]
  789. this.projects = [
  790. { _id: 1, lastUpdated: 1, owner_ref: 'user-1' },
  791. { _id: 2, lastUpdated: 2, owner_ref: 'user-2' },
  792. ]
  793. this.collabertions = [{ _id: 5, lastUpdated: 5, owner_ref: 'user-1' }]
  794. this.readOnly = [{ _id: 3, lastUpdated: 3, owner_ref: 'user-1' }]
  795. this.tokenReadAndWrite = [{ _id: 6, lastUpdated: 5, owner_ref: 'user-4' }]
  796. this.tokenReadOnly = [
  797. { _id: 6, lastUpdated: 5, owner_ref: 'user-4' }, // Also in tokenReadAndWrite
  798. { _id: 7, lastUpdated: 4, owner_ref: 'user-5' },
  799. ]
  800. this.allProjects = {
  801. owned: this.projects,
  802. readAndWrite: this.collabertions,
  803. readOnly: this.readOnly,
  804. tokenReadAndWrite: this.tokenReadAndWrite,
  805. tokenReadOnly: this.tokenReadOnly,
  806. }
  807. this.users = {
  808. 'user-1': {
  809. first_name: 'James',
  810. },
  811. 'user-2': {
  812. first_name: 'Henry',
  813. },
  814. }
  815. this.users[this.user._id] = this.user // Owner
  816. this.UserModel.findById = (id, fields, callback) => {
  817. callback(null, this.users[id])
  818. }
  819. this.LimitationsManager.hasPaidSubscription.callsArgWith(1, null, false)
  820. this.TagsHandler.getAllTags.callsArgWith(1, null, this.tags)
  821. this.NotificationsHandler.getUserNotifications = sinon
  822. .stub()
  823. .callsArgWith(1, null, this.notifications, {})
  824. this.ProjectGetter.findAllUsersProjects.callsArgWith(
  825. 2,
  826. null,
  827. this.allProjects
  828. )
  829. })
  830. it('should render the project/list page', function (done) {
  831. this.res.render = (pageName, opts) => {
  832. pageName.should.equal('project/list')
  833. done()
  834. }
  835. this.ProjectController.projectListPage(this.req, this.res)
  836. })
  837. it('should omit one of the projects', function (done) {
  838. this.res.render = (pageName, opts) => {
  839. opts.projects.length.should.equal(
  840. this.projects.length +
  841. this.collabertions.length +
  842. this.readOnly.length +
  843. this.tokenReadAndWrite.length +
  844. this.tokenReadOnly.length -
  845. 1
  846. )
  847. done()
  848. }
  849. this.ProjectController.projectListPage(this.req, this.res)
  850. })
  851. })
  852. describe('renameProject', function () {
  853. beforeEach(function () {
  854. this.newProjectName = 'my supper great new project'
  855. this.req.body.newProjectName = this.newProjectName
  856. })
  857. it('should call the editor controller', function (done) {
  858. this.EditorController.renameProject.callsArgWith(2)
  859. this.res.sendStatus = code => {
  860. code.should.equal(200)
  861. this.EditorController.renameProject
  862. .calledWith(this.project_id, this.newProjectName)
  863. .should.equal(true)
  864. done()
  865. }
  866. this.ProjectController.renameProject(this.req, this.res)
  867. })
  868. it('should send an error to next() if there is a problem', function (done) {
  869. let error
  870. this.EditorController.renameProject.callsArgWith(
  871. 2,
  872. (error = new Error('problem'))
  873. )
  874. const next = e => {
  875. e.should.equal(error)
  876. done()
  877. }
  878. this.ProjectController.renameProject(this.req, this.res, next)
  879. })
  880. })
  881. describe('loadEditor', function () {
  882. beforeEach(function () {
  883. this.settings.editorIsOpen = true
  884. this.project = {
  885. name: 'my proj',
  886. _id: '213123kjlkj',
  887. owner_ref: '59fc84d5fbea77482d436e1b',
  888. }
  889. this.brandedProject = {
  890. name: 'my branded proj',
  891. _id: '3252332',
  892. owner_ref: '59fc84d5fbea77482d436e1b',
  893. brandVariationId: '12',
  894. }
  895. this.user = {
  896. _id: '588f3ddae8ebc1bac07c9fa4',
  897. ace: {
  898. fontSize: 'massive',
  899. theme: 'sexy',
  900. },
  901. email: 'bob@bob.com',
  902. refProviders: {
  903. mendeley: { encrypted: 'aaaa' },
  904. zotero: { encrypted: 'bbbb' },
  905. },
  906. }
  907. this.ProjectGetter.getProject.callsArgWith(2, null, this.project)
  908. this.UserModel.findById.callsArgWith(2, null, this.user)
  909. this.SubscriptionLocator.getUsersSubscription.callsArgWith(1, null, {})
  910. this.AuthorizationManager.getPrivilegeLevelForProject.callsArgWith(
  911. 3,
  912. null,
  913. 'owner'
  914. )
  915. this.ProjectDeleter.unmarkAsDeletedByExternalSource = sinon.stub()
  916. this.InactiveProjectManager.reactivateProjectIfRequired.callsArgWith(1)
  917. this.ProjectUpdateHandler.markAsOpened.callsArgWith(1)
  918. })
  919. it('should render the project/editor page', function (done) {
  920. this.res.render = (pageName, opts) => {
  921. pageName.should.equal('project/editor')
  922. done()
  923. }
  924. this.ProjectController.loadEditor(this.req, this.res)
  925. })
  926. it('should add user', function (done) {
  927. this.res.render = (pageName, opts) => {
  928. opts.user.email.should.equal(this.user.email)
  929. done()
  930. }
  931. this.ProjectController.loadEditor(this.req, this.res)
  932. })
  933. it('should sanitize refProviders', function (done) {
  934. this.res.render = (_pageName, opts) => {
  935. expect(opts.user.refProviders).to.deep.equal({
  936. mendeley: true,
  937. zotero: true,
  938. })
  939. done()
  940. }
  941. this.ProjectController.loadEditor(this.req, this.res)
  942. })
  943. it('should add on userSettings', function (done) {
  944. this.res.render = (pageName, opts) => {
  945. opts.userSettings.fontSize.should.equal(this.user.ace.fontSize)
  946. opts.userSettings.editorTheme.should.equal(this.user.ace.theme)
  947. done()
  948. }
  949. this.ProjectController.loadEditor(this.req, this.res)
  950. })
  951. it('should add isRestrictedTokenMember', function (done) {
  952. this.res.render = (pageName, opts) => {
  953. opts.isRestrictedTokenMember.should.exist
  954. opts.isRestrictedTokenMember.should.equal(false)
  955. return done()
  956. }
  957. return this.ProjectController.loadEditor(this.req, this.res)
  958. })
  959. it('should set isRestrictedTokenMember when appropriate', function (done) {
  960. this.AuthorizationManager.isRestrictedUser.returns(true)
  961. this.res.render = (pageName, opts) => {
  962. opts.isRestrictedTokenMember.should.exist
  963. opts.isRestrictedTokenMember.should.equal(true)
  964. return done()
  965. }
  966. return this.ProjectController.loadEditor(this.req, this.res)
  967. })
  968. it('should render the closed page if the editor is closed', function (done) {
  969. this.settings.editorIsOpen = false
  970. this.res.render = (pageName, opts) => {
  971. pageName.should.equal('general/closed')
  972. done()
  973. }
  974. this.ProjectController.loadEditor(this.req, this.res)
  975. })
  976. it('should not render the page if the project can not be accessed', function (done) {
  977. this.AuthorizationManager.getPrivilegeLevelForProject = sinon
  978. .stub()
  979. .callsArgWith(3, null, null)
  980. this.res.sendStatus = (resCode, opts) => {
  981. resCode.should.equal(401)
  982. done()
  983. }
  984. this.ProjectController.loadEditor(this.req, this.res)
  985. })
  986. it('should reactivateProjectIfRequired', function (done) {
  987. this.res.render = (pageName, opts) => {
  988. this.InactiveProjectManager.reactivateProjectIfRequired
  989. .calledWith(this.project_id)
  990. .should.equal(true)
  991. done()
  992. }
  993. this.ProjectController.loadEditor(this.req, this.res)
  994. })
  995. it('should mark project as opened', function (done) {
  996. this.res.render = (pageName, opts) => {
  997. this.ProjectUpdateHandler.markAsOpened
  998. .calledWith(this.project_id)
  999. .should.equal(true)
  1000. done()
  1001. }
  1002. this.ProjectController.loadEditor(this.req, this.res)
  1003. })
  1004. it('should call the brand variations handler for branded projects', function (done) {
  1005. this.ProjectGetter.getProject.callsArgWith(2, null, this.brandedProject)
  1006. this.res.render = (pageName, opts) => {
  1007. this.BrandVariationsHandler.getBrandVariationById
  1008. .calledWith()
  1009. .should.equal(true)
  1010. done()
  1011. }
  1012. this.ProjectController.loadEditor(this.req, this.res)
  1013. })
  1014. it('should not call the brand variations handler for unbranded projects', function (done) {
  1015. this.res.render = (pageName, opts) => {
  1016. this.BrandVariationsHandler.getBrandVariationById.called.should.equal(
  1017. false
  1018. )
  1019. done()
  1020. }
  1021. this.ProjectController.loadEditor(this.req, this.res)
  1022. })
  1023. it('should expose the brand variation details as locals for branded projects', function (done) {
  1024. this.ProjectGetter.getProject.callsArgWith(2, null, this.brandedProject)
  1025. this.res.render = (pageName, opts) => {
  1026. opts.brandVariation.should.deep.equal(this.brandVariationDetails)
  1027. done()
  1028. }
  1029. this.ProjectController.loadEditor(this.req, this.res)
  1030. })
  1031. it('flushes the project to TPDS if a flush is pending', function (done) {
  1032. this.res.render = () => {
  1033. this.TpdsProjectFlusher.flushProjectToTpdsIfNeeded.should.have.been.calledWith(
  1034. this.project_id
  1035. )
  1036. done()
  1037. }
  1038. this.ProjectController.loadEditor(this.req, this.res)
  1039. })
  1040. it('should refresh the user features if the epoch is outdated', function (done) {
  1041. this.FeaturesUpdater.featuresEpochIsCurrent = sinon.stub().returns(false)
  1042. this.res.render = () => {
  1043. this.FeaturesUpdater.refreshFeatures.should.have.been.calledWith(
  1044. this.user._id,
  1045. 'load-editor'
  1046. )
  1047. done()
  1048. }
  1049. this.ProjectController.loadEditor(this.req, this.res)
  1050. })
  1051. describe('pdf caching feature flags', function () {
  1052. /* eslint-disable mocha/no-identical-title */
  1053. function showNoVariant() {
  1054. beforeEach(function () {
  1055. this.SplitTestHandler.getTestSegmentation = sinon
  1056. .stub()
  1057. .yields(null, { enabled: false })
  1058. })
  1059. }
  1060. function showVariant(variant) {
  1061. beforeEach(function () {
  1062. this.SplitTestHandler.getTestSegmentation = sinon
  1063. .stub()
  1064. .yields(null, { enabled: true, variant })
  1065. })
  1066. }
  1067. function expectBandwidthTrackingEnabled() {
  1068. it('should track pdf bandwidth', function (done) {
  1069. this.res.render = (pageName, opts) => {
  1070. expect(opts.trackPdfDownload).to.equal(true)
  1071. done()
  1072. }
  1073. this.ProjectController.loadEditor(this.req, this.res)
  1074. })
  1075. }
  1076. function expectPDFCachingEnabled() {
  1077. it('should enable pdf caching', function (done) {
  1078. this.res.render = (pageName, opts) => {
  1079. expect(opts.enablePdfCaching).to.equal(true)
  1080. done()
  1081. }
  1082. this.ProjectController.loadEditor(this.req, this.res)
  1083. })
  1084. }
  1085. function expectBandwidthTrackingDisabled() {
  1086. it('should not track pdf bandwidth', function (done) {
  1087. this.res.render = (pageName, opts) => {
  1088. expect(opts.trackPdfDownload).to.equal(false)
  1089. done()
  1090. }
  1091. this.ProjectController.loadEditor(this.req, this.res)
  1092. })
  1093. }
  1094. function expectPDFCachingDisabled() {
  1095. it('should disable pdf caching', function (done) {
  1096. this.res.render = (pageName, opts) => {
  1097. expect(opts.enablePdfCaching).to.equal(false)
  1098. done()
  1099. }
  1100. this.ProjectController.loadEditor(this.req, this.res)
  1101. })
  1102. }
  1103. function expectToCollectMetricsAndCachePDF() {
  1104. describe('with no query', function () {
  1105. expectBandwidthTrackingEnabled()
  1106. expectPDFCachingEnabled()
  1107. })
  1108. describe('with enable_pdf_caching=false', function () {
  1109. beforeEach(function () {
  1110. this.req.query.enable_pdf_caching = 'false'
  1111. })
  1112. expectBandwidthTrackingDisabled()
  1113. expectPDFCachingDisabled()
  1114. })
  1115. describe('with enable_pdf_caching=true', function () {
  1116. beforeEach(function () {
  1117. this.req.query.enable_pdf_caching = 'true'
  1118. })
  1119. expectBandwidthTrackingEnabled()
  1120. expectPDFCachingEnabled()
  1121. })
  1122. }
  1123. function expectToCollectMetricsOnly() {
  1124. describe('with no query', function () {
  1125. expectBandwidthTrackingEnabled()
  1126. expectPDFCachingDisabled()
  1127. })
  1128. describe('with enable_pdf_caching=false', function () {
  1129. beforeEach(function () {
  1130. this.req.query.enable_pdf_caching = 'false'
  1131. })
  1132. expectBandwidthTrackingDisabled()
  1133. expectPDFCachingDisabled()
  1134. })
  1135. describe('with enable_pdf_caching=true', function () {
  1136. beforeEach(function () {
  1137. this.req.query.enable_pdf_caching = 'true'
  1138. })
  1139. expectBandwidthTrackingEnabled()
  1140. expectPDFCachingDisabled()
  1141. })
  1142. }
  1143. function expectToCachePDFOnly() {
  1144. describe('with no query', function () {
  1145. expectBandwidthTrackingDisabled()
  1146. expectPDFCachingEnabled()
  1147. })
  1148. describe('with enable_pdf_caching=false', function () {
  1149. beforeEach(function () {
  1150. this.req.query.enable_pdf_caching = 'false'
  1151. })
  1152. expectBandwidthTrackingDisabled()
  1153. expectPDFCachingDisabled()
  1154. })
  1155. describe('with enable_pdf_caching=true', function () {
  1156. beforeEach(function () {
  1157. this.req.query.enable_pdf_caching = 'true'
  1158. })
  1159. expectBandwidthTrackingDisabled()
  1160. expectPDFCachingEnabled()
  1161. })
  1162. }
  1163. function expectToNotBeEnrolledAtAll() {
  1164. describe('with no query', function () {
  1165. expectBandwidthTrackingDisabled()
  1166. expectPDFCachingDisabled()
  1167. })
  1168. describe('with enable_pdf_caching=false', function () {
  1169. beforeEach(function () {
  1170. this.req.query.enable_pdf_caching = 'false'
  1171. })
  1172. expectBandwidthTrackingDisabled()
  1173. expectPDFCachingDisabled()
  1174. })
  1175. describe('with enable_pdf_caching=true', function () {
  1176. beforeEach(function () {
  1177. this.req.query.enable_pdf_caching = 'true'
  1178. })
  1179. expectBandwidthTrackingDisabled()
  1180. expectPDFCachingDisabled()
  1181. })
  1182. }
  1183. function tagAnonymous() {
  1184. beforeEach(function () {
  1185. this.SessionManager.isUserLoggedIn = sinon.stub().returns(false)
  1186. })
  1187. }
  1188. beforeEach(function () {
  1189. this.settings.enablePdfCaching = true
  1190. })
  1191. describe('during regular roll-out', function () {
  1192. before(function () {
  1193. this.skip()
  1194. })
  1195. describe('disabled', function () {
  1196. showNoVariant()
  1197. describe('regular user', function () {
  1198. expectToNotBeEnrolledAtAll()
  1199. })
  1200. describe('anonymous user', function () {
  1201. tagAnonymous()
  1202. expectToCachePDFOnly()
  1203. })
  1204. })
  1205. describe('variant=collect-metrics', function () {
  1206. showVariant('collect-metrics')
  1207. describe('regular user', function () {
  1208. expectToCollectMetricsOnly()
  1209. })
  1210. describe('anonymous user', function () {
  1211. tagAnonymous()
  1212. expectToCachePDFOnly()
  1213. })
  1214. })
  1215. describe('variant=collect-metrics-and-enable-caching', function () {
  1216. showVariant('collect-metrics-and-enable-caching')
  1217. describe('regular user', function () {
  1218. expectToCollectMetricsAndCachePDF()
  1219. })
  1220. describe('anonymous user', function () {
  1221. tagAnonymous()
  1222. expectToCachePDFOnly()
  1223. })
  1224. })
  1225. describe('variant=enable-caching-only', function () {
  1226. showVariant('enable-caching-only')
  1227. describe('regular user', function () {
  1228. expectToCachePDFOnly()
  1229. })
  1230. describe('anonymous user', function () {
  1231. tagAnonymous()
  1232. expectToCachePDFOnly()
  1233. })
  1234. })
  1235. })
  1236. describe('during opt-in only', function () {
  1237. describe('with no query', function () {
  1238. expectBandwidthTrackingDisabled()
  1239. expectPDFCachingDisabled()
  1240. })
  1241. describe('with enable_pdf_caching=false', function () {
  1242. beforeEach(function () {
  1243. this.req.query.enable_pdf_caching = 'false'
  1244. })
  1245. expectBandwidthTrackingDisabled()
  1246. expectPDFCachingDisabled()
  1247. })
  1248. describe('with enable_pdf_caching=true', function () {
  1249. beforeEach(function () {
  1250. this.req.query.enable_pdf_caching = 'true'
  1251. })
  1252. expectBandwidthTrackingEnabled()
  1253. expectPDFCachingEnabled()
  1254. })
  1255. })
  1256. })
  1257. describe('wsUrl', function () {
  1258. function checkLoadEditorWsMetric(metric) {
  1259. it(`should inc metric ${metric}`, function (done) {
  1260. this.res.render = () => {
  1261. this.Metrics.inc.calledWith(metric).should.equal(true)
  1262. done()
  1263. }
  1264. this.ProjectController.loadEditor(this.req, this.res)
  1265. })
  1266. }
  1267. function checkWsFallback(isBeta, isV2) {
  1268. describe('with ws=fallback', function () {
  1269. beforeEach(function () {
  1270. this.req.query = {}
  1271. this.req.query.ws = 'fallback'
  1272. })
  1273. it('should unset the wsUrl', function (done) {
  1274. this.res.render = (pageName, opts) => {
  1275. ;(opts.wsUrl || '/socket.io').should.equal('/socket.io')
  1276. done()
  1277. }
  1278. this.ProjectController.loadEditor(this.req, this.res)
  1279. })
  1280. checkLoadEditorWsMetric(
  1281. `load-editor-ws${isBeta ? '-beta' : ''}${
  1282. isV2 ? '-v2' : ''
  1283. }-fallback`
  1284. )
  1285. })
  1286. }
  1287. beforeEach(function () {
  1288. this.settings.wsUrl = '/other.socket.io'
  1289. })
  1290. it('should set the custom wsUrl', function (done) {
  1291. this.res.render = (pageName, opts) => {
  1292. opts.wsUrl.should.equal('/other.socket.io')
  1293. done()
  1294. }
  1295. this.ProjectController.loadEditor(this.req, this.res)
  1296. })
  1297. checkLoadEditorWsMetric('load-editor-ws')
  1298. checkWsFallback(false)
  1299. describe('beta program', function () {
  1300. beforeEach(function () {
  1301. this.settings.wsUrlBeta = '/beta.socket.io'
  1302. })
  1303. describe('for a normal user', function () {
  1304. it('should set the normal custom wsUrl', function (done) {
  1305. this.res.render = (pageName, opts) => {
  1306. opts.wsUrl.should.equal('/other.socket.io')
  1307. done()
  1308. }
  1309. this.ProjectController.loadEditor(this.req, this.res)
  1310. })
  1311. checkLoadEditorWsMetric('load-editor-ws')
  1312. checkWsFallback(false)
  1313. })
  1314. describe('for a beta user', function () {
  1315. beforeEach(function () {
  1316. this.user.betaProgram = true
  1317. })
  1318. it('should set the beta wsUrl', function (done) {
  1319. this.res.render = (pageName, opts) => {
  1320. opts.wsUrl.should.equal('/beta.socket.io')
  1321. done()
  1322. }
  1323. this.ProjectController.loadEditor(this.req, this.res)
  1324. })
  1325. checkLoadEditorWsMetric('load-editor-ws-beta')
  1326. checkWsFallback(true)
  1327. })
  1328. })
  1329. describe('v2-rollout', function () {
  1330. beforeEach(function () {
  1331. this.settings.wsUrlBeta = '/beta.socket.io'
  1332. this.settings.wsUrlV2 = '/socket.io.v2'
  1333. })
  1334. function checkNonMatch() {
  1335. it('should set the normal custom wsUrl', function (done) {
  1336. this.res.render = (pageName, opts) => {
  1337. opts.wsUrl.should.equal('/other.socket.io')
  1338. done()
  1339. }
  1340. this.ProjectController.loadEditor(this.req, this.res)
  1341. })
  1342. checkLoadEditorWsMetric('load-editor-ws')
  1343. checkWsFallback(false)
  1344. }
  1345. function checkMatch() {
  1346. it('should set the v2 wsUrl', function (done) {
  1347. this.res.render = (pageName, opts) => {
  1348. opts.wsUrl.should.equal('/socket.io.v2')
  1349. done()
  1350. }
  1351. this.ProjectController.loadEditor(this.req, this.res)
  1352. })
  1353. checkLoadEditorWsMetric('load-editor-ws-v2')
  1354. checkWsFallback(false, true)
  1355. }
  1356. function checkForBetaUser() {
  1357. describe('for a beta user', function () {
  1358. beforeEach(function () {
  1359. this.user.betaProgram = true
  1360. })
  1361. it('should set the beta wsUrl', function (done) {
  1362. this.res.render = (pageName, opts) => {
  1363. opts.wsUrl.should.equal('/beta.socket.io')
  1364. done()
  1365. }
  1366. this.ProjectController.loadEditor(this.req, this.res)
  1367. })
  1368. checkLoadEditorWsMetric('load-editor-ws-beta')
  1369. checkWsFallback(true)
  1370. })
  1371. }
  1372. describe('when the roll out percentage is 0', function () {
  1373. beforeEach(function () {
  1374. this.settings.wsUrlV2Percentage = 0
  1375. })
  1376. describe('when the projectId does not match (0)', function () {
  1377. beforeEach(function () {
  1378. this.req.params.Project_id = ObjectId.createFromTime(0)
  1379. })
  1380. checkNonMatch()
  1381. })
  1382. describe('when the projectId does not match (42)', function () {
  1383. beforeEach(function () {
  1384. this.req.params.Project_id = ObjectId.createFromTime(42)
  1385. })
  1386. checkNonMatch()
  1387. })
  1388. checkForBetaUser()
  1389. })
  1390. describe('when the roll out percentage is 1', function () {
  1391. beforeEach(function () {
  1392. this.settings.wsUrlV2Percentage = 1
  1393. })
  1394. describe('when the projectId matches (0)', function () {
  1395. beforeEach(function () {
  1396. this.req.params.Project_id = ObjectId.createFromTime(0)
  1397. })
  1398. checkMatch()
  1399. checkForBetaUser()
  1400. })
  1401. describe('when the projectId does not match (1)', function () {
  1402. beforeEach(function () {
  1403. this.req.params.Project_id = ObjectId.createFromTime(1)
  1404. })
  1405. checkNonMatch()
  1406. checkForBetaUser()
  1407. })
  1408. describe('when the projectId does not match (42)', function () {
  1409. beforeEach(function () {
  1410. this.req.params.Project_id = ObjectId.createFromTime(42)
  1411. })
  1412. checkNonMatch()
  1413. })
  1414. })
  1415. describe('when the roll out percentage is 10', function () {
  1416. beforeEach(function () {
  1417. this.settings.wsUrlV2Percentage = 10
  1418. })
  1419. describe('when the projectId matches (0)', function () {
  1420. beforeEach(function () {
  1421. this.req.params.Project_id = ObjectId.createFromTime(0)
  1422. })
  1423. checkMatch()
  1424. })
  1425. describe('when the projectId matches (9)', function () {
  1426. beforeEach(function () {
  1427. this.req.params.Project_id = ObjectId.createFromTime(9)
  1428. })
  1429. checkMatch()
  1430. checkForBetaUser()
  1431. })
  1432. describe('when the projectId does not match (10)', function () {
  1433. beforeEach(function () {
  1434. this.req.params.Project_id = ObjectId.createFromTime(10)
  1435. })
  1436. checkNonMatch()
  1437. })
  1438. describe('when the projectId does not match (42)', function () {
  1439. beforeEach(function () {
  1440. this.req.params.Project_id = ObjectId.createFromTime(42)
  1441. })
  1442. checkNonMatch()
  1443. checkForBetaUser()
  1444. })
  1445. })
  1446. describe('when the roll out percentage is 100', function () {
  1447. beforeEach(function () {
  1448. this.settings.wsUrlV2Percentage = 100
  1449. })
  1450. describe('when the projectId matches (0)', function () {
  1451. beforeEach(function () {
  1452. this.req.params.Project_id = ObjectId.createFromTime(0)
  1453. })
  1454. checkMatch()
  1455. checkForBetaUser()
  1456. })
  1457. describe('when the projectId matches (10)', function () {
  1458. beforeEach(function () {
  1459. this.req.params.Project_id = ObjectId.createFromTime(10)
  1460. })
  1461. checkMatch()
  1462. })
  1463. describe('when the projectId matches (42)', function () {
  1464. beforeEach(function () {
  1465. this.req.params.Project_id = ObjectId.createFromTime(42)
  1466. })
  1467. checkMatch()
  1468. })
  1469. describe('when the projectId matches (99)', function () {
  1470. beforeEach(function () {
  1471. this.req.params.Project_id = ObjectId.createFromTime(99)
  1472. })
  1473. checkMatch()
  1474. })
  1475. })
  1476. })
  1477. })
  1478. describe('feature flags', function () {
  1479. describe('showNewPdfPreview', function () {
  1480. it('should be false by default', function (done) {
  1481. this.res.render = (pageName, opts) => {
  1482. expect(opts.showNewPdfPreview).to.be.false
  1483. done()
  1484. }
  1485. this.ProjectController.loadEditor(this.req, this.res)
  1486. })
  1487. it('should be true when ?new_pdf_preview=true ', function (done) {
  1488. this.res.render = (pageName, opts) => {
  1489. expect(opts.showNewPdfPreview).to.be.true
  1490. done()
  1491. }
  1492. this.req.query.new_pdf_preview = 'true'
  1493. this.ProjectController.loadEditor(this.req, this.res)
  1494. })
  1495. it('should be true for alpha group', function (done) {
  1496. this.res.render = (pageName, opts) => {
  1497. expect(opts.showNewPdfPreview).to.be.true
  1498. done()
  1499. }
  1500. this.user.alphaProgram = true
  1501. this.ProjectController.loadEditor(this.req, this.res)
  1502. })
  1503. it('should be false when when ?new_pdf_preview=true and alpha group', function (done) {
  1504. this.res.render = (pageName, opts) => {
  1505. expect(opts.showNewPdfPreview).to.be.true
  1506. done()
  1507. }
  1508. this.user.alphaProgram = true
  1509. this.req.query.new_pdf_preview = 'false'
  1510. this.ProjectController.loadEditor(this.req, this.res)
  1511. })
  1512. })
  1513. describe('showPdfDetach', function () {
  1514. describe('showPdfDetach=false', function () {
  1515. it('should be false by default', function (done) {
  1516. this.res.render = (pageName, opts) => {
  1517. expect(opts.showPdfDetach).to.be.false
  1518. done()
  1519. }
  1520. this.ProjectController.loadEditor(this.req, this.res)
  1521. })
  1522. it('should be false by default, even when ?new_pdf_preview=true', function (done) {
  1523. this.res.render = (pageName, opts) => {
  1524. expect(opts.showPdfDetach).to.be.false
  1525. expect(opts.showNewPdfPreview).to.be.true
  1526. done()
  1527. }
  1528. this.req.query.new_pdf_preview = 'true'
  1529. this.ProjectController.loadEditor(this.req, this.res)
  1530. })
  1531. it('should be false when when ?pdf_detach=true and alpha group', function (done) {
  1532. this.res.render = (pageName, opts) => {
  1533. done()
  1534. }
  1535. this.user.alphaProgram = true
  1536. this.req.query.pdf_detach = 'false'
  1537. this.ProjectController.loadEditor(this.req, this.res)
  1538. })
  1539. })
  1540. describe('showPdfDetach=true', function () {
  1541. it('should be true when ?pdf_detach=true, and set showNewPdfPreview as true ', function (done) {
  1542. this.res.render = (pageName, opts) => {
  1543. expect(opts.showPdfDetach).to.be.true
  1544. expect(opts.showNewPdfPreview).to.be.true
  1545. done()
  1546. }
  1547. this.req.query.pdf_detach = 'true'
  1548. this.ProjectController.loadEditor(this.req, this.res)
  1549. })
  1550. it('should be true for alpha group, and set showNewPdfPreview as true', function (done) {
  1551. this.res.render = (pageName, opts) => {
  1552. expect(opts.showPdfDetach).to.be.true
  1553. expect(opts.showNewPdfPreview).to.be.true
  1554. done()
  1555. }
  1556. this.user.alphaProgram = true
  1557. this.ProjectController.loadEditor(this.req, this.res)
  1558. })
  1559. })
  1560. })
  1561. })
  1562. })
  1563. describe('userProjectsJson', function () {
  1564. beforeEach(function (done) {
  1565. const projects = [
  1566. {
  1567. archived: true,
  1568. trashed: true,
  1569. id: 'a',
  1570. name: 'A',
  1571. accessLevel: 'a',
  1572. somethingElse: 1,
  1573. },
  1574. {
  1575. archived: false,
  1576. id: 'b',
  1577. name: 'B',
  1578. accessLevel: 'b',
  1579. somethingElse: 1,
  1580. },
  1581. {
  1582. archived: false,
  1583. trashed: true,
  1584. id: 'c',
  1585. name: 'C',
  1586. accessLevel: 'c',
  1587. somethingElse: 1,
  1588. },
  1589. {
  1590. archived: false,
  1591. trashed: false,
  1592. id: 'd',
  1593. name: 'D',
  1594. accessLevel: 'd',
  1595. somethingElse: 1,
  1596. },
  1597. ]
  1598. this.ProjectHelper.isArchivedOrTrashed
  1599. .withArgs(projects[0], this.user._id)
  1600. .returns(true)
  1601. this.ProjectHelper.isArchivedOrTrashed
  1602. .withArgs(projects[1], this.user._id)
  1603. .returns(false)
  1604. this.ProjectHelper.isArchivedOrTrashed
  1605. .withArgs(projects[2], this.user._id)
  1606. .returns(true)
  1607. this.ProjectHelper.isArchivedOrTrashed
  1608. .withArgs(projects[3], this.user._id)
  1609. .returns(false)
  1610. this.ProjectGetter.findAllUsersProjects = sinon
  1611. .stub()
  1612. .callsArgWith(2, null, [])
  1613. this.ProjectController._buildProjectList = sinon.stub().returns(projects)
  1614. this.SessionManager.getLoggedInUserId = sinon
  1615. .stub()
  1616. .returns(this.user._id)
  1617. done()
  1618. })
  1619. it('should produce a list of projects', function (done) {
  1620. this.res.json = data => {
  1621. expect(data).to.deep.equal({
  1622. projects: [
  1623. { _id: 'b', name: 'B', accessLevel: 'b' },
  1624. { _id: 'd', name: 'D', accessLevel: 'd' },
  1625. ],
  1626. })
  1627. done()
  1628. }
  1629. this.ProjectController.userProjectsJson(this.req, this.res, this.next)
  1630. })
  1631. })
  1632. describe('projectEntitiesJson', function () {
  1633. beforeEach(function () {
  1634. this.SessionManager.getLoggedInUserId = sinon.stub().returns('abc')
  1635. this.req.params = { Project_id: 'abcd' }
  1636. this.project = { _id: 'abcd' }
  1637. this.docs = [
  1638. { path: '/things/b.txt', doc: true },
  1639. { path: '/main.tex', doc: true },
  1640. ]
  1641. this.files = [{ path: '/things/a.txt' }]
  1642. this.ProjectGetter.getProject = sinon
  1643. .stub()
  1644. .callsArgWith(1, null, this.project)
  1645. this.ProjectEntityHandler.getAllEntitiesFromProject = sinon
  1646. .stub()
  1647. .callsArgWith(1, null, this.docs, this.files)
  1648. })
  1649. it('should produce a list of entities', function (done) {
  1650. this.res.json = data => {
  1651. expect(data).to.deep.equal({
  1652. project_id: 'abcd',
  1653. entities: [
  1654. { path: '/main.tex', type: 'doc' },
  1655. { path: '/things/a.txt', type: 'file' },
  1656. { path: '/things/b.txt', type: 'doc' },
  1657. ],
  1658. })
  1659. expect(this.ProjectGetter.getProject.callCount).to.equal(1)
  1660. expect(
  1661. this.ProjectEntityHandler.getAllEntitiesFromProject.callCount
  1662. ).to.equal(1)
  1663. done()
  1664. }
  1665. this.ProjectController.projectEntitiesJson(this.req, this.res, this.next)
  1666. })
  1667. })
  1668. describe('_buildProjectViewModel', function () {
  1669. beforeEach(function () {
  1670. this.ProjectHelper.isArchived.returns(false)
  1671. this.ProjectHelper.isTrashed.returns(false)
  1672. this.project = {
  1673. _id: 'abcd',
  1674. name: 'netsenits',
  1675. lastUpdated: 1,
  1676. lastUpdatedBy: 2,
  1677. publicAccesLevel: 'private',
  1678. archived: false,
  1679. owner_ref: 'defg',
  1680. tokens: {
  1681. readAndWrite: '1abcd',
  1682. readAndWritePrefix: '1',
  1683. readOnly: 'neiotsranteoia',
  1684. },
  1685. }
  1686. })
  1687. describe('project not being archived or trashed', function () {
  1688. it('should produce a model of the project', function () {
  1689. const result = this.ProjectController._buildProjectViewModel(
  1690. this.project,
  1691. 'readAndWrite',
  1692. 'owner',
  1693. this.user._id
  1694. )
  1695. expect(result).to.exist
  1696. expect(result).to.be.an('object')
  1697. expect(result).to.deep.equal({
  1698. id: 'abcd',
  1699. name: 'netsenits',
  1700. lastUpdated: 1,
  1701. lastUpdatedBy: 2,
  1702. publicAccessLevel: 'private',
  1703. accessLevel: 'readAndWrite',
  1704. source: 'owner',
  1705. archived: false,
  1706. trashed: false,
  1707. owner_ref: 'defg',
  1708. isV1Project: false,
  1709. })
  1710. })
  1711. })
  1712. describe('project being simultaneously archived and trashed', function () {
  1713. beforeEach(function () {
  1714. this.ProjectHelper.isArchived.returns(true)
  1715. this.ProjectHelper.isTrashed.returns(true)
  1716. })
  1717. it('should produce a model of the project', function () {
  1718. const result = this.ProjectController._buildProjectViewModel(
  1719. this.project,
  1720. 'readAndWrite',
  1721. 'owner',
  1722. this.user._id
  1723. )
  1724. expect(result).to.exist
  1725. expect(result).to.be.an('object')
  1726. expect(result).to.deep.equal({
  1727. id: 'abcd',
  1728. name: 'netsenits',
  1729. lastUpdated: 1,
  1730. lastUpdatedBy: 2,
  1731. publicAccessLevel: 'private',
  1732. accessLevel: 'readAndWrite',
  1733. source: 'owner',
  1734. archived: true,
  1735. trashed: false,
  1736. owner_ref: 'defg',
  1737. isV1Project: false,
  1738. })
  1739. })
  1740. })
  1741. describe('when token-read-only access', function () {
  1742. it('should redact the owner and last-updated data', function () {
  1743. const result = this.ProjectController._buildProjectViewModel(
  1744. this.project,
  1745. 'readOnly',
  1746. 'token',
  1747. this.user._id
  1748. )
  1749. expect(result).to.exist
  1750. expect(result).to.be.an('object')
  1751. expect(result).to.deep.equal({
  1752. id: 'abcd',
  1753. name: 'netsenits',
  1754. lastUpdated: 1,
  1755. lastUpdatedBy: null,
  1756. publicAccessLevel: 'private',
  1757. accessLevel: 'readOnly',
  1758. source: 'token',
  1759. archived: false,
  1760. trashed: false,
  1761. owner_ref: null,
  1762. isV1Project: false,
  1763. })
  1764. })
  1765. })
  1766. })
  1767. describe('_isInPercentageRollout', function () {
  1768. before(function () {
  1769. this.ids = [
  1770. '5a05cd7621f9fe22be131740',
  1771. '5a05cd7821f9fe22be131741',
  1772. '5a05cd7921f9fe22be131742',
  1773. '5a05cd7a21f9fe22be131743',
  1774. '5a05cd7b21f9fe22be131744',
  1775. '5a05cd7c21f9fe22be131745',
  1776. '5a05cd7d21f9fe22be131746',
  1777. '5a05cd7e21f9fe22be131747',
  1778. '5a05cd7f21f9fe22be131748',
  1779. '5a05cd8021f9fe22be131749',
  1780. '5a05cd8021f9fe22be13174a',
  1781. '5a05cd8121f9fe22be13174b',
  1782. '5a05cd8221f9fe22be13174c',
  1783. '5a05cd8221f9fe22be13174d',
  1784. '5a05cd8321f9fe22be13174e',
  1785. '5a05cd8321f9fe22be13174f',
  1786. '5a05cd8421f9fe22be131750',
  1787. '5a05cd8421f9fe22be131751',
  1788. '5a05cd8421f9fe22be131752',
  1789. '5a05cd8521f9fe22be131753',
  1790. ]
  1791. })
  1792. it('should produce the expected results', function () {
  1793. expect(
  1794. this.ids.map(i =>
  1795. this.ProjectController._isInPercentageRollout('abcd', i, 50)
  1796. )
  1797. ).to.deep.equal([
  1798. false,
  1799. false,
  1800. false,
  1801. false,
  1802. false,
  1803. false,
  1804. true,
  1805. false,
  1806. true,
  1807. true,
  1808. true,
  1809. true,
  1810. true,
  1811. true,
  1812. false,
  1813. false,
  1814. false,
  1815. true,
  1816. false,
  1817. true,
  1818. ])
  1819. expect(
  1820. this.ids.map(i =>
  1821. this.ProjectController._isInPercentageRollout('efgh', i, 50)
  1822. )
  1823. ).to.deep.equal([
  1824. false,
  1825. false,
  1826. false,
  1827. false,
  1828. true,
  1829. false,
  1830. false,
  1831. true,
  1832. false,
  1833. false,
  1834. true,
  1835. true,
  1836. true,
  1837. false,
  1838. true,
  1839. false,
  1840. true,
  1841. true,
  1842. false,
  1843. false,
  1844. ])
  1845. })
  1846. })
  1847. })