|
|
@@ -1,10 +1,3 @@
|
|
|
-/* eslint-disable
|
|
|
- n/handle-callback-err,
|
|
|
- max-len,
|
|
|
- mocha/no-identical-title,
|
|
|
- no-return-assign,
|
|
|
- no-unused-vars,
|
|
|
-*/
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
// Fix any style issues and re-enable lint.
|
|
|
/*
|
|
|
@@ -12,14 +5,16 @@
|
|
|
* 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 { assert, expect } = require('chai')
|
|
|
-const sinon = require('sinon')
|
|
|
-const Errors = require('../../../../app/src/Features/Errors/Errors')
|
|
|
-const modulePath = '../../../../app/src/Features/References/ReferencesHandler'
|
|
|
+import esmock from 'esmock'
|
|
|
+
|
|
|
+import { expect } from 'chai'
|
|
|
+import sinon from 'sinon'
|
|
|
+import Errors from '../../../../app/src/Features/Errors/Errors.js'
|
|
|
+const modulePath =
|
|
|
+ '../../../../app/src/Features/References/ReferencesHandler.mjs'
|
|
|
|
|
|
describe('ReferencesHandler', function () {
|
|
|
- beforeEach(function () {
|
|
|
+ beforeEach(async function () {
|
|
|
this.projectId = '222'
|
|
|
this.fakeProject = {
|
|
|
_id: this.projectId,
|
|
|
@@ -46,38 +41,37 @@ describe('ReferencesHandler', function () {
|
|
|
],
|
|
|
}
|
|
|
this.docIds = ['aaa', 'ccc']
|
|
|
- this.handler = SandboxedModule.require(modulePath, {
|
|
|
- requires: {
|
|
|
- '@overleaf/settings': (this.settings = {
|
|
|
- apis: {
|
|
|
- references: { url: 'http://some.url/references' },
|
|
|
- docstore: { url: 'http://some.url/docstore' },
|
|
|
- filestore: { url: 'http://some.url/filestore' },
|
|
|
- },
|
|
|
- }),
|
|
|
- request: (this.request = {
|
|
|
- get: sinon.stub(),
|
|
|
- post: sinon.stub(),
|
|
|
- }),
|
|
|
- '../Project/ProjectGetter': (this.ProjectGetter = {
|
|
|
+ this.handler = await esmock.strict(modulePath, {
|
|
|
+ '@overleaf/settings': (this.settings = {
|
|
|
+ apis: {
|
|
|
+ references: { url: 'http://some.url/references' },
|
|
|
+ docstore: { url: 'http://some.url/docstore' },
|
|
|
+ filestore: { url: 'http://some.url/filestore' },
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ request: (this.request = {
|
|
|
+ get: sinon.stub(),
|
|
|
+ post: sinon.stub(),
|
|
|
+ }),
|
|
|
+ '../../../../app/src/Features/Project/ProjectGetter':
|
|
|
+ (this.ProjectGetter = {
|
|
|
getProject: sinon.stub().callsArgWith(2, null, this.fakeProject),
|
|
|
}),
|
|
|
- '../User/UserGetter': (this.UserGetter = {
|
|
|
- getUser: sinon.stub(),
|
|
|
- }),
|
|
|
- '../DocumentUpdater/DocumentUpdaterHandler':
|
|
|
- (this.DocumentUpdaterHandler = {
|
|
|
- flushDocToMongo: sinon.stub().callsArgWith(2, null),
|
|
|
- }),
|
|
|
- '../../infrastructure/Features': (this.Features = {
|
|
|
- hasFeature: sinon.stub().returns(true),
|
|
|
+ '../../../../app/src/Features/User/UserGetter': (this.UserGetter = {
|
|
|
+ getUser: sinon.stub(),
|
|
|
+ }),
|
|
|
+ '../../../../app/src/Features/DocumentUpdater/DocumentUpdaterHandler':
|
|
|
+ (this.DocumentUpdaterHandler = {
|
|
|
+ flushDocToMongo: sinon.stub().callsArgWith(2, null),
|
|
|
}),
|
|
|
- },
|
|
|
+ '../../../../app/src/infrastructure/Features': (this.Features = {
|
|
|
+ hasFeature: sinon.stub().returns(true),
|
|
|
+ }),
|
|
|
})
|
|
|
- return (this.fakeResponseData = {
|
|
|
+ this.fakeResponseData = {
|
|
|
projectId: this.projectId,
|
|
|
keys: ['k1', 'k2'],
|
|
|
- })
|
|
|
+ }
|
|
|
})
|
|
|
|
|
|
describe('indexAll', function () {
|
|
|
@@ -98,6 +92,7 @@ describe('ReferencesHandler', function () {
|
|
|
|
|
|
it('should call _findBibDocIds', function (done) {
|
|
|
return this.call((err, data) => {
|
|
|
+ expect(err).to.be.null
|
|
|
this.handler._findBibDocIds.callCount.should.equal(1)
|
|
|
this.handler._findBibDocIds
|
|
|
.calledWith(this.fakeProject)
|
|
|
@@ -108,6 +103,7 @@ describe('ReferencesHandler', function () {
|
|
|
|
|
|
it('should call _findBibFileIds', function (done) {
|
|
|
return this.call((err, data) => {
|
|
|
+ expect(err).to.be.null
|
|
|
this.handler._findBibDocIds.callCount.should.equal(1)
|
|
|
this.handler._findBibDocIds
|
|
|
.calledWith(this.fakeProject)
|
|
|
@@ -118,6 +114,7 @@ describe('ReferencesHandler', function () {
|
|
|
|
|
|
it('should call DocumentUpdaterHandler.flushDocToMongo', function (done) {
|
|
|
return this.call((err, data) => {
|
|
|
+ expect(err).to.be.null
|
|
|
this.DocumentUpdaterHandler.flushDocToMongo.callCount.should.equal(2)
|
|
|
return done()
|
|
|
})
|
|
|
@@ -125,6 +122,7 @@ describe('ReferencesHandler', function () {
|
|
|
|
|
|
it('should make a request to references service', function (done) {
|
|
|
return this.call((err, data) => {
|
|
|
+ expect(err).to.be.null
|
|
|
this.request.post.callCount.should.equal(1)
|
|
|
const arg = this.request.post.firstCall.args[0]
|
|
|
expect(arg.json).to.have.all.keys('docUrls', 'fullIndex')
|
|
|
@@ -143,6 +141,7 @@ describe('ReferencesHandler', function () {
|
|
|
|
|
|
it('should return data', function (done) {
|
|
|
return this.call((err, data) => {
|
|
|
+ expect(err).to.be.null
|
|
|
expect(data).to.not.equal(null)
|
|
|
expect(data).to.not.equal(undefined)
|
|
|
expect(data).to.equal(this.fakeResponseData)
|
|
|
@@ -165,7 +164,7 @@ describe('ReferencesHandler', function () {
|
|
|
})
|
|
|
|
|
|
it('should not send request', function (done) {
|
|
|
- return this.call((err, data) => {
|
|
|
+ return this.call(() => {
|
|
|
this.request.post.callCount.should.equal(0)
|
|
|
return done()
|
|
|
})
|
|
|
@@ -187,7 +186,7 @@ describe('ReferencesHandler', function () {
|
|
|
})
|
|
|
|
|
|
it('should not send request', function (done) {
|
|
|
- return this.call((err, data) => {
|
|
|
+ return this.call(() => {
|
|
|
this.request.post.callCount.should.equal(0)
|
|
|
return done()
|
|
|
})
|
|
|
@@ -210,7 +209,7 @@ describe('ReferencesHandler', function () {
|
|
|
})
|
|
|
|
|
|
it('should not send request', function (done) {
|
|
|
- return this.call((err, data) => {
|
|
|
+ return this.call(() => {
|
|
|
this.request.post.callCount.should.equal(0)
|
|
|
return done()
|
|
|
})
|
|
|
@@ -237,7 +236,7 @@ describe('ReferencesHandler', function () {
|
|
|
})
|
|
|
|
|
|
it('should not send request', function (done) {
|
|
|
- return this.call((err, data) => {
|
|
|
+ return this.call(() => {
|
|
|
this.request.post.callCount.should.equal(0)
|
|
|
return done()
|
|
|
})
|