From 9fdabb7a7f0b3779e89aecf0163d770f5262b9f8 Mon Sep 17 00:00:00 2001 From: ppaul Date: Tue, 1 Sep 2020 14:37:43 -0400 Subject: [PATCH] feat: minor fixes --- lib/server.js | 78 ++++++++++++++++++------------------- test/plugins/builds.test.js | 48 +++++++++++++++-------- 2 files changed, 69 insertions(+), 57 deletions(-) diff --git a/lib/server.js b/lib/server.js index d7157f4..3468d22 100644 --- a/lib/server.js +++ b/lib/server.js @@ -34,52 +34,48 @@ const CUSTOM_PLUGINS = [ * @return {http.Server} A listener: NodeJS http.Server object */ module.exports = async (config) => { - try { - let corsOrigins = [config.ecosystem.ui]; + let corsOrigins = [config.ecosystem.ui]; - if (Array.isArray(config.ecosystem.allowCors)) { - corsOrigins = corsOrigins.concat(config.ecosystem.allowCors); - } + if (Array.isArray(config.ecosystem.allowCors)) { + corsOrigins = corsOrigins.concat(config.ecosystem.allowCors); + } - // Allow ui to query store - const cors = { - origin: corsOrigins - }; + // Allow ui to query store + const cors = { + origin: corsOrigins + }; - // Create a server with a host and port - // Use Object.assign to pass httpd config - const server = Hapi.server({ - routes: { - cors, - log: { collect: true }, - payload: { timeout: 60000 } - }, - router: { - stripTrailingSlash: true - }, - cache: [config.cache], - ...config.httpd - }); + // Create a server with a host and port + // Use Object.assign to pass httpd config + const server = Hapi.server({ + routes: { + cors, + log: { collect: true }, + payload: { timeout: 60000 } + }, + router: { + stripTrailingSlash: true + }, + cache: [config.cache], + ...config.httpd + }); - // Register Plugins - /* eslint-disable */ - const coreRegistrations = CORE_PLUGINS.map(plugin => require(plugin)); - const customRegistrations = CUSTOM_PLUGINS.map(plugin => ({ - plugin: require(`../plugins/${plugin}`), - options: config[plugin] || {} - })); - /* eslint-enable */ + // Register Plugins + /* eslint-disable */ + const coreRegistrations = CORE_PLUGINS.map(plugin => require(plugin)); + const customRegistrations = CUSTOM_PLUGINS.map(plugin => ({ + plugin: require(`../plugins/${plugin}`), + options: config[plugin] || {} + })); + /* eslint-enable */ - await server.register(coreRegistrations.concat(customRegistrations), { - routes: { - prefix: '/v1' - } - }); + await server.register(coreRegistrations.concat(customRegistrations), { + routes: { + prefix: '/v1' + } + }); - await server.start(); + await server.start(); - return server; - } catch (err) { - throw err; - } + return server; }; diff --git a/test/plugins/builds.test.js b/test/plugins/builds.test.js index 297d035..72d735b 100644 --- a/test/plugins/builds.test.js +++ b/test/plugins/builds.test.js @@ -71,7 +71,8 @@ describe('builds plugin test', () => { credentials: { username: mockBuildID, scope: ['user'] - } }, + } + }, url: `/builds/${mockBuildID}/foo` }).then((response) => { assert.equal(response.statusCode, 404); @@ -114,7 +115,8 @@ describe('builds plugin test', () => { credentials: { username: mockBuildID, scope: ['user'] - } }, + } + }, url: `/builds/${mockBuildID}/foo` }).then((response) => { assert.equal(response.statusCode, 500); @@ -142,7 +144,8 @@ describe('builds plugin test', () => { credentials: { username: mockBuildID, scope: ['user'] - } }, + } + }, url: `/builds/${mockBuildID}/foo.html` }); @@ -173,7 +176,8 @@ describe('builds plugin test', () => { credentials: { username: mockBuildID, scope: ['user'] - } }, + } + }, url: `/builds/${mockBuildID}/foo` }); @@ -202,7 +206,8 @@ describe('builds plugin test', () => { credentials: { username: mockBuildID, scope: ['build'] - } } + } + } }; }); @@ -246,7 +251,8 @@ describe('builds plugin test', () => { credentials: { username: mockBuildID, scope: ['user'] - } } + } + } }); assert.equal(getResponse.statusCode, 200); @@ -262,7 +268,8 @@ describe('builds plugin test', () => { credentials: { username: mockBuildID, scope: ['user'] - } } + } + } }); assert.equal(downloadResponse.statusCode, 200); @@ -287,7 +294,8 @@ describe('builds plugin test', () => { credentials: { username: mockBuildID, scope: ['user'] - } } + } + } }); assert.equal(getResponse.statusCode, 200); @@ -303,7 +311,8 @@ describe('builds plugin test', () => { credentials: { username: mockBuildID, scope: ['user'] - } } + } + } }); assert.equal(downloadResponse.statusCode, 200); @@ -327,7 +336,8 @@ describe('builds plugin test', () => { credentials: { username: mockBuildID, scope: ['user'] - } } + } + } }).then((getResponse) => { assert.equal(getResponse.statusCode, 200); assert.equal(getResponse.headers['content-type'], 'text/plain; charset=utf-8'); @@ -351,7 +361,8 @@ describe('builds plugin test', () => { credentials: { username: mockBuildID, scope: ['user'] - } } + } + } }).then((getResponse) => { assert.equal(getResponse.statusCode, 200); assert.equal(getResponse.headers['content-type'], 'text/html; charset=utf-8'); @@ -376,7 +387,8 @@ describe('builds plugin test', () => { credentials: { username: mockBuildID, scope: ['pipeline'] - } } + } + } }).then((getResponse) => { assert.equal(getResponse.statusCode, 200); assert.equal(getResponse.result, 'THIS IS A TEST'); @@ -477,7 +489,8 @@ describe('builds plugin test using s3', () => { credentials: { username: mockBuildID, scope: ['user'] - } }, + } + }, url: `/builds/${mockBuildID}/foo.zip` }).then((response) => { assert.calledWith(getDownloadStreamMock, { @@ -501,7 +514,8 @@ describe('builds plugin test using s3', () => { credentials: { username: mockBuildID, scope: ['user'] - } }, + } + }, url: `/builds/${mockBuildID}/foo.zip` }).then((response) => { assert.calledWith(getDownloadStreamMock, { @@ -528,7 +542,8 @@ describe('builds plugin test using s3', () => { credentials: { username: mockBuildID, scope: ['build'] - } }, + } + }, url: `/builds/${mockBuildID}/foo.zip` }; }); @@ -547,7 +562,8 @@ describe('builds plugin test using s3', () => { strategy: 'token', credentials: { scope: ['user'] - } } + } + } }).then((getResponse) => { assert.equal(getResponse.statusCode, 204); assert.equal(getResponse.headers['content-type'], 'application/octet-stream');