Update test files with vitest compat changes
GitOrigin-RevId: 494f906089d250268a5ff8c8a2150ff2692c37e2
This commit is contained in:
@@ -1,18 +1,15 @@
|
||||
import esmock from 'esmock'
|
||||
import { vi } from 'vitest'
|
||||
import assert from 'assert'
|
||||
import sinon from 'sinon'
|
||||
import { expect } from 'chai'
|
||||
import MockResponse from '../helpers/MockResponse.js'
|
||||
import MockRequest from '../helpers/MockRequest.js'
|
||||
|
||||
const modulePath = new URL(
|
||||
'../../../../app/src/Features/User/UserPagesController',
|
||||
import.meta.url
|
||||
).pathname
|
||||
const modulePath = '../../../../app/src/Features/User/UserPagesController'
|
||||
|
||||
describe('UserPagesController', function () {
|
||||
beforeEach(async function () {
|
||||
this.settings = {
|
||||
beforeEach(async function (ctx) {
|
||||
ctx.settings = {
|
||||
apis: {
|
||||
v1: {
|
||||
url: 'some.host',
|
||||
@@ -21,8 +18,8 @@ describe('UserPagesController', function () {
|
||||
},
|
||||
},
|
||||
}
|
||||
this.user = {
|
||||
_id: (this.user_id = 'kwjewkl'),
|
||||
ctx.user = {
|
||||
_id: (ctx.user_id = 'kwjewkl'),
|
||||
features: {},
|
||||
email: 'joe@example.com',
|
||||
ip_address: '1.1.1.1',
|
||||
@@ -39,414 +36,507 @@ describe('UserPagesController', function () {
|
||||
papers: { encrypted: 'cccc' },
|
||||
},
|
||||
}
|
||||
this.adminEmail = 'group-admin-email@overleaf.com'
|
||||
this.subscriptionViewModel = {
|
||||
ctx.adminEmail = 'group-admin-email@overleaf.com'
|
||||
ctx.subscriptionViewModel = {
|
||||
memberGroupSubscriptions: [],
|
||||
}
|
||||
|
||||
this.UserGetter = {
|
||||
ctx.UserGetter = {
|
||||
getUser: sinon.stub(),
|
||||
promises: { getUser: sinon.stub() },
|
||||
}
|
||||
this.UserSessionsManager = { getAllUserSessions: sinon.stub() }
|
||||
this.dropboxStatus = {}
|
||||
this.ErrorController = { notFound: sinon.stub() }
|
||||
this.SessionManager = {
|
||||
getLoggedInUserId: sinon.stub().returns(this.user._id),
|
||||
getSessionUser: sinon.stub().returns(this.user),
|
||||
ctx.UserSessionsManager = { getAllUserSessions: sinon.stub() }
|
||||
ctx.dropboxStatus = {}
|
||||
ctx.ErrorController = { notFound: sinon.stub() }
|
||||
ctx.SessionManager = {
|
||||
getLoggedInUserId: sinon.stub().returns(ctx.user._id),
|
||||
getSessionUser: sinon.stub().returns(ctx.user),
|
||||
}
|
||||
this.NewsletterManager = {
|
||||
ctx.NewsletterManager = {
|
||||
subscribed: sinon.stub().yields(),
|
||||
}
|
||||
this.AuthenticationController = {
|
||||
ctx.AuthenticationController = {
|
||||
getRedirectFromSession: sinon.stub(),
|
||||
setRedirectInSession: sinon.stub(),
|
||||
}
|
||||
this.Features = {
|
||||
ctx.Features = {
|
||||
hasFeature: sinon.stub().returns(false),
|
||||
}
|
||||
this.PersonalAccessTokenManager = {
|
||||
ctx.PersonalAccessTokenManager = {
|
||||
listTokens: sinon.stub().returns([]),
|
||||
}
|
||||
this.SubscriptionLocator = {
|
||||
ctx.SubscriptionLocator = {
|
||||
promises: {
|
||||
getAdminEmail: sinon.stub().returns(this.adminEmail),
|
||||
getAdminEmail: sinon.stub().returns(ctx.adminEmail),
|
||||
getMemberSubscriptions: sinon.stub().resolves(),
|
||||
},
|
||||
}
|
||||
this.SplitTestHandler = {
|
||||
ctx.SplitTestHandler = {
|
||||
promises: {
|
||||
getAssignment: sinon.stub().returns('default'),
|
||||
},
|
||||
}
|
||||
this.Modules = {
|
||||
ctx.Modules = {
|
||||
promises: {
|
||||
hooks: {
|
||||
fire: sinon.stub().resolves(),
|
||||
},
|
||||
},
|
||||
}
|
||||
this.UserPagesController = await esmock.strict(modulePath, {
|
||||
'@overleaf/settings': this.settings,
|
||||
'../../../../app/src/Features/User/UserGetter': this.UserGetter,
|
||||
'../../../../app/src/Features/User/UserSessionsManager':
|
||||
this.UserSessionsManager,
|
||||
'../../../../app/src/Features/Newsletter/NewsletterManager':
|
||||
this.NewsletterManager,
|
||||
'../../../../app/src/Features/Errors/ErrorController':
|
||||
this.ErrorController,
|
||||
'../../../../app/src/Features/Authentication/AuthenticationController':
|
||||
this.AuthenticationController,
|
||||
'../../../../app/src/Features/Subscription/SubscriptionLocator':
|
||||
this.SubscriptionLocator,
|
||||
'../../../../app/src/infrastructure/Features': this.Features,
|
||||
'../../../../modules/oauth2-server/app/src/OAuthPersonalAccessTokenManager':
|
||||
this.PersonalAccessTokenManager,
|
||||
'../../../../app/src/Features/Authentication/SessionManager':
|
||||
this.SessionManager,
|
||||
'../../../../app/src/Features/SplitTests/SplitTestHandler':
|
||||
this.SplitTestHandler,
|
||||
'../../../../app/src/infrastructure/Modules': this.Modules,
|
||||
request: (this.request = sinon.stub()),
|
||||
})
|
||||
this.req = new MockRequest()
|
||||
this.req.session.user = this.user
|
||||
this.res = new MockResponse()
|
||||
|
||||
vi.doMock('@overleaf/settings', () => ({
|
||||
default: ctx.settings,
|
||||
}))
|
||||
|
||||
vi.doMock('../../../../app/src/Features/User/UserGetter', () => ({
|
||||
default: ctx.UserGetter,
|
||||
}))
|
||||
|
||||
vi.doMock('../../../../app/src/Features/User/UserSessionsManager', () => ({
|
||||
default: ctx.UserSessionsManager,
|
||||
}))
|
||||
|
||||
vi.doMock(
|
||||
'../../../../app/src/Features/Newsletter/NewsletterManager',
|
||||
() => ({
|
||||
default: ctx.NewsletterManager,
|
||||
})
|
||||
)
|
||||
|
||||
vi.doMock('../../../../app/src/Features/Errors/ErrorController', () => ({
|
||||
default: ctx.ErrorController,
|
||||
}))
|
||||
|
||||
vi.doMock(
|
||||
'../../../../app/src/Features/Authentication/AuthenticationController',
|
||||
() => ({
|
||||
default: ctx.AuthenticationController,
|
||||
})
|
||||
)
|
||||
|
||||
vi.doMock(
|
||||
'../../../../app/src/Features/Subscription/SubscriptionLocator',
|
||||
() => ({
|
||||
default: ctx.SubscriptionLocator,
|
||||
})
|
||||
)
|
||||
|
||||
vi.doMock('../../../../app/src/infrastructure/Features', () => ({
|
||||
default: ctx.Features,
|
||||
}))
|
||||
|
||||
vi.doMock(
|
||||
'../../../../modules/oauth2-server/app/src/OAuthPersonalAccessTokenManager',
|
||||
() => ({
|
||||
default: ctx.PersonalAccessTokenManager,
|
||||
})
|
||||
)
|
||||
|
||||
vi.doMock(
|
||||
'../../../../app/src/Features/Authentication/SessionManager',
|
||||
() => ({
|
||||
default: ctx.SessionManager,
|
||||
})
|
||||
)
|
||||
|
||||
vi.doMock(
|
||||
'../../../../app/src/Features/SplitTests/SplitTestHandler',
|
||||
() => ({
|
||||
default: ctx.SplitTestHandler,
|
||||
})
|
||||
)
|
||||
|
||||
vi.doMock('../../../../app/src/infrastructure/Modules', () => ({
|
||||
default: ctx.Modules,
|
||||
}))
|
||||
ctx.request = sinon.stub()
|
||||
vi.doMock('request', () => ({
|
||||
default: ctx.request,
|
||||
}))
|
||||
|
||||
ctx.UserPagesController = (await import(modulePath)).default
|
||||
ctx.req = new MockRequest()
|
||||
ctx.req.session.user = ctx.user
|
||||
ctx.res = new MockResponse()
|
||||
})
|
||||
|
||||
describe('registerPage', function () {
|
||||
it('should render the register page', function (done) {
|
||||
this.res.callback = () => {
|
||||
this.res.renderedTemplate.should.equal('user/register')
|
||||
done()
|
||||
}
|
||||
this.UserPagesController.registerPage(this.req, this.res, done)
|
||||
it('should render the register page', function (ctx) {
|
||||
return new Promise(resolve => {
|
||||
ctx.res.callback = () => {
|
||||
ctx.res.renderedTemplate.should.equal('user/register')
|
||||
resolve()
|
||||
}
|
||||
ctx.UserPagesController.registerPage(ctx.req, ctx.res, resolve)
|
||||
})
|
||||
})
|
||||
|
||||
it('should set sharedProjectData', function (done) {
|
||||
this.req.session.sharedProjectData = {
|
||||
project_name: 'myProject',
|
||||
user_first_name: 'user_first_name_here',
|
||||
}
|
||||
it('should set sharedProjectData', function (ctx) {
|
||||
return new Promise(resolve => {
|
||||
ctx.req.session.sharedProjectData = {
|
||||
project_name: 'myProject',
|
||||
user_first_name: 'user_first_name_here',
|
||||
}
|
||||
|
||||
this.res.callback = () => {
|
||||
this.res.renderedVariables.sharedProjectData.project_name.should.equal(
|
||||
'myProject'
|
||||
)
|
||||
this.res.renderedVariables.sharedProjectData.user_first_name.should.equal(
|
||||
'user_first_name_here'
|
||||
)
|
||||
done()
|
||||
}
|
||||
this.UserPagesController.registerPage(this.req, this.res, done)
|
||||
ctx.res.callback = () => {
|
||||
ctx.res.renderedVariables.sharedProjectData.project_name.should.equal(
|
||||
'myProject'
|
||||
)
|
||||
ctx.res.renderedVariables.sharedProjectData.user_first_name.should.equal(
|
||||
'user_first_name_here'
|
||||
)
|
||||
resolve()
|
||||
}
|
||||
ctx.UserPagesController.registerPage(ctx.req, ctx.res, resolve)
|
||||
})
|
||||
})
|
||||
|
||||
it('should set newTemplateData', function (done) {
|
||||
this.req.session.templateData = { templateName: 'templateName' }
|
||||
it('should set newTemplateData', function (ctx) {
|
||||
return new Promise(resolve => {
|
||||
ctx.req.session.templateData = { templateName: 'templateName' }
|
||||
|
||||
this.res.callback = () => {
|
||||
this.res.renderedVariables.newTemplateData.templateName.should.equal(
|
||||
'templateName'
|
||||
)
|
||||
done()
|
||||
}
|
||||
this.UserPagesController.registerPage(this.req, this.res, done)
|
||||
ctx.res.callback = () => {
|
||||
ctx.res.renderedVariables.newTemplateData.templateName.should.equal(
|
||||
'templateName'
|
||||
)
|
||||
resolve()
|
||||
}
|
||||
ctx.UserPagesController.registerPage(ctx.req, ctx.res, resolve)
|
||||
})
|
||||
})
|
||||
|
||||
it('should not set the newTemplateData if there is nothing in the session', function (done) {
|
||||
this.res.callback = () => {
|
||||
assert.equal(
|
||||
this.res.renderedVariables.newTemplateData.templateName,
|
||||
undefined
|
||||
)
|
||||
done()
|
||||
}
|
||||
this.UserPagesController.registerPage(this.req, this.res, done)
|
||||
it('should not set the newTemplateData if there is nothing in the session', function (ctx) {
|
||||
return new Promise(resolve => {
|
||||
ctx.res.callback = () => {
|
||||
assert.equal(
|
||||
ctx.res.renderedVariables.newTemplateData.templateName,
|
||||
undefined
|
||||
)
|
||||
resolve()
|
||||
}
|
||||
ctx.UserPagesController.registerPage(ctx.req, ctx.res, resolve)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('loginForm', function () {
|
||||
it('should render the login page', function (done) {
|
||||
this.res.callback = () => {
|
||||
this.res.renderedTemplate.should.equal('user/login')
|
||||
done()
|
||||
}
|
||||
this.UserPagesController.loginPage(this.req, this.res, done)
|
||||
it('should render the login page', function (ctx) {
|
||||
return new Promise(resolve => {
|
||||
ctx.res.callback = () => {
|
||||
ctx.res.renderedTemplate.should.equal('user/login')
|
||||
resolve()
|
||||
}
|
||||
ctx.UserPagesController.loginPage(ctx.req, ctx.res, resolve)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when an explicit redirect is set via query string', function () {
|
||||
beforeEach(function () {
|
||||
this.AuthenticationController.getRedirectFromSession = sinon
|
||||
beforeEach(function (ctx) {
|
||||
ctx.AuthenticationController.getRedirectFromSession = sinon
|
||||
.stub()
|
||||
.returns(null)
|
||||
this.AuthenticationController.setRedirectInSession = sinon.stub()
|
||||
this.req.query.redir = '/somewhere/in/particular'
|
||||
ctx.AuthenticationController.setRedirectInSession = sinon.stub()
|
||||
ctx.req.query.redir = '/somewhere/in/particular'
|
||||
})
|
||||
|
||||
it('should set a redirect', function (done) {
|
||||
this.res.callback = page => {
|
||||
this.AuthenticationController.setRedirectInSession.callCount.should.equal(
|
||||
1
|
||||
)
|
||||
expect(
|
||||
this.AuthenticationController.setRedirectInSession.lastCall.args[1]
|
||||
).to.equal(this.req.query.redir)
|
||||
done()
|
||||
}
|
||||
this.UserPagesController.loginPage(this.req, this.res, done)
|
||||
it('should set a redirect', function (ctx) {
|
||||
return new Promise(resolve => {
|
||||
ctx.res.callback = page => {
|
||||
ctx.AuthenticationController.setRedirectInSession.callCount.should.equal(
|
||||
1
|
||||
)
|
||||
expect(
|
||||
ctx.AuthenticationController.setRedirectInSession.lastCall.args[1]
|
||||
).to.equal(ctx.req.query.redir)
|
||||
resolve()
|
||||
}
|
||||
ctx.UserPagesController.loginPage(ctx.req, ctx.res, resolve)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('sessionsPage', function () {
|
||||
beforeEach(function () {
|
||||
this.UserSessionsManager.getAllUserSessions.callsArgWith(2, null, [])
|
||||
beforeEach(function (ctx) {
|
||||
ctx.UserSessionsManager.getAllUserSessions.callsArgWith(2, null, [])
|
||||
})
|
||||
|
||||
it('should render user/sessions', function (done) {
|
||||
this.res.callback = () => {
|
||||
this.res.renderedTemplate.should.equal('user/sessions')
|
||||
done()
|
||||
}
|
||||
this.UserPagesController.sessionsPage(this.req, this.res, done)
|
||||
it('should render user/sessions', function (ctx) {
|
||||
return new Promise(resolve => {
|
||||
ctx.res.callback = () => {
|
||||
ctx.res.renderedTemplate.should.equal('user/sessions')
|
||||
resolve()
|
||||
}
|
||||
ctx.UserPagesController.sessionsPage(ctx.req, ctx.res, resolve)
|
||||
})
|
||||
})
|
||||
|
||||
it('should include current session data in the view', function (done) {
|
||||
this.res.callback = () => {
|
||||
expect(this.res.renderedVariables.currentSession).to.deep.equal({
|
||||
ip_address: '1.1.1.1',
|
||||
session_created: 'timestamp',
|
||||
})
|
||||
done()
|
||||
}
|
||||
this.UserPagesController.sessionsPage(this.req, this.res, done)
|
||||
it('should include current session data in the view', function (ctx) {
|
||||
return new Promise(resolve => {
|
||||
ctx.res.callback = () => {
|
||||
expect(ctx.res.renderedVariables.currentSession).to.deep.equal({
|
||||
ip_address: '1.1.1.1',
|
||||
session_created: 'timestamp',
|
||||
})
|
||||
resolve()
|
||||
}
|
||||
ctx.UserPagesController.sessionsPage(ctx.req, ctx.res, resolve)
|
||||
})
|
||||
})
|
||||
|
||||
it('should have called getAllUserSessions', function (done) {
|
||||
this.res.callback = page => {
|
||||
this.UserSessionsManager.getAllUserSessions.callCount.should.equal(1)
|
||||
done()
|
||||
}
|
||||
this.UserPagesController.sessionsPage(this.req, this.res, done)
|
||||
it('should have called getAllUserSessions', function (ctx) {
|
||||
return new Promise(resolve => {
|
||||
ctx.res.callback = page => {
|
||||
ctx.UserSessionsManager.getAllUserSessions.callCount.should.equal(1)
|
||||
resolve()
|
||||
}
|
||||
ctx.UserPagesController.sessionsPage(ctx.req, ctx.res, resolve)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when getAllUserSessions produces an error', function () {
|
||||
beforeEach(function () {
|
||||
this.UserSessionsManager.getAllUserSessions.callsArgWith(
|
||||
beforeEach(function (ctx) {
|
||||
ctx.UserSessionsManager.getAllUserSessions.callsArgWith(
|
||||
2,
|
||||
new Error('woops')
|
||||
)
|
||||
})
|
||||
|
||||
it('should call next with an error', function (done) {
|
||||
this.next = err => {
|
||||
assert(err !== null)
|
||||
assert(err instanceof Error)
|
||||
done()
|
||||
}
|
||||
this.UserPagesController.sessionsPage(this.req, this.res, this.next)
|
||||
it('should call next with an error', function (ctx) {
|
||||
return new Promise(resolve => {
|
||||
ctx.next = err => {
|
||||
assert(err !== null)
|
||||
assert(err instanceof Error)
|
||||
resolve()
|
||||
}
|
||||
ctx.UserPagesController.sessionsPage(ctx.req, ctx.res, ctx.next)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('emailPreferencesPage', function () {
|
||||
beforeEach(function () {
|
||||
this.UserGetter.getUser = sinon.stub().yields(null, this.user)
|
||||
beforeEach(function (ctx) {
|
||||
ctx.UserGetter.getUser = sinon.stub().yields(null, ctx.user)
|
||||
})
|
||||
|
||||
it('render page with subscribed status', function (done) {
|
||||
this.NewsletterManager.subscribed.yields(null, true)
|
||||
this.res.callback = () => {
|
||||
this.res.renderedTemplate.should.equal('user/email-preferences')
|
||||
this.res.renderedVariables.title.should.equal('newsletter_info_title')
|
||||
this.res.renderedVariables.subscribed.should.equal(true)
|
||||
done()
|
||||
}
|
||||
this.UserPagesController.emailPreferencesPage(this.req, this.res, done)
|
||||
it('render page with subscribed status', function (ctx) {
|
||||
return new Promise(resolve => {
|
||||
ctx.NewsletterManager.subscribed.yields(null, true)
|
||||
ctx.res.callback = () => {
|
||||
ctx.res.renderedTemplate.should.equal('user/email-preferences')
|
||||
ctx.res.renderedVariables.title.should.equal('newsletter_info_title')
|
||||
ctx.res.renderedVariables.subscribed.should.equal(true)
|
||||
resolve()
|
||||
}
|
||||
ctx.UserPagesController.emailPreferencesPage(ctx.req, ctx.res, resolve)
|
||||
})
|
||||
})
|
||||
|
||||
it('render page with unsubscribed status', function (done) {
|
||||
this.NewsletterManager.subscribed.yields(null, false)
|
||||
this.res.callback = () => {
|
||||
this.res.renderedTemplate.should.equal('user/email-preferences')
|
||||
this.res.renderedVariables.title.should.equal('newsletter_info_title')
|
||||
this.res.renderedVariables.subscribed.should.equal(false)
|
||||
done()
|
||||
}
|
||||
this.UserPagesController.emailPreferencesPage(this.req, this.res, done)
|
||||
it('render page with unsubscribed status', function (ctx) {
|
||||
return new Promise(resolve => {
|
||||
ctx.NewsletterManager.subscribed.yields(null, false)
|
||||
ctx.res.callback = () => {
|
||||
ctx.res.renderedTemplate.should.equal('user/email-preferences')
|
||||
ctx.res.renderedVariables.title.should.equal('newsletter_info_title')
|
||||
ctx.res.renderedVariables.subscribed.should.equal(false)
|
||||
resolve()
|
||||
}
|
||||
ctx.UserPagesController.emailPreferencesPage(ctx.req, ctx.res, resolve)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('settingsPage', function () {
|
||||
beforeEach(function () {
|
||||
this.request.get = sinon
|
||||
beforeEach(function (ctx) {
|
||||
ctx.request.get = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, { statusCode: 200 }, { has_password: true })
|
||||
this.UserGetter.promises.getUser = sinon.stub().resolves(this.user)
|
||||
ctx.UserGetter.promises.getUser = sinon.stub().resolves(ctx.user)
|
||||
})
|
||||
|
||||
it('should render user/settings', function (done) {
|
||||
this.res.callback = () => {
|
||||
this.res.renderedTemplate.should.equal('user/settings')
|
||||
done()
|
||||
}
|
||||
this.UserPagesController.settingsPage(this.req, this.res, done)
|
||||
it('should render user/settings', function (ctx) {
|
||||
return new Promise(resolve => {
|
||||
ctx.res.callback = () => {
|
||||
ctx.res.renderedTemplate.should.equal('user/settings')
|
||||
resolve()
|
||||
}
|
||||
ctx.UserPagesController.settingsPage(ctx.req, ctx.res, resolve)
|
||||
})
|
||||
})
|
||||
|
||||
it('should send user', function (done) {
|
||||
this.res.callback = () => {
|
||||
this.res.renderedVariables.user.id.should.equal(this.user._id)
|
||||
this.res.renderedVariables.user.email.should.equal(this.user.email)
|
||||
done()
|
||||
}
|
||||
this.UserPagesController.settingsPage(this.req, this.res, done)
|
||||
it('should send user', function (ctx) {
|
||||
return new Promise(resolve => {
|
||||
ctx.res.callback = () => {
|
||||
ctx.res.renderedVariables.user.id.should.equal(ctx.user._id)
|
||||
ctx.res.renderedVariables.user.email.should.equal(ctx.user.email)
|
||||
resolve()
|
||||
}
|
||||
ctx.UserPagesController.settingsPage(ctx.req, ctx.res, resolve)
|
||||
})
|
||||
})
|
||||
|
||||
it("should set 'shouldAllowEditingDetails' to true", function (done) {
|
||||
this.res.callback = () => {
|
||||
this.res.renderedVariables.shouldAllowEditingDetails.should.equal(true)
|
||||
done()
|
||||
}
|
||||
this.UserPagesController.settingsPage(this.req, this.res, done)
|
||||
it("should set 'shouldAllowEditingDetails' to true", function (ctx) {
|
||||
return new Promise(resolve => {
|
||||
ctx.res.callback = () => {
|
||||
ctx.res.renderedVariables.shouldAllowEditingDetails.should.equal(true)
|
||||
resolve()
|
||||
}
|
||||
ctx.UserPagesController.settingsPage(ctx.req, ctx.res, resolve)
|
||||
})
|
||||
})
|
||||
|
||||
it('should restructure thirdPartyIdentifiers data for template use', function (done) {
|
||||
const expectedResult = {
|
||||
google: 'testId',
|
||||
}
|
||||
this.res.callback = () => {
|
||||
expect(this.res.renderedVariables.thirdPartyIds).to.include(
|
||||
expectedResult
|
||||
)
|
||||
done()
|
||||
}
|
||||
this.UserPagesController.settingsPage(this.req, this.res, done)
|
||||
it('should restructure thirdPartyIdentifiers data for template use', function (ctx) {
|
||||
return new Promise(resolve => {
|
||||
const expectedResult = {
|
||||
google: 'testId',
|
||||
}
|
||||
ctx.res.callback = () => {
|
||||
expect(ctx.res.renderedVariables.thirdPartyIds).to.include(
|
||||
expectedResult
|
||||
)
|
||||
resolve()
|
||||
}
|
||||
ctx.UserPagesController.settingsPage(ctx.req, ctx.res, resolve)
|
||||
})
|
||||
})
|
||||
|
||||
it("should set and clear 'projectSyncSuccessMessage'", function (done) {
|
||||
this.req.session.projectSyncSuccessMessage = 'Some Sync Success'
|
||||
this.res.callback = () => {
|
||||
this.res.renderedVariables.projectSyncSuccessMessage.should.equal(
|
||||
'Some Sync Success'
|
||||
)
|
||||
expect(this.req.session.projectSyncSuccessMessage).to.not.exist
|
||||
done()
|
||||
}
|
||||
this.UserPagesController.settingsPage(this.req, this.res, done)
|
||||
it("should set and clear 'projectSyncSuccessMessage'", function (ctx) {
|
||||
return new Promise(resolve => {
|
||||
ctx.req.session.projectSyncSuccessMessage = 'Some Sync Success'
|
||||
ctx.res.callback = () => {
|
||||
ctx.res.renderedVariables.projectSyncSuccessMessage.should.equal(
|
||||
'Some Sync Success'
|
||||
)
|
||||
expect(ctx.req.session.projectSyncSuccessMessage).to.not.exist
|
||||
resolve()
|
||||
}
|
||||
ctx.UserPagesController.settingsPage(ctx.req, ctx.res, resolve)
|
||||
})
|
||||
})
|
||||
|
||||
it('should cast refProviders to booleans', function (done) {
|
||||
this.res.callback = () => {
|
||||
expect(this.res.renderedVariables.user.refProviders).to.deep.equal({
|
||||
mendeley: true,
|
||||
papers: true,
|
||||
zotero: true,
|
||||
})
|
||||
done()
|
||||
}
|
||||
this.UserPagesController.settingsPage(this.req, this.res, done)
|
||||
it('should cast refProviders to booleans', function (ctx) {
|
||||
return new Promise(resolve => {
|
||||
ctx.res.callback = () => {
|
||||
expect(ctx.res.renderedVariables.user.refProviders).to.deep.equal({
|
||||
mendeley: true,
|
||||
papers: true,
|
||||
zotero: true,
|
||||
})
|
||||
resolve()
|
||||
}
|
||||
ctx.UserPagesController.settingsPage(ctx.req, ctx.res, resolve)
|
||||
})
|
||||
})
|
||||
|
||||
it('should send the correct managed user admin email', function (done) {
|
||||
this.res.callback = () => {
|
||||
expect(
|
||||
this.res.renderedVariables.currentManagedUserAdminEmail
|
||||
).to.equal(this.adminEmail)
|
||||
done()
|
||||
}
|
||||
this.UserPagesController.settingsPage(this.req, this.res, done)
|
||||
it('should send the correct managed user admin email', function (ctx) {
|
||||
return new Promise(resolve => {
|
||||
ctx.res.callback = () => {
|
||||
expect(
|
||||
ctx.res.renderedVariables.currentManagedUserAdminEmail
|
||||
).to.equal(ctx.adminEmail)
|
||||
resolve()
|
||||
}
|
||||
ctx.UserPagesController.settingsPage(ctx.req, ctx.res, resolve)
|
||||
})
|
||||
})
|
||||
|
||||
it('should send info for groups with SSO enabled', function (done) {
|
||||
this.user.enrollment = {
|
||||
sso: [
|
||||
{
|
||||
groupId: 'abc123abc123',
|
||||
primary: true,
|
||||
linkedAt: new Date(),
|
||||
it('should send info for groups with SSO enabled', function (ctx) {
|
||||
return new Promise(resolve => {
|
||||
ctx.user.enrollment = {
|
||||
sso: [
|
||||
{
|
||||
groupId: 'abc123abc123',
|
||||
primary: true,
|
||||
linkedAt: new Date(),
|
||||
},
|
||||
],
|
||||
}
|
||||
const group1 = {
|
||||
_id: 'abc123abc123',
|
||||
teamName: 'Group SSO Rulz',
|
||||
admin_id: {
|
||||
email: 'admin.email@ssolove.com',
|
||||
},
|
||||
],
|
||||
}
|
||||
const group1 = {
|
||||
_id: 'abc123abc123',
|
||||
teamName: 'Group SSO Rulz',
|
||||
admin_id: {
|
||||
email: 'admin.email@ssolove.com',
|
||||
},
|
||||
linked: true,
|
||||
}
|
||||
const group2 = {
|
||||
_id: 'def456def456',
|
||||
admin_id: {
|
||||
email: 'someone.else@noname.co.uk',
|
||||
},
|
||||
linked: false,
|
||||
}
|
||||
|
||||
this.Modules.promises.hooks.fire
|
||||
.withArgs('getUserGroupsSSOEnrollmentStatus')
|
||||
.resolves([[group1, group2]])
|
||||
|
||||
this.res.callback = () => {
|
||||
expect(
|
||||
this.res.renderedVariables.memberOfSSOEnabledGroups
|
||||
).to.deep.equal([
|
||||
{
|
||||
groupId: 'abc123abc123',
|
||||
groupName: 'Group SSO Rulz',
|
||||
adminEmail: 'admin.email@ssolove.com',
|
||||
linked: true,
|
||||
linked: true,
|
||||
}
|
||||
const group2 = {
|
||||
_id: 'def456def456',
|
||||
admin_id: {
|
||||
email: 'someone.else@noname.co.uk',
|
||||
},
|
||||
{
|
||||
groupId: 'def456def456',
|
||||
groupName: undefined,
|
||||
adminEmail: 'someone.else@noname.co.uk',
|
||||
linked: false,
|
||||
},
|
||||
])
|
||||
done()
|
||||
}
|
||||
linked: false,
|
||||
}
|
||||
|
||||
this.UserPagesController.settingsPage(this.req, this.res, done)
|
||||
ctx.Modules.promises.hooks.fire
|
||||
.withArgs('getUserGroupsSSOEnrollmentStatus')
|
||||
.resolves([[group1, group2]])
|
||||
|
||||
ctx.res.callback = () => {
|
||||
expect(
|
||||
ctx.res.renderedVariables.memberOfSSOEnabledGroups
|
||||
).to.deep.equal([
|
||||
{
|
||||
groupId: 'abc123abc123',
|
||||
groupName: 'Group SSO Rulz',
|
||||
adminEmail: 'admin.email@ssolove.com',
|
||||
linked: true,
|
||||
},
|
||||
{
|
||||
groupId: 'def456def456',
|
||||
groupName: undefined,
|
||||
adminEmail: 'someone.else@noname.co.uk',
|
||||
linked: false,
|
||||
},
|
||||
])
|
||||
resolve()
|
||||
}
|
||||
|
||||
ctx.UserPagesController.settingsPage(ctx.req, ctx.res, resolve)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when ldap.updateUserDetailsOnLogin is true', function () {
|
||||
beforeEach(function () {
|
||||
this.settings.ldap = { updateUserDetailsOnLogin: true }
|
||||
beforeEach(function (ctx) {
|
||||
ctx.settings.ldap = { updateUserDetailsOnLogin: true }
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
delete this.settings.ldap
|
||||
afterEach(function (ctx) {
|
||||
delete ctx.settings.ldap
|
||||
})
|
||||
|
||||
it('should set "shouldAllowEditingDetails" to false', function (done) {
|
||||
this.res.callback = () => {
|
||||
this.res.renderedVariables.shouldAllowEditingDetails.should.equal(
|
||||
false
|
||||
)
|
||||
done()
|
||||
}
|
||||
this.UserPagesController.settingsPage(this.req, this.res, done)
|
||||
it('should set "shouldAllowEditingDetails" to false', function (ctx) {
|
||||
return new Promise(resolve => {
|
||||
ctx.res.callback = () => {
|
||||
ctx.res.renderedVariables.shouldAllowEditingDetails.should.equal(
|
||||
false
|
||||
)
|
||||
resolve()
|
||||
}
|
||||
ctx.UserPagesController.settingsPage(ctx.req, ctx.res, resolve)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('when saml.updateUserDetailsOnLogin is true', function () {
|
||||
beforeEach(function () {
|
||||
this.settings.saml = { updateUserDetailsOnLogin: true }
|
||||
beforeEach(function (ctx) {
|
||||
ctx.settings.saml = { updateUserDetailsOnLogin: true }
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
delete this.settings.saml
|
||||
afterEach(function (ctx) {
|
||||
delete ctx.settings.saml
|
||||
})
|
||||
|
||||
it('should set "shouldAllowEditingDetails" to false', function (done) {
|
||||
this.res.callback = () => {
|
||||
this.res.renderedVariables.shouldAllowEditingDetails.should.equal(
|
||||
false
|
||||
)
|
||||
done()
|
||||
}
|
||||
this.UserPagesController.settingsPage(this.req, this.res, done)
|
||||
it('should set "shouldAllowEditingDetails" to false', function (ctx) {
|
||||
return new Promise(resolve => {
|
||||
ctx.res.callback = () => {
|
||||
ctx.res.renderedVariables.shouldAllowEditingDetails.should.equal(
|
||||
false
|
||||
)
|
||||
resolve()
|
||||
}
|
||||
ctx.UserPagesController.settingsPage(ctx.req, ctx.res, resolve)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user