ProjectListControllerTests.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  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-legacy')
  6. const Errors = require('../../../../app/src/Features/Errors/Errors')
  7. const MODULE_PATH = path.join(
  8. __dirname,
  9. '../../../../app/src/Features/Project/ProjectListController'
  10. )
  11. describe('ProjectListController', function () {
  12. beforeEach(function () {
  13. this.project_id = new ObjectId('abcdefabcdefabcdefabcdef')
  14. this.user = {
  15. _id: new ObjectId('123456123456123456123456'),
  16. email: 'test@overleaf.com',
  17. first_name: 'bjkdsjfk',
  18. features: {},
  19. emails: [{ email: 'test@overleaf.com' }],
  20. lastLoginIp: '111.111.111.112',
  21. }
  22. this.users = {
  23. 'user-1': {
  24. first_name: 'James',
  25. },
  26. 'user-2': {
  27. first_name: 'Henry',
  28. },
  29. }
  30. this.users[this.user._id] = this.user // Owner
  31. this.usersArr = Object.entries(this.users).map(([key, value]) => ({
  32. _id: key,
  33. ...value,
  34. }))
  35. this.tags = [
  36. { name: 1, project_ids: ['1', '2', '3'] },
  37. { name: 2, project_ids: ['a', '1'] },
  38. { name: 3, project_ids: ['a', 'b', 'c', 'd'] },
  39. ]
  40. this.notifications = [
  41. {
  42. _id: '1',
  43. user_id: '2',
  44. templateKey: '3',
  45. messageOpts: '4',
  46. key: '5',
  47. },
  48. ]
  49. this.settings = {
  50. siteUrl: 'https://overleaf.com',
  51. }
  52. this.LimitationsManager = {
  53. promises: {
  54. userIsMemberOfGroupSubscription: sinon.stub().resolves(false),
  55. },
  56. }
  57. this.TagsHandler = {
  58. promises: {
  59. getAllTags: sinon.stub().resolves(this.tags),
  60. },
  61. }
  62. this.NotificationsHandler = {
  63. promises: {
  64. getUserNotifications: sinon.stub().resolves(this.notifications),
  65. },
  66. }
  67. this.UserModel = {
  68. findById: sinon.stub().resolves(this.user),
  69. }
  70. this.UserPrimaryEmailCheckHandler = {
  71. requiresPrimaryEmailCheck: sinon.stub().returns(false),
  72. }
  73. this.ProjectGetter = {
  74. promises: {
  75. findAllUsersProjects: sinon.stub(),
  76. },
  77. }
  78. this.ProjectHelper = {
  79. isArchived: sinon.stub(),
  80. isTrashed: sinon.stub(),
  81. }
  82. this.SessionManager = {
  83. getLoggedInUserId: sinon.stub().returns(this.user._id),
  84. }
  85. this.UserController = {
  86. logout: sinon.stub(),
  87. }
  88. this.UserGetter = {
  89. promises: {
  90. getUsers: sinon.stub().resolves(this.usersArr),
  91. getUserFullEmails: sinon.stub().resolves([]),
  92. },
  93. }
  94. this.Features = {
  95. hasFeature: sinon.stub(),
  96. }
  97. this.Metrics = {
  98. inc: sinon.stub(),
  99. }
  100. this.SplitTestHandler = {
  101. promises: {
  102. getAssignment: sinon.stub().resolves({ variant: 'default' }),
  103. },
  104. }
  105. this.SplitTestSessionHandler = {
  106. promises: {
  107. sessionMaintenance: sinon.stub().resolves(),
  108. },
  109. }
  110. this.SubscriptionViewModelBuilder = {
  111. promises: {
  112. getBestSubscription: sinon.stub().resolves({ type: 'free' }),
  113. },
  114. }
  115. this.SurveyHandler = {
  116. promises: {
  117. getSurvey: sinon.stub().resolves({}),
  118. },
  119. }
  120. this.NotificationBuilder = {
  121. promises: {
  122. ipMatcherAffiliation: sinon.stub().returns({ create: sinon.stub() }),
  123. },
  124. }
  125. this.SubscriptionLocator = {
  126. promises: {
  127. getUserSubscription: sinon.stub().resolves({}),
  128. },
  129. }
  130. this.GeoIpLookup = {
  131. promises: {
  132. getCurrencyCode: sinon.stub().resolves({
  133. countryCode: 'US',
  134. currencyCode: 'USD',
  135. }),
  136. },
  137. }
  138. this.TutorialHandler = {
  139. getInactiveTutorials: sinon.stub().returns([]),
  140. }
  141. this.Modules = {
  142. promises: {
  143. hooks: {
  144. fire: sinon.stub().resolves([]),
  145. },
  146. },
  147. }
  148. this.ProjectListController = SandboxedModule.require(MODULE_PATH, {
  149. requires: {
  150. 'mongodb-legacy': { ObjectId },
  151. '@overleaf/settings': this.settings,
  152. '@overleaf/metrics': this.Metrics,
  153. '../SplitTests/SplitTestHandler': this.SplitTestHandler,
  154. '../SplitTests/SplitTestSessionHandler': this.SplitTestSessionHandler,
  155. '../User/UserController': this.UserController,
  156. './ProjectHelper': this.ProjectHelper,
  157. '../Subscription/LimitationsManager': this.LimitationsManager,
  158. '../Tags/TagsHandler': this.TagsHandler,
  159. '../Notifications/NotificationsHandler': this.NotificationsHandler,
  160. '../../models/User': { User: this.UserModel },
  161. './ProjectGetter': this.ProjectGetter,
  162. '../Authentication/SessionManager': this.SessionManager,
  163. '../../infrastructure/Features': this.Features,
  164. '../User/UserGetter': this.UserGetter,
  165. '../Subscription/SubscriptionViewModelBuilder':
  166. this.SubscriptionViewModelBuilder,
  167. '../../infrastructure/Modules': this.Modules,
  168. '../Survey/SurveyHandler': this.SurveyHandler,
  169. '../User/UserPrimaryEmailCheckHandler':
  170. this.UserPrimaryEmailCheckHandler,
  171. '../Notifications/NotificationsBuilder': this.NotificationBuilder,
  172. '../Subscription/SubscriptionLocator': this.SubscriptionLocator,
  173. '../../infrastructure/GeoIpLookup': this.GeoIpLookup,
  174. '../Tutorial/TutorialHandler': this.TutorialHandler,
  175. },
  176. })
  177. this.req = {
  178. query: {},
  179. params: {
  180. Project_id: this.project_id,
  181. },
  182. headers: {},
  183. session: {
  184. user: this.user,
  185. },
  186. body: {},
  187. i18n: {
  188. translate() {},
  189. },
  190. }
  191. this.res = {}
  192. })
  193. describe('projectListPage', function () {
  194. beforeEach(function () {
  195. this.projects = [
  196. { _id: 1, lastUpdated: 1, owner_ref: 'user-1' },
  197. {
  198. _id: 2,
  199. lastUpdated: 2,
  200. owner_ref: 'user-2',
  201. lastUpdatedBy: 'user-1',
  202. },
  203. ]
  204. this.readAndWrite = [{ _id: 5, lastUpdated: 5, owner_ref: 'user-1' }]
  205. this.readOnly = [{ _id: 3, lastUpdated: 3, owner_ref: 'user-1' }]
  206. this.tokenReadAndWrite = [{ _id: 6, lastUpdated: 5, owner_ref: 'user-4' }]
  207. this.tokenReadOnly = [{ _id: 7, lastUpdated: 4, owner_ref: 'user-5' }]
  208. this.allProjects = {
  209. owned: this.projects,
  210. readAndWrite: this.readAndWrite,
  211. readOnly: this.readOnly,
  212. tokenReadAndWrite: this.tokenReadAndWrite,
  213. tokenReadOnly: this.tokenReadOnly,
  214. }
  215. this.ProjectGetter.promises.findAllUsersProjects.resolves(
  216. this.allProjects
  217. )
  218. })
  219. it('should render the project/list-react page', function (done) {
  220. this.res.render = (pageName, opts) => {
  221. pageName.should.equal('project/list-react')
  222. done()
  223. }
  224. this.ProjectListController.projectListPage(this.req, this.res)
  225. })
  226. it('should invoke the session maintenance', function (done) {
  227. this.Features.hasFeature.withArgs('saas').returns(true)
  228. this.res.render = () => {
  229. this.SplitTestSessionHandler.promises.sessionMaintenance.should.have.been.calledWith(
  230. this.req,
  231. this.user
  232. )
  233. done()
  234. }
  235. this.ProjectListController.projectListPage(this.req, this.res)
  236. })
  237. it('should send the tags', function (done) {
  238. this.res.render = (pageName, opts) => {
  239. opts.tags.length.should.equal(this.tags.length)
  240. done()
  241. }
  242. this.ProjectListController.projectListPage(this.req, this.res)
  243. })
  244. it('should create trigger ip matcher notifications', function (done) {
  245. this.settings.overleaf = true
  246. this.req.ip = '111.111.111.111'
  247. this.res.render = (pageName, opts) => {
  248. this.NotificationBuilder.promises.ipMatcherAffiliation.called.should.equal(
  249. true
  250. )
  251. done()
  252. }
  253. this.ProjectListController.projectListPage(this.req, this.res)
  254. })
  255. it('should send the projects', function (done) {
  256. this.res.render = (pageName, opts) => {
  257. opts.prefetchedProjectsBlob.projects.length.should.equal(
  258. this.projects.length +
  259. this.readAndWrite.length +
  260. this.readOnly.length +
  261. this.tokenReadAndWrite.length +
  262. this.tokenReadOnly.length
  263. )
  264. done()
  265. }
  266. this.ProjectListController.projectListPage(this.req, this.res)
  267. })
  268. it('should send the user', function (done) {
  269. this.res.render = (pageName, opts) => {
  270. opts.user.should.deep.equal(this.user)
  271. done()
  272. }
  273. this.ProjectListController.projectListPage(this.req, this.res)
  274. })
  275. it('should inject the users', function (done) {
  276. this.res.render = (pageName, opts) => {
  277. const projects = opts.prefetchedProjectsBlob.projects
  278. projects
  279. .filter(p => p.id === '1')[0]
  280. .owner.firstName.should.equal(
  281. this.users[this.projects.filter(p => p._id === 1)[0].owner_ref]
  282. .first_name
  283. )
  284. projects
  285. .filter(p => p.id === '2')[0]
  286. .owner.firstName.should.equal(
  287. this.users[this.projects.filter(p => p._id === 2)[0].owner_ref]
  288. .first_name
  289. )
  290. projects
  291. .filter(p => p.id === '2')[0]
  292. .lastUpdatedBy.firstName.should.equal(
  293. this.users[this.projects.filter(p => p._id === 2)[0].lastUpdatedBy]
  294. .first_name
  295. )
  296. done()
  297. }
  298. this.ProjectListController.projectListPage(this.req, this.res)
  299. })
  300. it("should send the user's best subscription when saas feature present", function (done) {
  301. this.Features.hasFeature.withArgs('saas').returns(true)
  302. this.res.render = (pageName, opts) => {
  303. expect(opts.usersBestSubscription).to.deep.include({ type: 'free' })
  304. done()
  305. }
  306. this.ProjectListController.projectListPage(this.req, this.res)
  307. })
  308. it('should not return a best subscription without saas feature', function (done) {
  309. this.Features.hasFeature.withArgs('saas').returns(false)
  310. this.res.render = (pageName, opts) => {
  311. expect(opts.usersBestSubscription).to.be.undefined
  312. done()
  313. }
  314. this.ProjectListController.projectListPage(this.req, this.res)
  315. })
  316. it('should show INR Banner for Indian users with free account', function (done) {
  317. // usersBestSubscription is only available when saas feature is present
  318. this.Features.hasFeature.withArgs('saas').returns(true)
  319. this.SubscriptionViewModelBuilder.promises.getBestSubscription.resolves({
  320. type: 'free',
  321. })
  322. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  323. countryCode: 'IN',
  324. })
  325. this.res.render = (pageName, opts) => {
  326. expect(opts.showInrGeoBanner).to.be.true
  327. done()
  328. }
  329. this.ProjectListController.projectListPage(this.req, this.res)
  330. })
  331. it('should not show INR Banner for Indian users with premium account', function (done) {
  332. // usersBestSubscription is only available when saas feature is present
  333. this.Features.hasFeature.withArgs('saas').returns(true)
  334. this.SubscriptionViewModelBuilder.promises.getBestSubscription.resolves({
  335. type: 'individual',
  336. })
  337. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  338. countryCode: 'IN',
  339. })
  340. this.res.render = (pageName, opts) => {
  341. expect(opts.showInrGeoBanner).to.be.false
  342. done()
  343. }
  344. this.ProjectListController.projectListPage(this.req, this.res)
  345. })
  346. describe('With Institution SSO feature', function () {
  347. beforeEach(function (done) {
  348. this.institutionEmail = 'test@overleaf.com'
  349. this.institutionName = 'Overleaf'
  350. this.Features.hasFeature.withArgs('saml').returns(true)
  351. this.Features.hasFeature.withArgs('affiliations').returns(true)
  352. this.Features.hasFeature.withArgs('saas').returns(true)
  353. done()
  354. })
  355. it('should show institution SSO available notification for confirmed domains', function () {
  356. this.UserGetter.promises.getUserFullEmails.resolves([
  357. {
  358. email: 'test@overleaf.com',
  359. affiliation: {
  360. institution: {
  361. id: 1,
  362. confirmed: true,
  363. name: 'Overleaf',
  364. ssoBeta: false,
  365. ssoEnabled: true,
  366. },
  367. },
  368. },
  369. ])
  370. this.res.render = (pageName, opts) => {
  371. expect(opts.notificationsInstitution).to.deep.include({
  372. email: this.institutionEmail,
  373. institutionId: 1,
  374. institutionName: this.institutionName,
  375. templateKey: 'notification_institution_sso_available',
  376. })
  377. }
  378. this.ProjectListController.projectListPage(this.req, this.res)
  379. })
  380. it('should show a linked notification', function () {
  381. this.req.session.saml = {
  382. institutionEmail: this.institutionEmail,
  383. linked: {
  384. hasEntitlement: false,
  385. universityName: this.institutionName,
  386. },
  387. }
  388. this.res.render = (pageName, opts) => {
  389. expect(opts.notificationsInstitution).to.deep.include({
  390. email: this.institutionEmail,
  391. institutionName: this.institutionName,
  392. templateKey: 'notification_institution_sso_linked',
  393. })
  394. }
  395. this.ProjectListController.projectListPage(this.req, this.res)
  396. })
  397. it('should show a linked another email notification', function () {
  398. // when they request to link an email but the institution returns
  399. // a different email
  400. this.res.render = (pageName, opts) => {
  401. expect(opts.notificationsInstitution).to.deep.include({
  402. institutionEmail: this.institutionEmail,
  403. requestedEmail: 'requested@overleaf.com',
  404. templateKey: 'notification_institution_sso_non_canonical',
  405. })
  406. }
  407. this.req.session.saml = {
  408. emailNonCanonical: this.institutionEmail,
  409. institutionEmail: this.institutionEmail,
  410. requestedEmail: 'requested@overleaf.com',
  411. linked: {
  412. hasEntitlement: false,
  413. universityName: this.institutionName,
  414. },
  415. }
  416. this.ProjectListController.projectListPage(this.req, this.res)
  417. })
  418. it('should show a notification when intent was to register via SSO but account existed', function () {
  419. this.res.render = (pageName, opts) => {
  420. expect(opts.notificationsInstitution).to.deep.include({
  421. email: this.institutionEmail,
  422. templateKey: 'notification_institution_sso_already_registered',
  423. })
  424. }
  425. this.req.session.saml = {
  426. institutionEmail: this.institutionEmail,
  427. linked: {
  428. hasEntitlement: false,
  429. universityName: 'Overleaf',
  430. },
  431. registerIntercept: {
  432. id: 1,
  433. name: 'Example University',
  434. },
  435. }
  436. this.ProjectListController.projectListPage(this.req, this.res)
  437. })
  438. it('should not show a register notification if the flow was abandoned', function () {
  439. // could initially start to register with an SSO email and then
  440. // abandon flow and login with an existing non-institution SSO email
  441. this.res.render = (pageName, opts) => {
  442. expect(opts.notificationsInstitution).to.deep.not.include({
  443. email: 'test@overleaf.com',
  444. templateKey: 'notification_institution_sso_already_registered',
  445. })
  446. }
  447. this.req.session.saml = {
  448. registerIntercept: {
  449. id: 1,
  450. name: 'Example University',
  451. },
  452. }
  453. this.ProjectListController.projectListPage(this.req, this.res)
  454. })
  455. it('should show error notification', function () {
  456. this.res.render = (pageName, opts) => {
  457. expect(opts.notificationsInstitution.length).to.equal(1)
  458. expect(opts.notificationsInstitution[0].templateKey).to.equal(
  459. 'notification_institution_sso_error'
  460. )
  461. expect(opts.notificationsInstitution[0].error).to.be.instanceof(
  462. Errors.SAMLAlreadyLinkedError
  463. )
  464. }
  465. this.req.session.saml = {
  466. institutionEmail: this.institutionEmail,
  467. error: new Errors.SAMLAlreadyLinkedError(),
  468. }
  469. this.ProjectListController.projectListPage(this.req, this.res)
  470. })
  471. describe('for an unconfirmed domain for an SSO institution', function () {
  472. beforeEach(function (done) {
  473. this.UserGetter.promises.getUserFullEmails.resolves([
  474. {
  475. email: 'test@overleaf-uncofirmed.com',
  476. affiliation: {
  477. institution: {
  478. id: 1,
  479. confirmed: false,
  480. name: 'Overleaf',
  481. ssoBeta: false,
  482. ssoEnabled: true,
  483. },
  484. },
  485. },
  486. ])
  487. done()
  488. })
  489. it('should not show institution SSO available notification', function () {
  490. this.res.render = (pageName, opts) => {
  491. expect(opts.notificationsInstitution.length).to.equal(0)
  492. }
  493. this.ProjectListController.projectListPage(this.req, this.res)
  494. })
  495. })
  496. describe('when linking/logging in initiated on institution side', function () {
  497. it('should not show a linked another email notification', function () {
  498. // this is only used when initated on Overleaf,
  499. // because we keep track of the requested email they tried to link
  500. this.res.render = (pageName, opts) => {
  501. expect(opts.notificationsInstitution).to.not.deep.include({
  502. institutionEmail: this.institutionEmail,
  503. requestedEmail: undefined,
  504. templateKey: 'notification_institution_sso_non_canonical',
  505. })
  506. }
  507. this.req.session.saml = {
  508. emailNonCanonical: this.institutionEmail,
  509. institutionEmail: this.institutionEmail,
  510. linked: {
  511. hasEntitlement: false,
  512. universityName: this.institutionName,
  513. },
  514. }
  515. this.ProjectListController.projectListPage(this.req, this.res)
  516. })
  517. })
  518. describe('Institution with SSO beta testable', function () {
  519. beforeEach(function (done) {
  520. this.UserGetter.promises.getUserFullEmails.resolves([
  521. {
  522. email: 'beta@beta.com',
  523. affiliation: {
  524. institution: {
  525. id: 2,
  526. confirmed: true,
  527. name: 'Beta University',
  528. ssoBeta: true,
  529. ssoEnabled: false,
  530. },
  531. },
  532. },
  533. ])
  534. done()
  535. })
  536. it('should show institution SSO available notification when on a beta testing session', function () {
  537. this.req.session.samlBeta = true
  538. this.res.render = (pageName, opts) => {
  539. expect(opts.notificationsInstitution).to.deep.include({
  540. email: 'beta@beta.com',
  541. institutionId: 2,
  542. institutionName: 'Beta University',
  543. templateKey: 'notification_institution_sso_available',
  544. })
  545. }
  546. this.ProjectListController.projectListPage(this.req, this.res)
  547. })
  548. it('should not show institution SSO available notification when not on a beta testing session', function () {
  549. this.req.session.samlBeta = false
  550. this.res.render = (pageName, opts) => {
  551. expect(opts.notificationsInstitution).to.deep.not.include({
  552. email: 'test@overleaf.com',
  553. institutionId: 1,
  554. institutionName: 'Overleaf',
  555. templateKey: 'notification_institution_sso_available',
  556. })
  557. }
  558. this.ProjectListController.projectListPage(this.req, this.res)
  559. })
  560. })
  561. })
  562. describe('Without Institution SSO feature', function () {
  563. beforeEach(function (done) {
  564. this.Features.hasFeature.withArgs('saml').returns(false)
  565. done()
  566. })
  567. it('should not show institution sso available notification', function () {
  568. this.res.render = (pageName, opts) => {
  569. expect(opts.notificationsInstitution).to.deep.not.include({
  570. email: 'test@overleaf.com',
  571. institutionId: 1,
  572. institutionName: 'Overleaf',
  573. templateKey: 'notification_institution_sso_available',
  574. })
  575. }
  576. this.ProjectListController.projectListPage(this.req, this.res)
  577. })
  578. })
  579. describe('enterprise banner', function () {
  580. beforeEach(function (done) {
  581. this.Features.hasFeature.withArgs('saas').returns(true)
  582. this.LimitationsManager.promises.userIsMemberOfGroupSubscription.resolves(
  583. { isMember: false }
  584. )
  585. this.UserGetter.promises.getUserFullEmails.resolves([
  586. {
  587. email: 'test@test-domain.com',
  588. },
  589. ])
  590. done()
  591. })
  592. describe('normal enterprise banner', function () {
  593. it('shows banner', function () {
  594. this.res.render = (pageName, opts) => {
  595. expect(opts.showGroupsAndEnterpriseBanner).to.be.true
  596. }
  597. this.ProjectListController.projectListPage(this.req, this.res)
  598. })
  599. it('does not show banner if user is part of any affiliation', function () {
  600. this.UserGetter.promises.getUserFullEmails.resolves([
  601. {
  602. email: 'test@overleaf.com',
  603. affiliation: {
  604. licence: 'pro_plus',
  605. institution: {
  606. id: 1,
  607. confirmed: true,
  608. name: 'Overleaf',
  609. ssoBeta: false,
  610. ssoEnabled: true,
  611. },
  612. },
  613. },
  614. ])
  615. this.res.render = (pageName, opts) => {
  616. expect(opts.showGroupsAndEnterpriseBanner).to.be.false
  617. }
  618. this.ProjectListController.projectListPage(this.req, this.res)
  619. })
  620. it('does not show banner if user is part of any group subscription', function () {
  621. this.LimitationsManager.promises.userIsMemberOfGroupSubscription.resolves(
  622. { isMember: true }
  623. )
  624. this.res.render = (pageName, opts) => {
  625. expect(opts.showGroupsAndEnterpriseBanner).to.be.false
  626. }
  627. this.ProjectListController.projectListPage(this.req, this.res)
  628. })
  629. it('have a banner variant of "FOMO" or "on-premise"', function () {
  630. this.res.render = (pageName, opts) => {
  631. expect(opts.groupsAndEnterpriseBannerVariant).to.be.oneOf([
  632. 'FOMO',
  633. 'on-premise',
  634. ])
  635. }
  636. this.ProjectListController.projectListPage(this.req, this.res)
  637. })
  638. })
  639. describe('US government enterprise banner', function () {
  640. it('does not show enterprise banner if US government enterprise banner is shown', function () {
  641. const emails = [
  642. {
  643. email: 'test@test.mil',
  644. confirmedAt: new Date('2024-01-01'),
  645. },
  646. ]
  647. this.UserGetter.promises.getUserFullEmails.resolves(emails)
  648. this.Modules.promises.hooks.fire
  649. .withArgs('getUSGovBanner', emails, false, false)
  650. .resolves([
  651. {
  652. showUSGovBanner: true,
  653. usGovBannerVariant: 'variant',
  654. },
  655. ])
  656. this.res.render = (pageName, opts) => {
  657. expect(opts.showGroupsAndEnterpriseBanner).to.be.false
  658. expect(opts.showUSGovBanner).to.be.true
  659. }
  660. this.ProjectListController.projectListPage(this.req, this.res)
  661. })
  662. })
  663. })
  664. })
  665. describe('projectListReactPage with duplicate projects', function () {
  666. beforeEach(function () {
  667. this.projects = [
  668. { _id: 1, lastUpdated: 1, owner_ref: 'user-1' },
  669. { _id: 2, lastUpdated: 2, owner_ref: 'user-2' },
  670. ]
  671. this.readAndWrite = [{ _id: 5, lastUpdated: 5, owner_ref: 'user-1' }]
  672. this.readOnly = [{ _id: 3, lastUpdated: 3, owner_ref: 'user-1' }]
  673. this.tokenReadAndWrite = [{ _id: 6, lastUpdated: 5, owner_ref: 'user-4' }]
  674. this.tokenReadOnly = [
  675. { _id: 6, lastUpdated: 5, owner_ref: 'user-4' }, // Also in tokenReadAndWrite
  676. { _id: 7, lastUpdated: 4, owner_ref: 'user-5' },
  677. ]
  678. this.allProjects = {
  679. owned: this.projects,
  680. readAndWrite: this.readAndWrite,
  681. readOnly: this.readOnly,
  682. tokenReadAndWrite: this.tokenReadAndWrite,
  683. tokenReadOnly: this.tokenReadOnly,
  684. }
  685. this.ProjectGetter.promises.findAllUsersProjects.resolves(
  686. this.allProjects
  687. )
  688. })
  689. it('should render the project/list-react page', function (done) {
  690. this.res.render = (pageName, opts) => {
  691. pageName.should.equal('project/list-react')
  692. done()
  693. }
  694. this.ProjectListController.projectListPage(this.req, this.res)
  695. })
  696. it('should omit one of the projects', function (done) {
  697. this.res.render = (pageName, opts) => {
  698. opts.prefetchedProjectsBlob.projects.length.should.equal(
  699. this.projects.length +
  700. this.readAndWrite.length +
  701. this.readOnly.length +
  702. this.tokenReadAndWrite.length +
  703. this.tokenReadOnly.length -
  704. 1
  705. )
  706. done()
  707. }
  708. this.ProjectListController.projectListPage(this.req, this.res)
  709. })
  710. })
  711. })