From 0321780eba458d8b4a062cd039597bce47d411fc Mon Sep 17 00:00:00 2001 From: hugh-obrien Date: Sat, 9 Jun 2018 13:23:07 +0100 Subject: [PATCH] adding tests for exports status checker --- .../Features/Exports/ExportsHandler.coffee | 1 - .../Exports/ExportsControllerTests.coffee | 12 +++++++ .../coffee/Exports/ExportsHandlerTests.coffee | 31 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/services/web/app/coffee/Features/Exports/ExportsHandler.coffee b/services/web/app/coffee/Features/Exports/ExportsHandler.coffee index 167dc8bba0..adedfc582b 100644 --- a/services/web/app/coffee/Features/Exports/ExportsHandler.coffee +++ b/services/web/app/coffee/Features/Exports/ExportsHandler.coffee @@ -104,7 +104,6 @@ module.exports = ExportsHandler = self = url: "#{settings.apis.v1.url}/api/v1/sharelatex/exports/#{export_id}" auth: {user: settings.apis.v1.user, pass: settings.apis.v1.pass } }, (err, res, body) -> - console.log(body) if err? logger.err err:err, export:export_id, "error making request to v1 export" callback err diff --git a/services/web/test/unit/coffee/Exports/ExportsControllerTests.coffee b/services/web/test/unit/coffee/Exports/ExportsControllerTests.coffee index 821eb5b4e0..7ec568cede 100644 --- a/services/web/test/unit/coffee/Exports/ExportsControllerTests.coffee +++ b/services/web/test/unit/coffee/Exports/ExportsControllerTests.coffee @@ -37,3 +37,15 @@ describe 'ExportsController', -> @controller.exportProject @req, send:(body) => expect(body).to.deep.equal {export_v1_id: 897} done() + + it 'should ask the handler to return the status of an export', (done) -> + @handler.fetchExport = sinon.stub().yields( + null, + "{\"id\":897, \"status_summary\":\"completed\"}") + + @req.params = {project_id: project_id, export_id: 897} + @controller.exportStatus @req, send:(body) => + expect(body).to.deep.equal {export_json: { + status_summary: 'completed', status_detail: undefined + }} + done() diff --git a/services/web/test/unit/coffee/Exports/ExportsHandlerTests.coffee b/services/web/test/unit/coffee/Exports/ExportsHandlerTests.coffee index f10f4631c1..e8beccddf9 100644 --- a/services/web/test/unit/coffee/Exports/ExportsHandlerTests.coffee +++ b/services/web/test/unit/coffee/Exports/ExportsHandlerTests.coffee @@ -235,3 +235,34 @@ describe 'ExportsHandler', -> it "should return the error", -> (@callback.args[0][0] instanceof Error) .should.equal true + + describe 'fetchExport', -> + beforeEach (done) -> + @settings.apis = + v1: + url: 'http://localhost:5000' + user: 'overleaf' + pass: 'pass' + @export_id = 897 + @body = "{\"id\":897, \"status_summary\":\"completed\"}" + @stubGet = sinon.stub().yields(null, {statusCode: 200}, { body: @body }) + done() + + describe "when all goes well", -> + beforeEach (done) -> + @stubRequest.get = @stubGet + @ExportsHandler.fetchExport @export_id, (error, body) => + @callback(error, body) + done() + + it 'should issue the request', -> + expect(@stubGet.getCall(0).args[0]).to.deep.equal + url: @settings.apis.v1.url + '/api/v1/sharelatex/exports/' + @export_id + auth: + user: @settings.apis.v1.user + pass: @settings.apis.v1.pass + + it 'should return the v1 export id', -> + @callback.calledWith(null, { body: @body }) + .should.equal true +