diff --git a/run/markdown-preview/editor/main.js b/run/markdown-preview/editor/main.js index 2285cad688..445e10eaff 100644 --- a/run/markdown-preview/editor/main.js +++ b/run/markdown-preview/editor/main.js @@ -78,5 +78,6 @@ app.listen(port, err => { // Exports for testing purposes. module.exports = { app, + buildService, buildTemplate } \ No newline at end of file diff --git a/run/markdown-preview/editor/package.json b/run/markdown-preview/editor/package.json index ffdd462d94..51d3378afd 100644 --- a/run/markdown-preview/editor/package.json +++ b/run/markdown-preview/editor/package.json @@ -15,7 +15,7 @@ "main": "main.js", "scripts": { "start": "node main.js", - "test": "mocha test/*.test.js" + "test": "mocha test/*.test.js --exit" }, "dependencies": { "express": "^4.17.1", diff --git a/run/markdown-preview/editor/test/main.test.js b/run/markdown-preview/editor/test/main.test.js index ed97008342..0b7491da51 100644 --- a/run/markdown-preview/editor/test/main.test.js +++ b/run/markdown-preview/editor/test/main.test.js @@ -18,12 +18,15 @@ const assert = require('assert'); const path = require('path'); const supertest = require('supertest'); -let request, template, htmlString, markdownString, falseString; +const env = Object.assign({}, process.env); + +let request, service, template, htmlString, markdownString, falseString; describe('Editor unit tests', () => { before(async () => { - const {app, buildTemplate} = require(path.join(__dirname, '..', 'main')); + const {app, buildService, buildTemplate} = require(path.join(__dirname, '..', 'main')); request = supertest(app); + service = async () => { return await buildService()}; template = await buildTemplate(); }); @@ -57,4 +60,25 @@ describe('Editor unit tests', () => { await request.post('/render').type('json').send('{"markdown":"valid string"}').expect(200); }); }); + + describe('Service builder', () => { + it('should respond with an error for no EDITOR_UPSTREAM_RENDER_URL var', async () => { + assert.rejects(await service, 'Error') + }); + + // Reload the server with updated env vars. + before(async () => { + process.env.EDITOR_UPSTREAM_RENDER_URL = 'https://www.example.com/'; + const {app, buildService} = require(path.join(__dirname, '..', 'main')); + request = supertest(app); + service = async () => { return await buildService()}; + }) + + it('should return an object with an EDITOR_UPSTREAM_RENDER_URL var', async () => { + const response = await service(); + assert.equal(response.url, process.env.EDITOR_UPSTREAM_RENDER_URL); + assert.equal(response.url, 'https://www.example.com/'); + assert.equal(response.isAuthenticated, true); + }) + }) }); diff --git a/run/markdown-preview/renderer/package.json b/run/markdown-preview/renderer/package.json index 033b9f0981..50d988db22 100644 --- a/run/markdown-preview/renderer/package.json +++ b/run/markdown-preview/renderer/package.json @@ -15,7 +15,7 @@ "main": "main.js", "scripts": { "start": "node main.js", - "test": "mocha test/*.test.js" + "test": "mocha test/*.test.js --exit" }, "dependencies": { "express": "^4.17.1",