|
@@ -1,7 +1,7 @@
|
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
import * as path from 'node:path'
|
|
import * as path from 'node:path'
|
|
|
import sinon from 'sinon'
|
|
import sinon from 'sinon'
|
|
|
-import MockResponse from '../../../../../test/unit/src/helpers/MockResponse.js'
|
|
|
|
|
|
|
+import MockResponse from '../../../../../test/unit/src/helpers/MockResponse.mjs'
|
|
|
|
|
|
|
|
const modulePath = path.join(
|
|
const modulePath = path.join(
|
|
|
import.meta.dirname,
|
|
import.meta.dirname,
|
|
@@ -9,10 +9,6 @@ const modulePath = path.join(
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
describe('LaunchpadController', function () {
|
|
describe('LaunchpadController', function () {
|
|
|
- // esmock doesn't work well with CommonJS dependencies, global imports for
|
|
|
|
|
- // @overleaf/settings aren't working until that module is migrated to ESM. In the
|
|
|
|
|
- // meantime, the workaround is to set and restore settings values
|
|
|
|
|
-
|
|
|
|
|
beforeEach(async function (ctx) {
|
|
beforeEach(async function (ctx) {
|
|
|
ctx.user = {
|
|
ctx.user = {
|
|
|
_id: '323123',
|
|
_id: '323123',
|
|
@@ -89,7 +85,7 @@ describe('LaunchpadController', function () {
|
|
|
session: {},
|
|
session: {},
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- ctx.res = new MockResponse()
|
|
|
|
|
|
|
+ ctx.res = new MockResponse(vi)
|
|
|
ctx.res.locals = {
|
|
ctx.res.locals = {
|
|
|
translate(key) {
|
|
translate(key) {
|
|
|
return key
|
|
return key
|
|
@@ -127,8 +123,8 @@ describe('LaunchpadController', function () {
|
|
|
import.meta.dirname,
|
|
import.meta.dirname,
|
|
|
'../../../app/views/launchpad'
|
|
'../../../app/views/launchpad'
|
|
|
)
|
|
)
|
|
|
- ctx.res.render.callCount.should.equal(1)
|
|
|
|
|
- expect(ctx.res.render).to.have.been.calledWith(viewPath, {
|
|
|
|
|
|
|
+ expect(ctx.res.render).toHaveBeenCalledTimes(1)
|
|
|
|
|
+ expect(ctx.res.render).toHaveBeenCalledWith(viewPath, {
|
|
|
adminUserExists: false,
|
|
adminUserExists: false,
|
|
|
authMethod: 'local',
|
|
authMethod: 'local',
|
|
|
})
|
|
})
|
|
@@ -149,11 +145,11 @@ describe('LaunchpadController', function () {
|
|
|
ctx.AuthenticationController.setRedirectInSession.callCount.should.equal(
|
|
ctx.AuthenticationController.setRedirectInSession.callCount.should.equal(
|
|
|
1
|
|
1
|
|
|
)
|
|
)
|
|
|
- ctx.res.redirect.calledWith('/login').should.equal(true)
|
|
|
|
|
|
|
+ expect(ctx.res.redirect).toHaveBeenCalledWith('/login')
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should not render the launchpad page', function (ctx) {
|
|
it('should not render the launchpad page', function (ctx) {
|
|
|
- ctx.res.render.callCount.should.equal(0)
|
|
|
|
|
|
|
+ expect(ctx.res.render).not.toHaveBeenCalled()
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
@@ -185,8 +181,8 @@ describe('LaunchpadController', function () {
|
|
|
import.meta.dirname,
|
|
import.meta.dirname,
|
|
|
'../../../app/views/launchpad'
|
|
'../../../app/views/launchpad'
|
|
|
)
|
|
)
|
|
|
- ctx.res.render.callCount.should.equal(1)
|
|
|
|
|
- expect(ctx.res.render).to.have.been.calledWith(viewPath, {
|
|
|
|
|
|
|
+ expect(ctx.res.render).toHaveBeenCalledTimes(1)
|
|
|
|
|
+ expect(ctx.res.render).toHaveBeenCalledWith(viewPath, {
|
|
|
wsUrl: undefined,
|
|
wsUrl: undefined,
|
|
|
adminUserExists: true,
|
|
adminUserExists: true,
|
|
|
authMethod: 'local',
|
|
authMethod: 'local',
|
|
@@ -207,8 +203,8 @@ describe('LaunchpadController', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should redirect to restricted page', function (ctx) {
|
|
it('should redirect to restricted page', function (ctx) {
|
|
|
- ctx.res.redirect.callCount.should.equal(1)
|
|
|
|
|
- ctx.res.redirect.calledWith('/restricted').should.equal(true)
|
|
|
|
|
|
|
+ expect(ctx.res.redirect).toHaveBeenCalledTimes(1)
|
|
|
|
|
+ expect(ctx.res.redirect).toHaveBeenCalledWith('/restricted')
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
@@ -258,7 +254,7 @@ describe('LaunchpadController', function () {
|
|
|
|
|
|
|
|
it('should produce a 200 response', async function (ctx) {
|
|
it('should produce a 200 response', async function (ctx) {
|
|
|
await ctx.LaunchpadController.sendTestEmail(ctx.req, ctx.res, ctx.next)
|
|
await ctx.LaunchpadController.sendTestEmail(ctx.req, ctx.res, ctx.next)
|
|
|
- ctx.res.json.calledWith({ message: 'email_sent' }).should.equal(true)
|
|
|
|
|
|
|
+ expect(ctx.res.json).toHaveBeenCalledWith({ message: 'email_sent' })
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should not call next with an error', function (ctx) {
|
|
it('should not call next with an error', function (ctx) {
|
|
@@ -300,12 +296,10 @@ describe('LaunchpadController', function () {
|
|
|
|
|
|
|
|
it('should produce a 400 response', function (ctx) {
|
|
it('should produce a 400 response', function (ctx) {
|
|
|
ctx.LaunchpadController.sendTestEmail(ctx.req, ctx.res, ctx.next)
|
|
ctx.LaunchpadController.sendTestEmail(ctx.req, ctx.res, ctx.next)
|
|
|
- ctx.res.status.calledWith(400).should.equal(true)
|
|
|
|
|
- ctx.res.json
|
|
|
|
|
- .calledWith({
|
|
|
|
|
- message: 'no email address supplied',
|
|
|
|
|
- })
|
|
|
|
|
- .should.equal(true)
|
|
|
|
|
|
|
+ expect(ctx.res.status).toHaveBeenCalledWith(400)
|
|
|
|
|
+ expect(ctx.res.json).toHaveBeenCalledWith({
|
|
|
|
|
+ message: 'no email address supplied',
|
|
|
|
|
+ })
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
@@ -341,8 +335,8 @@ describe('LaunchpadController', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should send back a json response', function (ctx) {
|
|
it('should send back a json response', function (ctx) {
|
|
|
- ctx.res.json.callCount.should.equal(1)
|
|
|
|
|
- expect(ctx.res.json).to.have.been.calledWith({ redir: '/launchpad' })
|
|
|
|
|
|
|
+ expect(ctx.res.json).toHaveBeenCalledTimes(1)
|
|
|
|
|
+ expect(ctx.res.json).toHaveBeenCalledWith({ redir: '/launchpad' })
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should have checked for existing admins', function (ctx) {
|
|
it('should have checked for existing admins', function (ctx) {
|
|
@@ -394,8 +388,8 @@ describe('LaunchpadController', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should send a 400 response', function (ctx) {
|
|
it('should send a 400 response', function (ctx) {
|
|
|
- ctx.res.sendStatus.callCount.should.equal(1)
|
|
|
|
|
- ctx.res.sendStatus.calledWith(400).should.equal(true)
|
|
|
|
|
|
|
+ expect(ctx.res.sendStatus).toHaveBeenCalledTimes(1)
|
|
|
|
|
+ expect(ctx.res.sendStatus).toHaveBeenCalledWith(400)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should not check for existing admins', function (ctx) {
|
|
it('should not check for existing admins', function (ctx) {
|
|
@@ -427,8 +421,8 @@ describe('LaunchpadController', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should send a 400 response', function (ctx) {
|
|
it('should send a 400 response', function (ctx) {
|
|
|
- ctx.res.sendStatus.callCount.should.equal(1)
|
|
|
|
|
- ctx.res.sendStatus.calledWith(400).should.equal(true)
|
|
|
|
|
|
|
+ expect(ctx.res.sendStatus).toHaveBeenCalledTimes(1)
|
|
|
|
|
+ expect(ctx.res.sendStatus).toHaveBeenCalledWith(400)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should not check for existing admins', function (ctx) {
|
|
it('should not check for existing admins', function (ctx) {
|
|
@@ -464,9 +458,9 @@ describe('LaunchpadController', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should send a 400 response', function (ctx) {
|
|
it('should send a 400 response', function (ctx) {
|
|
|
- ctx.res.status.callCount.should.equal(1)
|
|
|
|
|
- ctx.res.status.calledWith(400).should.equal(true)
|
|
|
|
|
- ctx.res.json.calledWith({
|
|
|
|
|
|
|
+ expect(ctx.res.status).toHaveBeenCalledTimes(1)
|
|
|
|
|
+ expect(ctx.res.status).toHaveBeenCalledWith(400)
|
|
|
|
|
+ expect(ctx.res.json).toHaveBeenCalledWith({
|
|
|
message: { type: 'error', text: 'bad email' },
|
|
message: { type: 'error', text: 'bad email' },
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
@@ -500,9 +494,9 @@ describe('LaunchpadController', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should send a 400 response', function (ctx) {
|
|
it('should send a 400 response', function (ctx) {
|
|
|
- ctx.res.status.callCount.should.equal(1)
|
|
|
|
|
- ctx.res.status.calledWith(400).should.equal(true)
|
|
|
|
|
- ctx.res.json.calledWith({
|
|
|
|
|
|
|
+ expect(ctx.res.status).toHaveBeenCalledTimes(1)
|
|
|
|
|
+ expect(ctx.res.status).toHaveBeenCalledWith(400)
|
|
|
|
|
+ expect(ctx.res.json).toHaveBeenCalledWith({
|
|
|
message: { type: 'error', text: 'bad password' },
|
|
message: { type: 'error', text: 'bad password' },
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
@@ -534,8 +528,8 @@ describe('LaunchpadController', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should send a 403 response', function (ctx) {
|
|
it('should send a 403 response', function (ctx) {
|
|
|
- ctx.res.status.callCount.should.equal(1)
|
|
|
|
|
- ctx.res.status.calledWith(403).should.equal(true)
|
|
|
|
|
|
|
+ expect(ctx.res.status).toHaveBeenCalledTimes(1)
|
|
|
|
|
+ expect(ctx.res.status).toHaveBeenCalledWith(403)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should not call registerNewUser', function (ctx) {
|
|
it('should not call registerNewUser', function (ctx) {
|
|
@@ -690,8 +684,8 @@ describe('LaunchpadController', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should send back a json response', function (ctx) {
|
|
it('should send back a json response', function (ctx) {
|
|
|
- ctx.res.json.callCount.should.equal(1)
|
|
|
|
|
- expect(ctx.res.json).to.have.been.calledWith({ redir: '/launchpad' })
|
|
|
|
|
|
|
+ expect(ctx.res.json).toHaveBeenCalledTimes(1)
|
|
|
|
|
+ expect(ctx.res.json).toHaveBeenCalledWith({ redir: '/launchpad' })
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should have checked for existing admins', function (ctx) {
|
|
it('should have checked for existing admins', function (ctx) {
|
|
@@ -757,8 +751,8 @@ describe('LaunchpadController', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should send back a json response', function (ctx) {
|
|
it('should send back a json response', function (ctx) {
|
|
|
- ctx.res.json.callCount.should.equal(1)
|
|
|
|
|
- expect(ctx.res.json.lastCall.args[0].email).to.equal(ctx.email)
|
|
|
|
|
|
|
+ expect(ctx.res.json).toHaveBeenCalledTimes(1)
|
|
|
|
|
+ expect(ctx.res.json.mock.lastCall[0].email).to.equal(ctx.email)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should have checked for existing admins', function (ctx) {
|
|
it('should have checked for existing admins', function (ctx) {
|
|
@@ -824,8 +818,8 @@ describe('LaunchpadController', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should send a 403 response', function (ctx) {
|
|
it('should send a 403 response', function (ctx) {
|
|
|
- ctx.res.sendStatus.callCount.should.equal(1)
|
|
|
|
|
- ctx.res.sendStatus.calledWith(403).should.equal(true)
|
|
|
|
|
|
|
+ expect(ctx.res.sendStatus).toHaveBeenCalledTimes(1)
|
|
|
|
|
+ expect(ctx.res.sendStatus).toHaveBeenCalledWith(403)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should not check for existing admins', function (ctx) {
|
|
it('should not check for existing admins', function (ctx) {
|
|
@@ -859,8 +853,8 @@ describe('LaunchpadController', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should send a 400 response', function (ctx) {
|
|
it('should send a 400 response', function (ctx) {
|
|
|
- ctx.res.sendStatus.callCount.should.equal(1)
|
|
|
|
|
- ctx.res.sendStatus.calledWith(400).should.equal(true)
|
|
|
|
|
|
|
+ expect(ctx.res.sendStatus).toHaveBeenCalledTimes(1)
|
|
|
|
|
+ expect(ctx.res.sendStatus).toHaveBeenCalledWith(400)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should not check for existing admins', function (ctx) {
|
|
it('should not check for existing admins', function (ctx) {
|
|
@@ -894,8 +888,8 @@ describe('LaunchpadController', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should send a 403 response', function (ctx) {
|
|
it('should send a 403 response', function (ctx) {
|
|
|
- ctx.res.sendStatus.callCount.should.equal(1)
|
|
|
|
|
- ctx.res.sendStatus.calledWith(403).should.equal(true)
|
|
|
|
|
|
|
+ expect(ctx.res.sendStatus).toHaveBeenCalledTimes(1)
|
|
|
|
|
+ expect(ctx.res.sendStatus).toHaveBeenCalledWith(403)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should not call registerNewUser', function (ctx) {
|
|
it('should not call registerNewUser', function (ctx) {
|