From 10fcdd6daf38960b382322e77e18e9b21a2212fb Mon Sep 17 00:00:00 2001 From: Michael Mazour Date: Thu, 13 Sep 2018 12:14:06 +0100 Subject: [PATCH] Add optional gallery fields to export request Support the optional (well, gallery-only) fields `title`, `description`, `author`, `license`, and `show_source` in export requests. --- .../Features/Exports/ExportsController.coffee | 9 ++- .../Features/Exports/ExportsHandler.coffee | 9 ++- .../acceptance/coffee/ExportsTests.coffee | 14 ++++- .../Exports/ExportsControllerTests.coffee | 59 +++++++++++++++---- .../coffee/Exports/ExportsHandlerTests.coffee | 20 +++++++ 5 files changed, 96 insertions(+), 15 deletions(-) diff --git a/services/web/app/coffee/Features/Exports/ExportsController.coffee b/services/web/app/coffee/Features/Exports/ExportsController.coffee index e724951d2d..2f14fdb183 100644 --- a/services/web/app/coffee/Features/Exports/ExportsController.coffee +++ b/services/web/app/coffee/Features/Exports/ExportsController.coffee @@ -16,10 +16,17 @@ module.exports = if req.body && req.body.firstName && req.body.lastName export_params.first_name = req.body.firstName.trim() export_params.last_name = req.body.lastName.trim() + # additional parameters for gallery exports + if req.body + export_params.title = req.body.title.trim() if req.body.title + export_params.description = req.body.description.trim() if req.body.description + export_params.author = req.body.author.trim() if req.body.author + export_params.license = req.body.license.trim() if req.body.license + export_params.show_source = req.body.show_source if req.body.show_source ExportsHandler.exportProject export_params, (err, export_data) -> return next(err) if err? - logger.log + logger.log user_id:user_id project_id: project_id brand_variation_id:brand_variation_id diff --git a/services/web/app/coffee/Features/Exports/ExportsHandler.coffee b/services/web/app/coffee/Features/Exports/ExportsHandler.coffee index 234a334241..885f063c8b 100644 --- a/services/web/app/coffee/Features/Exports/ExportsHandler.coffee +++ b/services/web/app/coffee/Features/Exports/ExportsHandler.coffee @@ -20,9 +20,7 @@ module.exports = ExportsHandler = self = callback null, export_data _buildExport: (export_params, callback=(err, export_data) ->) -> - project_id = export_params.project_id - user_id = export_params.user_id - brand_variation_id = export_params.brand_variation_id + {project_id, user_id, brand_variation_id, title, description, author, license, show_source} = export_params jobs = project: (cb) -> ProjectGetter.getProject project_id, cb @@ -60,6 +58,11 @@ module.exports = ExportsHandler = self = metadata: compiler: project.compiler imageName: project.imageName + title: title + description: description + author: author + license: license + show_source: show_source user: id: user_id firstName: user.first_name diff --git a/services/web/test/acceptance/coffee/ExportsTests.coffee b/services/web/test/acceptance/coffee/ExportsTests.coffee index 7a6784008d..95e7b2984c 100644 --- a/services/web/test/acceptance/coffee/ExportsTests.coffee +++ b/services/web/test/acceptance/coffee/ExportsTests.coffee @@ -30,7 +30,13 @@ describe 'Exports', -> @owner.request { method: 'POST', url: "/project/#{@project_id}/export/#{@brand_variation_id}", - json: {}, + json: true, + body: + title: 'title' + description: 'description' + author: 'author' + license: 'other' + show_source: true }, (error, response, body) => throw error if error? expect(response.statusCode).to.equal 200 @@ -42,6 +48,12 @@ describe 'Exports', -> # project details should match expect(project.id).to.equal @project_id expect(project.rootDocPath).to.equal '/main.tex' + # gallery details should match + expect(project.metadata.title).to.equal 'title' + expect(project.metadata.description).to.equal 'description' + expect(project.metadata.author).to.equal 'author' + expect(project.metadata.license).to.equal 'other' + expect(project.metadata.show_source).to.equal true # version should match what was retrieved from project-history expect(project.historyVersion).to.equal @version # user details should match diff --git a/services/web/test/unit/coffee/Exports/ExportsControllerTests.coffee b/services/web/test/unit/coffee/Exports/ExportsControllerTests.coffee index 15d35707d9..4e96f68926 100644 --- a/services/web/test/unit/coffee/Exports/ExportsControllerTests.coffee +++ b/services/web/test/unit/coffee/Exports/ExportsControllerTests.coffee @@ -10,6 +10,13 @@ describe 'ExportsController', -> project_id = "123njdskj9jlk" user_id = "123nd3ijdks" brand_variation_id = 22 + firstName = 'first' + lastName = 'last' + title = "title" + description = "description" + author = "author" + license = "other" + show_source = true beforeEach -> @handler = @@ -18,6 +25,9 @@ describe 'ExportsController', -> params: project_id: project_id brand_variation_id: brand_variation_id + body: + firstName: firstName + lastName: lastName session: user: _id:user_id @@ -32,16 +42,45 @@ describe 'ExportsController', -> err:-> '../Authentication/AuthenticationController': @AuthenticationController - it 'should ask the handler to perform the export', (done) -> - @handler.exportProject = sinon.stub().yields(null, {iAmAnExport: true, v1_id: 897}) - expected = - project_id: project_id - user_id: user_id - brand_variation_id: brand_variation_id - @controller.exportProject @req, send:(body) => - expect(@handler.exportProject.args[0][0]).to.deep.equal expected - expect(body).to.deep.equal {export_v1_id: 897} - done() + describe "without gallery fields",-> + it 'should ask the handler to perform the export', (done) -> + @handler.exportProject = sinon.stub().yields(null, {iAmAnExport: true, v1_id: 897}) + expected = + project_id: project_id + user_id: user_id + brand_variation_id: brand_variation_id + first_name: firstName + last_name: lastName + @controller.exportProject @req, send:(body) => + expect(@handler.exportProject.args[0][0]).to.deep.equal expected + expect(body).to.deep.equal {export_v1_id: 897} + done() + + describe "with gallery fields",-> + beforeEach -> + @req.body.title = title + @req.body.description = description + @req.body.author = author + @req.body.license = license + @req.body.show_source = true + + it 'should ask the handler to perform the export', (done) -> + @handler.exportProject = sinon.stub().yields(null, {iAmAnExport: true, v1_id: 897}) + expected = + project_id: project_id + user_id: user_id + brand_variation_id: brand_variation_id + first_name: firstName + last_name: lastName + title: title + description: description + author: author + license: license + show_source: show_source + @controller.exportProject @req, send:(body) => + expect(@handler.exportProject.args[0][0]).to.deep.equal expected + 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( diff --git a/services/web/test/unit/coffee/Exports/ExportsHandlerTests.coffee b/services/web/test/unit/coffee/Exports/ExportsHandlerTests.coffee index 8b16088552..edd1ce127a 100644 --- a/services/web/test/unit/coffee/Exports/ExportsHandlerTests.coffee +++ b/services/web/test/unit/coffee/Exports/ExportsHandlerTests.coffee @@ -27,10 +27,20 @@ describe 'ExportsHandler', -> @project_history_id = 987 @user_id = "user-id-456" @brand_variation_id = 789 + @title = "title" + @description = "description" + @author = "author" + @license = "other" + @show_source = true @export_params = { project_id: @project_id, brand_variation_id: @brand_variation_id, user_id: @user_id + title: @title + description: @description + author: @author + license: @license + show_source: @show_source } @callback = sinon.stub() @@ -105,6 +115,11 @@ describe 'ExportsHandler', -> metadata: compiler: 'pdflatex' imageName: 'mock-image-name' + title: @title + description: @description + author: @author + license: @license + show_source: @show_source user: id: @user_id firstName: @user.first_name @@ -140,6 +155,11 @@ describe 'ExportsHandler', -> metadata: compiler: 'pdflatex' imageName: 'mock-image-name' + title: @title + description: @description + author: @author + license: @license + show_source: @show_source user: id: @user_id firstName: @custom_first_name