From 7aef6d8a5956c0899dd69fd59357bac978064903 Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Sat, 27 Jul 2019 07:17:08 +0200 Subject: [PATCH] chore: organize block unit test add some extra context --- .secrets-baseline | 8 ++-- test/unit/modules/api/api.spec.ts | 69 ++++++++++++++++++------------- 2 files changed, 44 insertions(+), 33 deletions(-) diff --git a/.secrets-baseline b/.secrets-baseline index 00885476e..de455377d 100644 --- a/.secrets-baseline +++ b/.secrets-baseline @@ -3,7 +3,7 @@ "files": null, "lines": null }, - "generated_at": "2019-07-19T05:01:56Z", + "generated_at": "2019-07-27T05:16:42Z", "plugins_used": [ { "name": "AWSKeyDetector" @@ -270,12 +270,12 @@ "test/unit/modules/api/api.spec.ts": [ { "hashed_secret": "97752a468368b0d6b192140d6a140c38fd0cbd8b", - "line_number": 287, + "line_number": 292, "type": "Secret Keyword" }, { "hashed_secret": "364bdf2ed77a8544d3b711a03b69eeadcc63c9d7", - "line_number": 786, + "line_number": 799, "type": "Secret Keyword" } ], @@ -2985,5 +2985,5 @@ } ] }, - "version": "0.12.2" + "version": "0.12.4" } diff --git a/test/unit/modules/api/api.spec.ts b/test/unit/modules/api/api.spec.ts index d025a4bb7..a7c35508d 100644 --- a/test/unit/modules/api/api.spec.ts +++ b/test/unit/modules/api/api.spec.ts @@ -56,7 +56,10 @@ describe('endpoint unit test', () => { npmjs: { url: `http://${DOMAIN_SERVERS}:${mockServerPort}` } - } + }, + logs: [ + { type: 'stdout', format: 'pretty', level: 'warn' } + ] }, 'api.spec.yaml'); app = await endPointAPI(configForTest); @@ -307,6 +310,12 @@ describe('endpoint unit test', () => { }); describe('should test package api', () => { + // The current behaviour depends of what's defined in the following configuration file. + // test/unit/partials/config/yaml/api.spec.yaml + // 'jquery': + // access: $all + // publish: $all + // proxy: npmjs test('should fetch jquery package from remote uplink', (done) => { @@ -392,35 +401,37 @@ describe('endpoint unit test', () => { }); }); - test('be able to filter packages', (done) => { - request(app) - .get('/npm_test') - .set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET) - .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET) - .expect(HTTP_STATUS.OK) - .end(function(err, res) { - if (err) { - return done(err); - } - // Filter out 2.0.0 - expect(Object.keys(res.body.versions)).toEqual(['1.0.0']); - done(); - }); - }); + describe('testing filters', () => { + test('be able to filter packages', (done) => { + request(app) + .get('/npm_test') + .set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET) + .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET) + .expect(HTTP_STATUS.OK) + .end(function(err, res) { + if (err) { + return done(err); + } + // Filter out 2.0.0 + expect(Object.keys(res.body.versions)).toEqual(['1.0.0']); + done(); + }); + }); - test('should not found when a filter fails', (done) => { - request(app) - // Filter errors look like other uplink errors - .get('/trigger-filter-failure') - .set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET) - .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET) - .expect(HTTP_STATUS.NOT_FOUND) - .end(function(err, res) { - if (err) { - return done(err); - } - done(); - }); + test('should not found when a filter fails', (done) => { + request(app) + // Filter errors look like other uplink errors + .get('/trigger-filter-failure') + .set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET) + .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET) + .expect(HTTP_STATUS.NOT_FOUND) + .end(function(err, res) { + if (err) { + return done(err); + } + done(); + }); + }); }); test('should forbid access to remote package', (done) => {