From fb3966ef354e823b4b1828c0a0d3c3d4219044ae Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Tue, 22 Jun 2021 12:13:19 +0100 Subject: [PATCH 1/2] [misc] CompileController: simplify composing of outputFiles --- services/clsi/app/js/CompileController.js | 14 ++------------ .../clsi/test/unit/js/CompileControllerTests.js | 12 ++---------- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/services/clsi/app/js/CompileController.js b/services/clsi/app/js/CompileController.js index 2813bca984..4307736d5a 100644 --- a/services/clsi/app/js/CompileController.js +++ b/services/clsi/app/js/CompileController.js @@ -123,7 +123,7 @@ module.exports = CompileController = { stats, timings, outputFiles: outputFiles.map((file) => { - const record = { + return { url: `${Settings.apis.clsi.url}/project/${request.project_id}` + (request.user_id != null @@ -131,18 +131,8 @@ module.exports = CompileController = { : '') + (file.build != null ? `/build/${file.build}` : '') + `/output/${file.path}`, - path: file.path, - type: file.type, - build: file.build, - contentId: file.contentId + ...file } - if (file.ranges != null) { - record.ranges = file.ranges - } - if (file.size != null) { - record.size = file.size - } - return record }) } }) diff --git a/services/clsi/test/unit/js/CompileControllerTests.js b/services/clsi/test/unit/js/CompileControllerTests.js index 6d6b34ee58..6236be77f0 100644 --- a/services/clsi/test/unit/js/CompileControllerTests.js +++ b/services/clsi/test/unit/js/CompileControllerTests.js @@ -157,11 +157,7 @@ describe('CompileController', function () { outputFiles: this.output_files.map((file) => { return { url: `${this.Settings.apis.clsi.url}/project/${this.project_id}/build/${file.build}/output/${file.path}`, - path: file.path, - type: file.type, - build: file.build, - // gets dropped by JSON.stringify - contentId: undefined + ...file } }) } @@ -202,11 +198,7 @@ describe('CompileController', function () { outputFiles: this.output_files.map((file) => { return { url: `${this.Settings.apis.clsi.url}/project/${this.project_id}/build/${file.build}/output/${file.path}`, - path: file.path, - type: file.type, - build: file.build, - // gets dropped by JSON.stringify - contentId: undefined + ...file } }) } From ffaff1bd7232de94be7cc58f0f84e6354eb3832e Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Tue, 22 Jun 2021 12:14:33 +0100 Subject: [PATCH 2/2] [CompileController] emit status=failure for an empty output.pdf file --- services/clsi/app/js/CompileController.js | 2 +- .../test/unit/js/CompileControllerTests.js | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/services/clsi/app/js/CompileController.js b/services/clsi/app/js/CompileController.js index 4307736d5a..63a4106aa0 100644 --- a/services/clsi/app/js/CompileController.js +++ b/services/clsi/app/js/CompileController.js @@ -88,7 +88,7 @@ module.exports = CompileController = { let file status = 'failure' for (file of Array.from(outputFiles)) { - if (file.path === 'output.pdf') { + if (file.path === 'output.pdf' && file.size > 0) { status = 'success' } } diff --git a/services/clsi/test/unit/js/CompileControllerTests.js b/services/clsi/test/unit/js/CompileControllerTests.js index 6236be77f0..3b29c867c4 100644 --- a/services/clsi/test/unit/js/CompileControllerTests.js +++ b/services/clsi/test/unit/js/CompileControllerTests.js @@ -99,6 +99,7 @@ describe('CompileController', function () { { path: 'output.pdf', type: 'pdf', + size: 1337, build: 1234 }, { @@ -207,6 +208,48 @@ describe('CompileController', function () { }) }) + describe('with an empty output.pdf', function () { + beforeEach(function () { + this.output_files = [ + { + path: 'output.pdf', + type: 'pdf', + size: 0, + build: 1234 + }, + { + path: 'output.log', + type: 'log', + build: 1234 + } + ] + this.CompileManager.doCompileWithLock = sinon + .stub() + .yields(null, this.output_files, this.stats, this.timings) + this.CompileController.compile(this.req, this.res) + }) + + it('should return the JSON response with status failure', function () { + this.res.status.calledWith(200).should.equal(true) + this.res.send + .calledWith({ + compile: { + status: 'failure', + error: null, + stats: this.stats, + timings: this.timings, + outputFiles: this.output_files.map((file) => { + return { + url: `${this.Settings.apis.clsi.url}/project/${this.project_id}/build/${file.build}/output/${file.path}`, + ...file + } + }) + } + }) + .should.equal(true) + }) + }) + describe('with an error', function () { beforeEach(function () { this.CompileManager.doCompileWithLock = sinon