|
@@ -1,39 +1,26 @@
|
|
|
-/* eslint-disable
|
|
|
|
|
- max-len,
|
|
|
|
|
- no-return-assign,
|
|
|
|
|
- no-unused-vars,
|
|
|
|
|
-*/
|
|
|
|
|
-// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
|
-// Fix any style issues and re-enable lint.
|
|
|
|
|
-/*
|
|
|
|
|
- * decaffeinate suggestions:
|
|
|
|
|
- * DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
|
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
|
- */
|
|
|
|
|
-const SandboxedModule = require('sandboxed-module')
|
|
|
|
|
-const sinon = require('sinon')
|
|
|
|
|
-const { assert } = require('chai')
|
|
|
|
|
|
|
+import esmock from 'esmock'
|
|
|
|
|
+import sinon from 'sinon'
|
|
|
|
|
+import MockRequest from '../helpers/MockRequest.js'
|
|
|
|
|
+import MockResponse from '../helpers/MockResponse.js'
|
|
|
const modulePath =
|
|
const modulePath =
|
|
|
'../../../../app/src/Features/References/ReferencesController'
|
|
'../../../../app/src/Features/References/ReferencesController'
|
|
|
-const MockRequest = require('../helpers/MockRequest')
|
|
|
|
|
-const MockResponse = require('../helpers/MockResponse')
|
|
|
|
|
|
|
|
|
|
describe('ReferencesController', function () {
|
|
describe('ReferencesController', function () {
|
|
|
- beforeEach(function () {
|
|
|
|
|
|
|
+ beforeEach(async function () {
|
|
|
this.projectId = '2222'
|
|
this.projectId = '2222'
|
|
|
- this.controller = SandboxedModule.require(modulePath, {
|
|
|
|
|
- requires: {
|
|
|
|
|
- '@overleaf/settings': (this.settings = {
|
|
|
|
|
- apis: { web: { url: 'http://some.url' } },
|
|
|
|
|
- }),
|
|
|
|
|
- './ReferencesHandler': (this.ReferencesHandler = {
|
|
|
|
|
|
|
+ this.controller = await esmock.strict(modulePath, {
|
|
|
|
|
+ '@overleaf/settings': (this.settings = {
|
|
|
|
|
+ apis: { web: { url: 'http://some.url' } },
|
|
|
|
|
+ }),
|
|
|
|
|
+ '../../../../app/src/Features/References/ReferencesHandler':
|
|
|
|
|
+ (this.ReferencesHandler = {
|
|
|
index: sinon.stub(),
|
|
index: sinon.stub(),
|
|
|
indexAll: sinon.stub(),
|
|
indexAll: sinon.stub(),
|
|
|
}),
|
|
}),
|
|
|
- '../Editor/EditorRealTimeController': (this.EditorRealTimeController = {
|
|
|
|
|
|
|
+ '../../../../app/src/Features/Editor/EditorRealTimeController':
|
|
|
|
|
+ (this.EditorRealTimeController = {
|
|
|
emitToRoom: sinon.stub(),
|
|
emitToRoom: sinon.stub(),
|
|
|
}),
|
|
}),
|
|
|
- },
|
|
|
|
|
})
|
|
})
|
|
|
this.req = new MockRequest()
|
|
this.req = new MockRequest()
|
|
|
this.req.params.Project_id = this.projectId
|
|
this.req.params.Project_id = this.projectId
|
|
@@ -45,10 +32,10 @@ describe('ReferencesController', function () {
|
|
|
this.res.json = sinon.stub()
|
|
this.res.json = sinon.stub()
|
|
|
this.res.sendStatus = sinon.stub()
|
|
this.res.sendStatus = sinon.stub()
|
|
|
this.next = sinon.stub()
|
|
this.next = sinon.stub()
|
|
|
- return (this.fakeResponseData = {
|
|
|
|
|
|
|
+ this.fakeResponseData = {
|
|
|
projectId: this.projectId,
|
|
projectId: this.projectId,
|
|
|
keys: ['one', 'two', 'three'],
|
|
keys: ['one', 'two', 'three'],
|
|
|
- })
|
|
|
|
|
|
|
+ }
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
describe('indexAll', function () {
|
|
describe('indexAll', function () {
|
|
@@ -59,36 +46,36 @@ describe('ReferencesController', function () {
|
|
|
null,
|
|
null,
|
|
|
this.fakeResponseData
|
|
this.fakeResponseData
|
|
|
)
|
|
)
|
|
|
- return (this.call = callback => {
|
|
|
|
|
|
|
+ this.call = callback => {
|
|
|
this.controller.indexAll(this.req, this.res, this.next)
|
|
this.controller.indexAll(this.req, this.res, this.next)
|
|
|
return callback()
|
|
return callback()
|
|
|
- })
|
|
|
|
|
|
|
+ }
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should not produce an error', function (done) {
|
|
it('should not produce an error', function (done) {
|
|
|
- return this.call(() => {
|
|
|
|
|
|
|
+ this.call(() => {
|
|
|
this.res.sendStatus.callCount.should.equal(0)
|
|
this.res.sendStatus.callCount.should.equal(0)
|
|
|
this.res.sendStatus.calledWith(500).should.equal(false)
|
|
this.res.sendStatus.calledWith(500).should.equal(false)
|
|
|
this.res.sendStatus.calledWith(400).should.equal(false)
|
|
this.res.sendStatus.calledWith(400).should.equal(false)
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should return data', function (done) {
|
|
it('should return data', function (done) {
|
|
|
- return this.call(() => {
|
|
|
|
|
|
|
+ this.call(() => {
|
|
|
this.res.json.callCount.should.equal(1)
|
|
this.res.json.callCount.should.equal(1)
|
|
|
this.res.json.calledWith(this.fakeResponseData).should.equal(true)
|
|
this.res.json.calledWith(this.fakeResponseData).should.equal(true)
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should call ReferencesHandler.indexAll', function (done) {
|
|
it('should call ReferencesHandler.indexAll', function (done) {
|
|
|
- return this.call(() => {
|
|
|
|
|
|
|
+ this.call(() => {
|
|
|
this.ReferencesHandler.indexAll.callCount.should.equal(1)
|
|
this.ReferencesHandler.indexAll.callCount.should.equal(1)
|
|
|
this.ReferencesHandler.indexAll
|
|
this.ReferencesHandler.indexAll
|
|
|
.calledWith(this.projectId)
|
|
.calledWith(this.projectId)
|
|
|
.should.equal(true)
|
|
.should.equal(true)
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
@@ -99,30 +86,30 @@ describe('ReferencesController', function () {
|
|
|
null,
|
|
null,
|
|
|
this.fakeResponseData
|
|
this.fakeResponseData
|
|
|
)
|
|
)
|
|
|
- return (this.req.body.shouldBroadcast = true)
|
|
|
|
|
|
|
+ this.req.body.shouldBroadcast = true
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should call EditorRealTimeController.emitToRoom', function (done) {
|
|
it('should call EditorRealTimeController.emitToRoom', function (done) {
|
|
|
- return this.call(() => {
|
|
|
|
|
|
|
+ this.call(() => {
|
|
|
this.EditorRealTimeController.emitToRoom.callCount.should.equal(1)
|
|
this.EditorRealTimeController.emitToRoom.callCount.should.equal(1)
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should not produce an error', function (done) {
|
|
it('should not produce an error', function (done) {
|
|
|
- return this.call(() => {
|
|
|
|
|
|
|
+ this.call(() => {
|
|
|
this.res.sendStatus.callCount.should.equal(0)
|
|
this.res.sendStatus.callCount.should.equal(0)
|
|
|
this.res.sendStatus.calledWith(500).should.equal(false)
|
|
this.res.sendStatus.calledWith(500).should.equal(false)
|
|
|
this.res.sendStatus.calledWith(400).should.equal(false)
|
|
this.res.sendStatus.calledWith(400).should.equal(false)
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should still return data', function (done) {
|
|
it('should still return data', function (done) {
|
|
|
- return this.call(() => {
|
|
|
|
|
|
|
+ this.call(() => {
|
|
|
this.res.json.callCount.should.equal(1)
|
|
this.res.json.callCount.should.equal(1)
|
|
|
this.res.json.calledWith(this.fakeResponseData).should.equal(true)
|
|
this.res.json.calledWith(this.fakeResponseData).should.equal(true)
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
@@ -134,30 +121,30 @@ describe('ReferencesController', function () {
|
|
|
null,
|
|
null,
|
|
|
this.fakeResponseData
|
|
this.fakeResponseData
|
|
|
)
|
|
)
|
|
|
- return (this.req.body.shouldBroadcast = false)
|
|
|
|
|
|
|
+ this.req.body.shouldBroadcast = false
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should not call EditorRealTimeController.emitToRoom', function (done) {
|
|
it('should not call EditorRealTimeController.emitToRoom', function (done) {
|
|
|
- return this.call(() => {
|
|
|
|
|
|
|
+ this.call(() => {
|
|
|
this.EditorRealTimeController.emitToRoom.callCount.should.equal(0)
|
|
this.EditorRealTimeController.emitToRoom.callCount.should.equal(0)
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should not produce an error', function (done) {
|
|
it('should not produce an error', function (done) {
|
|
|
- return this.call(() => {
|
|
|
|
|
|
|
+ this.call(() => {
|
|
|
this.res.sendStatus.callCount.should.equal(0)
|
|
this.res.sendStatus.callCount.should.equal(0)
|
|
|
this.res.sendStatus.calledWith(500).should.equal(false)
|
|
this.res.sendStatus.calledWith(500).should.equal(false)
|
|
|
this.res.sendStatus.calledWith(400).should.equal(false)
|
|
this.res.sendStatus.calledWith(400).should.equal(false)
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should still return data', function (done) {
|
|
it('should still return data', function (done) {
|
|
|
- return this.call(() => {
|
|
|
|
|
|
|
+ this.call(() => {
|
|
|
this.res.json.callCount.should.equal(1)
|
|
this.res.json.callCount.should.equal(1)
|
|
|
this.res.json.calledWith(this.fakeResponseData).should.equal(true)
|
|
this.res.json.calledWith(this.fakeResponseData).should.equal(true)
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
@@ -166,35 +153,35 @@ describe('ReferencesController', function () {
|
|
|
describe('there is no data', function () {
|
|
describe('there is no data', function () {
|
|
|
beforeEach(function () {
|
|
beforeEach(function () {
|
|
|
this.ReferencesHandler.indexAll.callsArgWith(1)
|
|
this.ReferencesHandler.indexAll.callsArgWith(1)
|
|
|
- return (this.call = callback => {
|
|
|
|
|
|
|
+ this.call = callback => {
|
|
|
this.controller.indexAll(this.req, this.res, this.next)
|
|
this.controller.indexAll(this.req, this.res, this.next)
|
|
|
- return callback()
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ callback()
|
|
|
|
|
+ }
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should not call EditorRealTimeController.emitToRoom', function (done) {
|
|
it('should not call EditorRealTimeController.emitToRoom', function (done) {
|
|
|
- return this.call(() => {
|
|
|
|
|
|
|
+ this.call(() => {
|
|
|
this.EditorRealTimeController.emitToRoom.callCount.should.equal(0)
|
|
this.EditorRealTimeController.emitToRoom.callCount.should.equal(0)
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should not produce an error', function (done) {
|
|
it('should not produce an error', function (done) {
|
|
|
- return this.call(() => {
|
|
|
|
|
|
|
+ this.call(() => {
|
|
|
this.res.sendStatus.callCount.should.equal(0)
|
|
this.res.sendStatus.callCount.should.equal(0)
|
|
|
this.res.sendStatus.calledWith(500).should.equal(false)
|
|
this.res.sendStatus.calledWith(500).should.equal(false)
|
|
|
this.res.sendStatus.calledWith(400).should.equal(false)
|
|
this.res.sendStatus.calledWith(400).should.equal(false)
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should send a response with an empty keys list', function (done) {
|
|
it('should send a response with an empty keys list', function (done) {
|
|
|
- return this.call(() => {
|
|
|
|
|
|
|
+ this.call(() => {
|
|
|
this.res.json.called.should.equal(true)
|
|
this.res.json.called.should.equal(true)
|
|
|
this.res.json
|
|
this.res.json
|
|
|
.calledWith({ projectId: this.projectId, keys: [] })
|
|
.calledWith({ projectId: this.projectId, keys: [] })
|
|
|
.should.equal(true)
|
|
.should.equal(true)
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|