| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107 |
- import { expect, vi } from 'vitest'
- import sinon from 'sinon'
- import mongodb from 'mongodb-legacy'
- import Errors from '../../../../app/src/Features/Errors/Errors.js'
- const ObjectId = mongodb.ObjectId
- const MODULE_PATH = `${import.meta.dirname}/../../../../app/src/Features/Project/ProjectListController`
- // Mock AnalyticsManager as it isn't used in these tests but causes the User model to be imported
- // TODO: remove this once all models are ESM and this kind of mocking is no longer necessary
- vi.mock('../../../../app/src/Features/Analytics/AnalyticsManager.js', () => {
- return {}
- })
- describe('ProjectListController', function () {
- beforeEach(async function (ctx) {
- ctx.project_id = new ObjectId('abcdefabcdefabcdefabcdef')
- ctx.user = {
- _id: new ObjectId('123456123456123456123456'),
- email: 'test@overleaf.com',
- first_name: 'bjkdsjfk',
- features: {},
- emails: [{ email: 'test@overleaf.com' }],
- lastActive: new Date(2),
- signUpDate: new Date(1),
- lastLoginIp: '111.111.111.112',
- ace: {
- syntaxValidation: true,
- pdfViewer: 'pdfjs',
- spellCheckLanguage: 'en',
- autoPairDelimiters: true,
- autoComplete: true,
- fontSize: 12,
- theme: 'textmate',
- mode: 'none',
- },
- }
- ctx.users = {
- 'user-1': {
- first_name: 'James',
- },
- 'user-2': {
- first_name: 'Henry',
- },
- }
- ctx.users[ctx.user._id] = ctx.user // Owner
- ctx.usersArr = Object.entries(ctx.users).map(([key, value]) => ({
- _id: key,
- ...value,
- }))
- ctx.tags = [
- { name: 1, project_ids: ['1', '2', '3'] },
- { name: 2, project_ids: ['a', '1'] },
- { name: 3, project_ids: ['a', 'b', 'c', 'd'] },
- ]
- ctx.notifications = [
- {
- _id: '1',
- user_id: '2',
- templateKey: '3',
- messageOpts: '4',
- key: '5',
- },
- ]
- ctx.settings = {
- siteUrl: 'https://overleaf.com',
- }
- ctx.onboardingDataCollection = {
- companyDivisionDepartment: '',
- companyJobTitle: '',
- firstName: 'Dos',
- governmentJobTitle: '',
- institutionName: '',
- lastName: 'Mukasan',
- nonprofitDivisionDepartment: '',
- nonprofitJobTitle: '',
- otherJobTitle: '',
- primaryOccupation: 'company',
- role: 'conductor',
- subjectArea: 'music',
- updatedAt: '2025-09-04T12:12:21.628Z',
- usedLatex: 'occasionally',
- }
- ctx.TagsHandler = {
- promises: {
- getAllTags: sinon.stub().resolves(ctx.tags),
- },
- }
- ctx.NotificationsHandler = {
- promises: {
- getUserNotifications: sinon.stub().resolves(ctx.notifications),
- },
- }
- ctx.UserModel = {
- findById: sinon.stub().resolves(ctx.user),
- }
- ctx.OnboardingDataCollectionModel = {
- findById: sinon.stub().resolves(ctx.onboardingDataCollection),
- }
- ctx.UserPrimaryEmailCheckHandler = {
- requiresPrimaryEmailCheck: sinon.stub().returns(false),
- }
- ctx.ProjectGetter = {
- promises: {
- findAllUsersProjects: sinon.stub(),
- },
- }
- ctx.ProjectHelper = {
- isArchived: sinon.stub(),
- isTrashed: sinon.stub(),
- }
- ctx.SessionManager = {
- getLoggedInUserId: sinon.stub().returns(ctx.user._id),
- }
- ctx.UserController = {
- logout: sinon.stub(),
- }
- ctx.UserGetter = {
- promises: {
- getUsers: sinon.stub().resolves(ctx.usersArr),
- getUserFullEmails: sinon.stub().resolves([]),
- getWritefullData: sinon.stub().resolves({ isPremium: true }),
- },
- }
- ctx.Features = {
- hasFeature: sinon.stub(),
- }
- ctx.Metrics = {
- inc: sinon.stub(),
- }
- ctx.SplitTestHandler = {
- promises: {
- getAssignment: sinon.stub().resolves({ variant: 'default' }),
- hasUserBeenAssignedToVariant: sinon.stub().resolves(false),
- },
- }
- ctx.SplitTestSessionHandler = {
- promises: {
- sessionMaintenance: sinon.stub().resolves(),
- },
- }
- ctx.SubscriptionViewModelBuilder = {
- promises: {
- getUsersSubscriptionDetails: sinon.stub().resolves({
- bestSubscription: { type: 'free' },
- individualSubscription: null,
- memberGroupSubscriptions: [],
- }),
- },
- }
- ctx.SurveyHandler = {
- promises: {
- getSurvey: sinon.stub().resolves({}),
- },
- }
- ctx.NotificationBuilder = {
- promises: {
- ipMatcherAffiliation: sinon.stub().returns({ create: sinon.stub() }),
- },
- }
- ctx.GeoIpLookup = {
- promises: {
- getCurrencyCode: sinon.stub().resolves({
- countryCode: 'US',
- currencyCode: 'USD',
- }),
- },
- }
- ctx.TutorialHandler = {
- getInactiveTutorials: sinon.stub().returns([]),
- }
- ctx.Modules = {
- promises: {
- hooks: {
- fire: sinon.stub().resolves([]),
- },
- },
- }
- ctx.PermissionsManager = {
- promises: {
- checkUserPermissions: sinon.stub().resolves(true),
- },
- }
- ctx.SubscriptionLocator = {
- promises: {
- getUsersSubscription: sinon.stub().resolves({}),
- },
- }
- vi.doMock('mongodb-legacy', () => ({
- default: { ObjectId },
- }))
- vi.doMock('@overleaf/settings', () => ({
- default: ctx.settings,
- }))
- vi.doMock('@overleaf/metrics', () => ({
- default: ctx.Metrics,
- }))
- vi.doMock(
- '../../../../app/src/Features/SplitTests/SplitTestHandler',
- () => ({
- default: ctx.SplitTestHandler,
- })
- )
- vi.doMock(
- '../../../../app/src/Features/SplitTests/SplitTestSessionHandler',
- () => ({
- default: ctx.SplitTestSessionHandler,
- })
- )
- vi.doMock('../../../../app/src/Features/User/UserController', () => ({
- default: ctx.UserController,
- }))
- vi.doMock('../../../../app/src/Features/Project/ProjectHelper', () => ({
- default: ctx.ProjectHelper,
- }))
- vi.doMock('../../../../app/src/Features/Tags/TagsHandler', () => ({
- default: ctx.TagsHandler,
- }))
- vi.doMock(
- '../../../../app/src/Features/Notifications/NotificationsHandler',
- () => ({
- default: ctx.NotificationsHandler,
- })
- )
- vi.doMock('../../../../app/src/models/User', () => ({
- User: ctx.UserModel,
- }))
- vi.doMock('../../../../app/src/models/OnboardingDataCollection', () => ({
- OnboardingDataCollection: ctx.OnboardingDataCollectionModel,
- }))
- vi.doMock('../../../../app/src/Features/Project/ProjectGetter', () => ({
- default: ctx.ProjectGetter,
- }))
- vi.doMock(
- '../../../../app/src/Features/Authentication/SessionManager',
- () => ({
- default: ctx.SessionManager,
- })
- )
- vi.doMock('../../../../app/src/infrastructure/Features', () => ({
- default: ctx.Features,
- }))
- vi.doMock('../../../../app/src/Features/User/UserGetter', () => ({
- default: ctx.UserGetter,
- }))
- vi.doMock(
- '../../../../app/src/Features/Subscription/SubscriptionViewModelBuilder',
- () => ({
- default: ctx.SubscriptionViewModelBuilder,
- })
- )
- vi.doMock('../../../../app/src/infrastructure/Modules', () => ({
- default: ctx.Modules,
- }))
- vi.doMock('../../../../app/src/Features/Survey/SurveyHandler', () => ({
- default: ctx.SurveyHandler,
- }))
- vi.doMock(
- '../../../../app/src/Features/User/UserPrimaryEmailCheckHandler',
- () => ({
- default: ctx.UserPrimaryEmailCheckHandler,
- })
- )
- vi.doMock(
- '../../../../app/src/Features/Notifications/NotificationsBuilder',
- () => ({
- default: ctx.NotificationBuilder,
- })
- )
- vi.doMock('../../../../app/src/infrastructure/GeoIpLookup', () => ({
- default: ctx.GeoIpLookup,
- }))
- vi.doMock('../../../../app/src/Features/Tutorial/TutorialHandler', () => ({
- default: ctx.TutorialHandler,
- }))
- vi.doMock(
- '../../../../app/src/Features/Authorization/PermissionsManager',
- () => ({
- default: ctx.PermissionsManager,
- })
- )
- vi.doMock(
- '../../../../app/src/Features/Subscription/SubscriptionLocator',
- () => ({
- default: ctx.SubscriptionLocator,
- })
- )
- ctx.ProjectListController = (await import(MODULE_PATH)).default
- ctx.req = {
- query: {},
- params: {
- Project_id: ctx.project_id,
- },
- headers: {},
- session: {
- user: ctx.user,
- },
- body: {},
- i18n: {
- translate() {},
- },
- }
- ctx.res = {}
- })
- describe('projectListPage', function () {
- beforeEach(function (ctx) {
- ctx.projects = [
- { _id: 1, lastUpdated: new Date(1), owner_ref: 'user-1' },
- {
- _id: 2,
- lastUpdated: new Date(2),
- owner_ref: 'user-2',
- lastUpdatedBy: 'user-1',
- },
- ]
- ctx.readAndWrite = [
- { _id: 5, lastUpdated: new Date(5), owner_ref: 'user-1' },
- ]
- ctx.readOnly = [{ _id: 3, lastUpdated: new Date(3), owner_ref: 'user-1' }]
- ctx.tokenReadAndWrite = [
- { _id: 6, lastUpdated: new Date(5), owner_ref: 'user-4' },
- ]
- ctx.tokenReadOnly = [
- { _id: 7, lastUpdated: new Date(4), owner_ref: 'user-5' },
- ]
- ctx.review = [{ _id: 8, lastUpdated: new Date(4), owner_ref: 'user-6' }]
- ctx.allProjects = {
- owned: ctx.projects,
- readAndWrite: ctx.readAndWrite,
- readOnly: ctx.readOnly,
- tokenReadAndWrite: ctx.tokenReadAndWrite,
- tokenReadOnly: ctx.tokenReadOnly,
- review: ctx.review,
- }
- ctx.ProjectGetter.promises.findAllUsersProjects.resolves(ctx.allProjects)
- })
- it('should render the project/list-react page', async function (ctx) {
- await new Promise(resolve => {
- ctx.res.render = (pageName, opts) => {
- pageName.should.equal('project/list-react')
- resolve()
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- })
- it('should invoke the session maintenance', async function (ctx) {
- await new Promise(resolve => {
- ctx.Features.hasFeature.withArgs('saas').returns(true)
- ctx.res.render = () => {
- ctx.SplitTestSessionHandler.promises.sessionMaintenance.should.have.been.calledWith(
- ctx.req,
- ctx.user
- )
- resolve()
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- })
- it('should send the tags', async function (ctx) {
- await new Promise(resolve => {
- ctx.res.render = (pageName, opts) => {
- opts.tags.length.should.equal(ctx.tags.length)
- resolve()
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- })
- it('should create trigger ip matcher notifications', async function (ctx) {
- await new Promise(resolve => {
- ctx.settings.overleaf = true
- ctx.req.ip = '111.111.111.111'
- ctx.res.render = (pageName, opts) => {
- ctx.NotificationBuilder.promises.ipMatcherAffiliation.called.should.equal(
- true
- )
- resolve()
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- })
- it('should send the projects', async function (ctx) {
- await new Promise(resolve => {
- ctx.res.render = (pageName, opts) => {
- opts.prefetchedProjectsBlob.projects.length.should.equal(
- ctx.projects.length +
- ctx.readAndWrite.length +
- ctx.readOnly.length +
- ctx.tokenReadAndWrite.length +
- ctx.tokenReadOnly.length +
- ctx.review.length
- )
- resolve()
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- })
- it('should send the user', async function (ctx) {
- await new Promise(resolve => {
- ctx.res.render = (pageName, opts) => {
- opts.user.should.deep.equal(ctx.user)
- resolve()
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- })
- it('should inject the users', async function (ctx) {
- await new Promise(resolve => {
- ctx.res.render = (pageName, opts) => {
- const projects = opts.prefetchedProjectsBlob.projects
- projects
- .filter(p => p.id === '1')[0]
- .owner.firstName.should.equal(
- ctx.users[ctx.projects.filter(p => p._id === 1)[0].owner_ref]
- .first_name
- )
- projects
- .filter(p => p.id === '2')[0]
- .owner.firstName.should.equal(
- ctx.users[ctx.projects.filter(p => p._id === 2)[0].owner_ref]
- .first_name
- )
- projects
- .filter(p => p.id === '2')[0]
- .lastUpdatedBy.firstName.should.equal(
- ctx.users[ctx.projects.filter(p => p._id === 2)[0].lastUpdatedBy]
- .first_name
- )
- resolve()
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- })
- it("should send the user's best subscription when saas feature present", async function (ctx) {
- await new Promise(resolve => {
- ctx.Features.hasFeature.withArgs('saas').returns(true)
- ctx.res.render = (pageName, opts) => {
- expect(opts.usersBestSubscription).to.deep.include({ type: 'free' })
- resolve()
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- })
- it('should not return a best subscription without saas feature', async function (ctx) {
- await new Promise(resolve => {
- ctx.Features.hasFeature.withArgs('saas').returns(false)
- ctx.res.render = (pageName, opts) => {
- expect(opts.usersBestSubscription).to.be.undefined
- resolve()
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- })
- it('should show INR Banner for Indian users with free account', async function (ctx) {
- await new Promise(resolve => {
- // usersBestSubscription is only available when saas feature is present
- ctx.Features.hasFeature.withArgs('saas').returns(true)
- ctx.SubscriptionViewModelBuilder.promises.getUsersSubscriptionDetails.resolves(
- {
- bestSubscription: {
- type: 'free',
- },
- }
- )
- ctx.GeoIpLookup.promises.getCurrencyCode.resolves({
- countryCode: 'IN',
- })
- ctx.res.render = (pageName, opts) => {
- expect(opts.showInrGeoBanner).to.be.true
- resolve()
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- })
- it('should not show INR Banner for Indian users with premium account', async function (ctx) {
- await new Promise(resolve => {
- // usersBestSubscription is only available when saas feature is present
- ctx.Features.hasFeature.withArgs('saas').returns(true)
- ctx.SubscriptionViewModelBuilder.promises.getUsersSubscriptionDetails.resolves(
- {
- bestSubscription: {
- type: 'individual',
- },
- }
- )
- ctx.GeoIpLookup.promises.getCurrencyCode.resolves({
- countryCode: 'IN',
- })
- ctx.res.render = (pageName, opts) => {
- expect(opts.showInrGeoBanner).to.be.false
- resolve()
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- })
- it('should redirect to domain capture page', async function (ctx) {
- await new Promise(resolve => {
- ctx.Features.hasFeature.withArgs('saas').returns(true)
- ctx.SplitTestHandler.promises.getAssignment
- .withArgs(ctx.req, ctx.res, 'domain-capture-redirect')
- .resolves({ variant: 'enabled' })
- ctx.Modules.promises.hooks.fire
- .withArgs('findDomainCaptureGroupUserCouldBePartOf', ctx.user._id)
- .resolves([{ _id: new ObjectId(), managedUsersEnabled: true }])
- ctx.res.redirect = url => {
- url.should.equal('/domain-capture')
- resolve()
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- })
- describe('when user linked to SSO', function () {
- const linkedEmail = 'picard@starfleet.com'
- const universityName = 'Starfleet'
- const notificationData = {
- email: linkedEmail,
- institutionName: universityName,
- }
- beforeEach(function (ctx) {
- ctx.Features.hasFeature.withArgs('saml').returns(true)
- ctx.req.session.saml = {
- institutionEmail: linkedEmail,
- linked: {
- universityName,
- },
- }
- })
- it('should render with Commons template when Commons was linked', async function (ctx) {
- await new Promise(resolve => {
- ctx.res.render = (pageName, opts) => {
- expect(opts.notificationsInstitution).to.deep.equal([
- Object.assign(
- { templateKey: 'notification_institution_sso_linked' },
- notificationData
- ),
- ])
- resolve()
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- })
- describe('when via domain capture', function () {
- beforeEach(function (ctx) {
- ctx.req.session.saml.domainCaptureEnabled = true
- })
- it('should render with group template', async function (ctx) {
- await new Promise(resolve => {
- ctx.res.render = (pageName, opts) => {
- expect(opts.notificationsInstitution).to.deep.equal([
- Object.assign(
- { templateKey: 'notification_group_sso_linked' },
- notificationData
- ),
- ])
- resolve()
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- })
- describe('user created via domain capture and group is managed', function () {
- beforeEach(function (ctx) {
- ctx.req.session.saml.userCreatedViaDomainCapture = true
- })
- it('should render with notification_group_sso_linked', async function (ctx) {
- await new Promise(resolve => {
- ctx.res.render = (pageName, opts) => {
- expect(opts.notificationsInstitution).to.deep.equal([
- Object.assign(
- {
- templateKey: 'notification_group_sso_linked',
- },
- notificationData
- ),
- ])
- resolve()
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- })
- it('should render with notification_account_created_via_group_domain_capture_and_managed_users_enabled when managed user is enabled', async function (ctx) {
- ctx.req.session.saml.managedUsersEnabled = true
- await new Promise(resolve => {
- ctx.res.render = (pageName, opts) => {
- expect(opts.notificationsInstitution).to.deep.equal([
- Object.assign(
- {
- templateKey:
- 'notification_account_created_via_group_domain_capture_and_managed_users_enabled',
- },
- notificationData
- ),
- ])
- resolve()
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- })
- })
- })
- })
- describe('With Institution SSO feature', function () {
- beforeEach(async function (ctx) {
- await new Promise(resolve => {
- ctx.institutionEmail = 'test@overleaf.com'
- ctx.institutionName = 'Overleaf'
- ctx.Features.hasFeature.withArgs('saml').returns(true)
- ctx.Features.hasFeature.withArgs('affiliations').returns(true)
- ctx.Features.hasFeature.withArgs('saas').returns(true)
- resolve()
- })
- })
- it('should show institution SSO available notification for confirmed domains', function (ctx) {
- ctx.UserGetter.promises.getUserFullEmails.resolves([
- {
- email: 'test@overleaf.com',
- affiliation: {
- institution: {
- id: 1,
- confirmed: true,
- name: 'Overleaf',
- ssoBeta: false,
- ssoEnabled: true,
- },
- },
- },
- ])
- ctx.res.render = (pageName, opts) => {
- expect(opts.notificationsInstitution).to.deep.include({
- email: ctx.institutionEmail,
- institutionId: 1,
- institutionName: ctx.institutionName,
- templateKey: 'notification_institution_sso_available',
- })
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- it('should show a linked notification', function (ctx) {
- ctx.req.session.saml = {
- institutionEmail: ctx.institutionEmail,
- linked: {
- hasEntitlement: false,
- universityName: ctx.institutionName,
- },
- }
- ctx.res.render = (pageName, opts) => {
- expect(opts.notificationsInstitution).to.deep.include({
- email: ctx.institutionEmail,
- institutionName: ctx.institutionName,
- templateKey: 'notification_institution_sso_linked',
- })
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- it('should show a group linked notification when domain capture enabled', function (ctx) {
- ctx.req.session.saml = {
- institutionEmail: ctx.institutionEmail,
- linked: {
- hasEntitlement: false,
- universityName: ctx.institutionName,
- },
- domainCaptureEnabled: true,
- }
- ctx.res.render = (pageName, opts) => {
- expect(opts.notificationsInstitution).to.deep.include({
- email: ctx.institutionEmail,
- institutionName: ctx.institutionName,
- templateKey: 'notification_group_sso_linked',
- })
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- it('should show a success notification when joining group via domain capture page', function (ctx) {
- ctx.req.session.saml = {
- linkedGroup: true,
- universityName: ctx.institutionName,
- domainCaptureJoin: true,
- }
- ctx.res.render = (pageName, opts) => {
- expect(opts).to.deep.include({
- groupSsoSetupSuccess: true,
- joinedGroupName: ctx.institutionName,
- viaDomainCapture: true,
- })
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- it('should show a linked another email notification', function (ctx) {
- // when they request to link an email but the institution returns
- // a different email
- ctx.res.render = (pageName, opts) => {
- expect(opts.notificationsInstitution).to.deep.include({
- institutionEmail: ctx.institutionEmail,
- requestedEmail: 'requested@overleaf.com',
- templateKey: 'notification_institution_sso_non_canonical',
- })
- }
- ctx.req.session.saml = {
- emailNonCanonical: ctx.institutionEmail,
- institutionEmail: ctx.institutionEmail,
- requestedEmail: 'requested@overleaf.com',
- linked: {
- hasEntitlement: false,
- universityName: ctx.institutionName,
- },
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- it('should show a notification when intent was to register via SSO but account existed', function (ctx) {
- ctx.res.render = (pageName, opts) => {
- expect(opts.notificationsInstitution).to.deep.include({
- email: ctx.institutionEmail,
- templateKey: 'notification_institution_sso_already_registered',
- })
- }
- ctx.req.session.saml = {
- institutionEmail: ctx.institutionEmail,
- linked: {
- hasEntitlement: false,
- universityName: 'Overleaf',
- },
- registerIntercept: {
- id: 1,
- name: 'Example University',
- },
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- it('should not show a register notification if the flow was abandoned', function (ctx) {
- // could initially start to register with an SSO email and then
- // abandon flow and login with an existing non-institution SSO email
- ctx.res.render = (pageName, opts) => {
- expect(opts.notificationsInstitution).to.deep.not.include({
- email: 'test@overleaf.com',
- templateKey: 'notification_institution_sso_already_registered',
- })
- }
- ctx.req.session.saml = {
- registerIntercept: {
- id: 1,
- name: 'Example University',
- },
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- it('should show error notification', function (ctx) {
- ctx.res.render = (pageName, opts) => {
- expect(opts.notificationsInstitution.length).to.equal(1)
- expect(opts.notificationsInstitution[0].templateKey).to.equal(
- 'notification_institution_sso_error'
- )
- expect(opts.notificationsInstitution[0].error).to.be.instanceof(
- Errors.SAMLAlreadyLinkedError
- )
- }
- ctx.req.session.saml = {
- institutionEmail: ctx.institutionEmail,
- error: new Errors.SAMLAlreadyLinkedError(),
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- describe('for an unconfirmed domain for an SSO institution', function () {
- beforeEach(async function (ctx) {
- await new Promise(resolve => {
- ctx.UserGetter.promises.getUserFullEmails.resolves([
- {
- email: 'test@overleaf-uncofirmed.com',
- affiliation: {
- institution: {
- id: 1,
- confirmed: false,
- name: 'Overleaf',
- ssoBeta: false,
- ssoEnabled: true,
- },
- },
- },
- ])
- resolve()
- })
- })
- it('should not show institution SSO available notification', function (ctx) {
- ctx.res.render = (pageName, opts) => {
- expect(opts.notificationsInstitution.length).to.equal(0)
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- })
- describe('when linking/logging in initiated on institution side', function () {
- it('should not show a linked another email notification', function (ctx) {
- // this is only used when initated on Overleaf,
- // because we keep track of the requested email they tried to link
- ctx.res.render = (pageName, opts) => {
- expect(opts.notificationsInstitution).to.not.deep.include({
- institutionEmail: ctx.institutionEmail,
- requestedEmail: undefined,
- templateKey: 'notification_institution_sso_non_canonical',
- })
- }
- ctx.req.session.saml = {
- emailNonCanonical: ctx.institutionEmail,
- institutionEmail: ctx.institutionEmail,
- linked: {
- hasEntitlement: false,
- universityName: ctx.institutionName,
- },
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- })
- describe('Institution with SSO beta testable', function () {
- beforeEach(async function (ctx) {
- await new Promise(resolve => {
- ctx.UserGetter.promises.getUserFullEmails.resolves([
- {
- email: 'beta@beta.com',
- affiliation: {
- institution: {
- id: 2,
- confirmed: true,
- name: 'Beta University',
- ssoBeta: true,
- ssoEnabled: false,
- },
- },
- },
- ])
- resolve()
- })
- })
- it('should show institution SSO available notification when on a beta testing session', function (ctx) {
- ctx.req.session.samlBeta = true
- ctx.res.render = (pageName, opts) => {
- expect(opts.notificationsInstitution).to.deep.include({
- email: 'beta@beta.com',
- institutionId: 2,
- institutionName: 'Beta University',
- templateKey: 'notification_institution_sso_available',
- })
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- it('should not show institution SSO available notification when not on a beta testing session', function (ctx) {
- ctx.req.session.samlBeta = false
- ctx.res.render = (pageName, opts) => {
- expect(opts.notificationsInstitution).to.deep.not.include({
- email: 'test@overleaf.com',
- institutionId: 1,
- institutionName: 'Overleaf',
- templateKey: 'notification_institution_sso_available',
- })
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- })
- describe('group domain capture enabled for domain', function () {
- it('does not show institution SSO available notification', function (ctx) {
- ctx.UserGetter.promises.getUserFullEmails.resolves([
- {
- email: 'test@overleaf.com',
- affiliation: {
- group: { domainCaptureEnabled: true },
- institution: {
- id: 1,
- confirmed: true,
- name: 'Overleaf',
- ssoBeta: false,
- ssoEnabled: true,
- },
- },
- },
- ])
- ctx.res.render = (pageName, opts) => {
- expect(opts.notificationsInstitution).to.deep.equal([])
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- }
- })
- })
- })
- describe('Without Institution SSO feature', function () {
- beforeEach(async function (ctx) {
- await new Promise(resolve => {
- ctx.Features.hasFeature.withArgs('saml').returns(false)
- resolve()
- })
- })
- it('should not show institution sso available notification', function (ctx) {
- ctx.res.render = (pageName, opts) => {
- expect(opts.notificationsInstitution).to.deep.not.include({
- email: 'test@overleaf.com',
- institutionId: 1,
- institutionName: 'Overleaf',
- templateKey: 'notification_institution_sso_available',
- })
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- })
- describe('enterprise banner', function () {
- beforeEach(function (ctx) {
- ctx.Features.hasFeature.withArgs('saas').returns(true)
- ctx.SubscriptionViewModelBuilder.promises.getUsersSubscriptionDetails.resolves(
- { memberGroupSubscriptions: [] }
- )
- ctx.UserGetter.promises.getUserFullEmails.resolves([
- {
- email: 'test@test-domain.com',
- },
- ])
- })
- describe('normal enterprise banner', function () {
- it('shows banner', function (ctx) {
- ctx.res.render = (pageName, opts) => {
- expect(opts.showGroupsAndEnterpriseBanner).to.be.true
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- it('does not show banner if user is part of any affiliation', function (ctx) {
- ctx.UserGetter.promises.getUserFullEmails.resolves([
- {
- email: 'test@overleaf.com',
- affiliation: {
- licence: 'pro_plus',
- institution: {
- id: 1,
- confirmed: true,
- name: 'Overleaf',
- ssoBeta: false,
- ssoEnabled: true,
- },
- },
- },
- ])
- ctx.res.render = (pageName, opts) => {
- expect(opts.showGroupsAndEnterpriseBanner).to.be.false
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- it('does not show banner if user is part of any group subscription', function (ctx) {
- ctx.SubscriptionViewModelBuilder.promises.getUsersSubscriptionDetails.resolves(
- { memberGroupSubscriptions: [{}] }
- )
- ctx.res.render = (pageName, opts) => {
- expect(opts.showGroupsAndEnterpriseBanner).to.be.false
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- it('have a banner variant of "FOMO" or "on-premise"', function (ctx) {
- ctx.res.render = (pageName, opts) => {
- expect(opts.groupsAndEnterpriseBannerVariant).to.be.oneOf([
- 'FOMO',
- 'on-premise',
- ])
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- })
- describe('US government enterprise banner', function () {
- it('does not show enterprise banner if US government enterprise banner is shown', function (ctx) {
- const emails = [
- {
- email: 'test@test.mil',
- confirmedAt: new Date('2024-01-01'),
- },
- ]
- ctx.UserGetter.promises.getUserFullEmails.resolves(emails)
- ctx.Modules.promises.hooks.fire
- .withArgs('getUSGovBanner', emails, false, [])
- .resolves([
- {
- showUSGovBanner: true,
- usGovBannerVariant: 'variant',
- },
- ])
- ctx.res.render = (pageName, opts) => {
- expect(opts.showGroupsAndEnterpriseBanner).to.be.false
- expect(opts.showUSGovBanner).to.be.true
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- })
- })
- })
- describe('projectListReactPage with duplicate projects', function () {
- beforeEach(function (ctx) {
- ctx.projects = [
- { _id: 1, lastUpdated: new Date(1), owner_ref: 'user-1' },
- { _id: 2, lastUpdated: new Date(2), owner_ref: 'user-2' },
- ]
- ctx.readAndWrite = [
- { _id: 5, lastUpdated: new Date(5), owner_ref: 'user-1' },
- ]
- ctx.readOnly = [{ _id: 3, lastUpdated: new Date(3), owner_ref: 'user-1' }]
- ctx.tokenReadAndWrite = [
- { _id: 6, lastUpdated: new Date(5), owner_ref: 'user-4' },
- ]
- ctx.tokenReadOnly = [
- { _id: 6, lastUpdated: new Date(5), owner_ref: 'user-4' }, // Also in tokenReadAndWrite
- { _id: 7, lastUpdated: new Date(4), owner_ref: 'user-5' },
- ]
- ctx.review = [{ _id: 8, lastUpdated: new Date(5), owner_ref: 'user-6' }]
- ctx.allProjects = {
- owned: ctx.projects,
- readAndWrite: ctx.readAndWrite,
- readOnly: ctx.readOnly,
- tokenReadAndWrite: ctx.tokenReadAndWrite,
- tokenReadOnly: ctx.tokenReadOnly,
- review: ctx.review,
- }
- ctx.ProjectGetter.promises.findAllUsersProjects.resolves(ctx.allProjects)
- })
- it('should render the project/list-react page', async function (ctx) {
- await new Promise(resolve => {
- ctx.res.render = (pageName, opts) => {
- pageName.should.equal('project/list-react')
- resolve()
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- })
- it('should omit one of the projects', async function (ctx) {
- await new Promise(resolve => {
- ctx.res.render = (pageName, opts) => {
- opts.prefetchedProjectsBlob.projects.length.should.equal(
- ctx.projects.length +
- ctx.readAndWrite.length +
- ctx.readOnly.length +
- ctx.tokenReadAndWrite.length +
- ctx.tokenReadOnly.length +
- ctx.review.length -
- 1
- )
- resolve()
- }
- ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
- })
- })
- })
- })
|