mirror of
https://github.com/overleaf/overleaf.git
synced 2025-02-23 08:31:08 +00:00
Test the ReferencesSearchHandler
This commit is contained in:
parent
9280dd240b
commit
a63028bad3
2 changed files with 78 additions and 1 deletions
|
@ -38,5 +38,5 @@ module.exports = ReferencesSearchHandler =
|
|||
return callback(null, result)
|
||||
else
|
||||
err = new Error("references api responded with non-success code: #{res.statusCode}")
|
||||
logger.log {err, project_id, file_url}, "error getting references keys"
|
||||
logger.log {err, project_id}, "error getting references keys"
|
||||
return callback(err)
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
SandboxedModule = require('sandboxed-module')
|
||||
should = require('chai').should()
|
||||
expect = require('chai').expect
|
||||
sinon = require 'sinon'
|
||||
assert = require("chai").assert
|
||||
modulePath = "../../../../app/js/Features/ReferencesSearch/ReferencesSearchHandler"
|
||||
|
||||
describe 'ReferencesSearchHandler', ->
|
||||
|
||||
beforeEach ->
|
||||
@project_id = '222'
|
||||
@file_url = 'http://example.com/some/file'
|
||||
@handler = SandboxedModule.require modulePath, requires:
|
||||
'logger-sharelatex': {
|
||||
log: ->
|
||||
err: ->
|
||||
}
|
||||
'settings-sharelatex': @settings = {
|
||||
apis: {references: {url: 'http://some.url'}}
|
||||
}
|
||||
'request': @request = {
|
||||
get: sinon.stub()
|
||||
post: sinon.stub()
|
||||
}
|
||||
|
||||
describe 'indexFile', ->
|
||||
|
||||
describe 'when index operation is successful', ->
|
||||
beforeEach ->
|
||||
@request.post.callsArgWith(1, null, {statusCode: 201}, {})
|
||||
|
||||
it 'should not produce an error', (done) ->
|
||||
@handler.indexFile @project_id, @file_url, (err) =>
|
||||
expect(err).to.equal null
|
||||
done()
|
||||
|
||||
describe 'when index operation fails', ->
|
||||
beforeEach ->
|
||||
@request.post.callsArgWith(1, null, {statusCode: 500}, {})
|
||||
|
||||
it 'should produce an error', (done) ->
|
||||
@handler.indexFile @project_id, @file_url, (err) =>
|
||||
expect(err).to.not.equal null
|
||||
done()
|
||||
|
||||
describe 'getKeys', ->
|
||||
|
||||
describe 'when request is successful', ->
|
||||
beforeEach ->
|
||||
@data =
|
||||
projectId: @projectId
|
||||
keys: ['a', 'b', 'c']
|
||||
@request.get.callsArgWith(1, null, {statusCode: 200}, @data)
|
||||
|
||||
it 'should not produce an error', ->
|
||||
@handler.getKeys @project_id, (err, result) =>
|
||||
expect(err).to.equal null
|
||||
|
||||
it 'should produce a result object', ->
|
||||
@handler.getKeys @project_id, (err, result) =>
|
||||
expect(result).to.not.equal null
|
||||
expect(result).to.deep.equal @data
|
||||
|
||||
describe 'when request fails', ->
|
||||
beforeEach ->
|
||||
@data =
|
||||
projectId: @project_Id
|
||||
keys: ['a', 'b', 'c']
|
||||
@request.get.callsArgWith(1, null, {statusCode: 500}, null)
|
||||
|
||||
it 'should produce an error', ->
|
||||
@handler.getKeys @project_id, (err, result) =>
|
||||
expect(err).to.not.equal null
|
||||
|
||||
it 'should not produce a result', ->
|
||||
@handler.getKeys @project_id, (err, result) =>
|
||||
expect(result).to.not.equal null
|
Loading…
Reference in a new issue