diff --git a/.editorconfig b/.editorconfig index 944c376..78c6dde 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,4 +5,4 @@ end_of_line = lf insert_final_newline = true charset = utf-8 indent_style = space -indent_size = 2 \ No newline at end of file +indent_size = 2 diff --git a/.gitignore b/.gitignore index 8988168..8484af7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ /.idea /node_modules /src/locales -/coverage \ No newline at end of file +/coverage diff --git a/LICENSE b/LICENSE index 7f6f77f..3f0d6c0 100644 --- a/LICENSE +++ b/LICENSE @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE. diff --git a/language/en.yml b/language/en.yml index aefb629..7c86ba1 100644 --- a/language/en.yml +++ b/language/en.yml @@ -42,3 +42,4 @@ invalid_request: The request task %1% has unknown properties. response_not_success: 'The response was not success, %1% field was %2%' response_not_failure: 'The response was not failure, %1% field was %2%' no_errors_warnings: No errors or warnings found. +impossible_include: Can't include %1%'s export %2%. diff --git a/property/middlewares/max-time.ts b/property/middlewares/max-time.ts index 2397368..cbc0d21 100644 --- a/property/middlewares/max-time.ts +++ b/property/middlewares/max-time.ts @@ -1,9 +1,11 @@ -import MaxTime from '../../src/middlewares/max-time'; +import { + process as post, +} from '../../src/middlewares/max-time.js'; import { expect, } from 'chai'; import 'mocha'; -import Result from '../../src/messaging/result'; +import Result from '../../src/messaging/result.js'; import fc from 'fast-check'; describe('middlewares/max-time', () => { @@ -25,13 +27,13 @@ describe('middlewares/max-time', () => { }, }; if (duration > max) { - expect(() => MaxTime.process(response,),) + expect(() => post(response,),) .to.throw( `The response time was above ${ max } ns`, ); return; } - expect(() => MaxTime.process(response,),).to.not.throw(); + expect(() => post(response,),).to.not.throw(); }, ); },),); diff --git a/src/routes/include-default.ts b/src/routes/include-default.ts index 8ef3b2b..0b615f7 100644 --- a/src/routes/include-default.ts +++ b/src/routes/include-default.ts @@ -12,8 +12,8 @@ const include = async( path = path .replace(/\/\//ug, '/',) .replace(/\.ts$/u, INCLUDE_EXTENSION,); - const val = await import('file://' + path,)[part]; - if (typeof val !== 'function') { + const val = (await import('file://' + path,))[part]; + if (typeof val === 'undefined') { throw new Error(language('impossible_include', path, part,),); } if (part === 'default' && isCallable(val,)) { diff --git a/src/routes/validate-tasks.ts b/src/routes/validate-tasks.ts index 4e12a56..c7c1359 100644 --- a/src/routes/validate-tasks.ts +++ b/src/routes/validate-tasks.ts @@ -1,9 +1,9 @@ import Task from './task.js'; -import language from './helper/language.js'; +import language from '../helper/language.js'; import { EMPTY, -} from './constants.js'; -import noDuplicateIds from './no-duplicate-ids.js'; +} from '../constants.js'; +import noDuplicateIds from '../validation/no-duplicate-ids.js'; const executableAmount = ( repetitions: number, diff --git a/src/worker/runner.ts b/src/worker/runner.ts index f7b468a..a470014 100644 --- a/src/worker/runner.ts +++ b/src/worker/runner.ts @@ -5,7 +5,7 @@ import { import Task from '../routes/task.js'; import { prepare, - process, + process as post, } from '../middlewares/middleware.js'; import load from '../routes/middleware-loader.js'; @@ -45,10 +45,10 @@ const handlePost = async(task: Task, res:Result, callable: Callback,) => { for (const validator of task.post) { try { // eslint-disable-next-line no-await-in-loop - const validatorMiddleware: process = await load( + const validatorMiddleware: post = await load( validator, 'post', - ) as process; + ) as post; validatorMiddleware(res,); } catch (er) { callable(buildAnswer(res, er+'', false,),); diff --git a/test/helper/middleware-loader.ts b/test/helper/middleware-loader.ts index 1361323..c8def96 100644 --- a/test/helper/middleware-loader.ts +++ b/test/helper/middleware-loader.ts @@ -1,4 +1,4 @@ -import loader from '../../src/routes/middleware-loader'; +import loader from '../../src/routes/middleware-loader.js'; import { expect, } from 'chai'; @@ -15,36 +15,36 @@ const __dirname = url.fileURLToPath(new URL('.', import.meta.url,),); const basedir = realpathSync(__dirname + '../..',); describe('helper/middleware-loader', () => { - it('should be a string', () => { + it('should be a function', () => { expect(loader,).to.be.a('function',); },); it('should load by absolute path', async() => { - expect(await loader(__dirname + '../../src/middlewares/cookie',),) + expect(await loader(__dirname + '../../src/middlewares/cookie', 'post',),) .to.be.a('function',); },); it('should load by ^-path', async() => { - expect(await loader('^cookie',),).to.be.a('function',); + expect(await loader('^cookie', 'post',),).to.be.a('function',); },); it('should load by ^-path and skip the default key', async() => { - expect(await loader('^encoding',),).to.be.a('function',); + expect(await loader('^encoding', 'pre',),).to.be.a('function',); },); it('should load by #-path', async() => { - expect(await loader('#cookie',),).to.be.a('function',); + expect(await loader('#cookie', 'pre',),).to.be.a('function',); },); it('should load by $-path', async() => { try { - await loader('$needle/cookie',); + await loader('$needle/cookie', 'post',); // eslint-disable-next-line no-unused-expressions expect(false,).to.be.true; } catch (e) { if (sep === '/') { expect(`${ e }`,).to.equal(`Error: Cannot find module '${ basedir }` + '/node_modules/needle/src/middlewares/cookie.ts\' ' - + `imported from ${ basedir }/src/helper/include-default.ts`,); + + `imported from ${ basedir }/src/routes/include-default.ts`,); } else { expect(`${ e }`,).to.equal(`Error: Cannot find module '${ basedir }` + '\\node_modules\\needle\\src\\middlewares\\cookie.ts\' ' - + `imported from ${ basedir }\\src\\helper\\include-default.ts`,); + + `imported from ${ basedir }\\src\\routes\\include-default.ts`,); } } },); diff --git a/test/helper/user-agent.ts b/test/helper/user-agent.ts index 36122ed..d2fd15f 100644 --- a/test/helper/user-agent.ts +++ b/test/helper/user-agent.ts @@ -11,25 +11,25 @@ describe('helper/user-agent', () => { it('should match expectations', () => { expect(userAgent,).to.match( // eslint-disable-next-line max-len - /^@idrinth-api-bench\/framework\/\d+\.\d+ @idrinth\/api-bench\/\d+\.\d+ needle\/\d+\.\d+$/u, + /^@idrinth-api-bench\/framework\/\d+\.\d+ @idrinth-api-bench\/framework\/\d+\.\d+ needle\/\d+\.\d+$/u, ); },); it('should not be root version 0.0', () => { expect(userAgent,).to.not.match( // eslint-disable-next-line max-len - /^@idrinth-api-bench\/framework\/0+\.0+ @idrinth\/api-bench\/\d+\.\d+ needle\/\d+\.\d+$/u, + /^@idrinth-api-bench\/framework\/0+\.0+ @idrinth-api-bench\/framework\/\d+\.\d+ needle\/\d+\.\d+$/u, ); },); it('should not be needle version 0.0', () => { expect(userAgent,).to.not.match( // eslint-disable-next-line max-len - /^@idrinth-api-bench\/framework\/\d+\.\d+ @idrinth\/api-bench\/\d+\.\d+ needle\/0\.0$/u, + /^@idrinth-api-bench\/framework\/\d+\.\d+ @idrinth-api-bench\/framework\/\d+\.\d+ needle\/0\.0$/u, ); },); it('should not be api-bench version 0.0', () => { expect(userAgent,).to.not.match( // eslint-disable-next-line max-len - /^@idrinth-api-bench\/framework\/\d+\.\d+ @idrinth\/api-bench\/0\.0 needle\/\d+\.\d+$/u, + /^@idrinth-api-bench\/framework\/\d+\.\d+ @idrinth-api-bench\/framework\/0\.0 needle\/\d+\.\d+$/u, ); },); },); diff --git a/test/middlewares/access-token.ts b/test/middlewares/access-token.ts index 8d1594d..ea67487 100644 --- a/test/middlewares/access-token.ts +++ b/test/middlewares/access-token.ts @@ -1,29 +1,29 @@ -import Access from '../../src/middlewares/access-token'; +import { + prepare as pre, + process as post, +} from '../../src/middlewares/access-token.js'; import { expect, } from 'chai'; import 'mocha'; -import Request from '../../src/routes/request'; -import Result from '../../src/messaging/result'; -import store from '../../src/store/store'; +import Request from '../../src/routes/request.js'; +import Result from '../../src/messaging/result.js'; +import store from '../../src/store/store.js'; describe('middlewares/csrf-header', () => { before(store.clean,); after(store.clean,); - it('should be a class', () => { - expect(Access,).to.be.a('function',); - },); it('should have a static method prepare', () => { - expect(Access.prepare,).to.be.a('function',); + expect(pre,).to.be.a('function',); },); it('should have a static method process', () => { - expect(Access.process,).to.be.a('function',); + expect(post,).to.be.a('function',); },); it('should not set token by default', () => { - expect(Access.prepare({},),).to.deep.equal({},); + expect(pre({},),).to.deep.equal({},); },); it('should get token by default', () => { - expect(() => Access.process({ + expect(() => post({ response: { headers: { 'content-type': 'application/json', @@ -33,26 +33,26 @@ describe('middlewares/csrf-header', () => { },),).to.not.throw(); },); it('should set token it has', () => { - expect(Access.prepare({},),).to.deep.equal({ + expect(pre({},),).to.deep.equal({ headers: { 'authorization': 'Bearer 11', }, },); },); it('should change no token if the response is incomplete', () => { - expect(() => Access.process({ + expect(() => post({ response: {}, },),).to.not.throw(); },); it('should set token it has', () => { - expect(Access.prepare({},),).to.deep.equal({ + expect(pre({},),).to.deep.equal({ headers: { 'authorization': 'Bearer 11', }, },); },); it('should get refresh-token by default', () => { - expect(() => Access.process({ + expect(() => post({ response: { headers: { 'content-type': 'application/json', @@ -62,7 +62,7 @@ describe('middlewares/csrf-header', () => { },),).to.not.throw(); },); it('should set all tokens it has', () => { - expect(Access.prepare({ + expect(pre({ body: '%refresh-token-middleware%%access-token-middleware%', },),).to.deep.equal({ headers: { diff --git a/test/middlewares/cookie.ts b/test/middlewares/cookie.ts index 3180abe..958d9dd 100644 --- a/test/middlewares/cookie.ts +++ b/test/middlewares/cookie.ts @@ -1,31 +1,31 @@ -import Cookie from '../../src/middlewares/cookie'; +import { + prepare as pre, + process as post, +} from '../../src/middlewares/cookie.js'; import { expect, } from 'chai'; import 'mocha'; -import Request from '../../src/routes/request'; -import Result from '../../src/messaging/result'; -import store from '../../src/store/store'; +import Request from '../../src/routes/request.js'; +import Result from '../../src/messaging/result.js'; +import store from '../../src/store/store.js'; describe('middlewares/cookie', () => { before(store.clean,); after(store.clean,); - it('should be a class', () => { - expect(Cookie,).to.be.a('function',); - },); it('should have a static method prepare', () => { - expect(Cookie.prepare,).to.be.a('function',); + expect(pre,).to.be.a('function',); },); it('should have a static method process', () => { - expect(Cookie.process,).to.be.a('function',); + expect(post,).to.be.a('function',); },); it('should not set cookies by default', () => { - expect(Cookie.prepare({},),).to.deep.equal({ + expect(pre({},),).to.deep.equal({ cookies: {}, },); },); it('should get cookies by default', () => { - expect(() => Cookie.process({ + expect(() => post({ response: { cookies: { abc: 'def', @@ -34,26 +34,26 @@ describe('middlewares/cookie', () => { },),).to.not.throw(); },); it('should set cookies it has', () => { - expect(Cookie.prepare({},),).to.deep.equal({ + expect(pre({},),).to.deep.equal({ cookies: { abc: 'def', }, },); },); it('should change no cookies if there are none', () => { - expect(() => Cookie.process({ + expect(() => post({ response: { cookies: {}, }, },),).to.not.throw(); },); it('should change no cookies if the response is incomplete', () => { - expect(() => Cookie.process({ + expect(() => post({ response: {}, },),).to.not.throw(); },); it('should set cookies it has', () => { - expect(Cookie.prepare({},),).to.deep.equal({ + expect(pre({},),).to.deep.equal({ cookies: { abc: 'def', }, diff --git a/test/middlewares/csrf-header.ts b/test/middlewares/csrf-header.ts index 6b446f5..97d4357 100644 --- a/test/middlewares/csrf-header.ts +++ b/test/middlewares/csrf-header.ts @@ -1,29 +1,29 @@ -import CsrfHeader from '../../src/middlewares/csrf-header'; +import { + prepare as pre, + process as post, +} from '../../src/middlewares/csrf-header.js'; import { expect, } from 'chai'; import 'mocha'; -import Request from '../../src/routes/request'; -import Result from '../../src/messaging/result'; -import store from '../../src/store/store'; +import Request from '../../src/routes/request.js'; +import Result from '../../src/messaging/result.js'; +import store from '../../src/store/store.js'; describe('middlewares/csrf-header', () => { before(store.clean,); after(store.clean,); - it('should be a class', () => { - expect(CsrfHeader,).to.be.a('function',); - },); it('should have a static method prepare', () => { - expect(CsrfHeader.prepare,).to.be.a('function',); + expect(pre,).to.be.a('function',); },); it('should have a static method process', () => { - expect(CsrfHeader.process,).to.be.a('function',); + expect(post,).to.be.a('function',); },); it('should not set token by default', () => { - expect(CsrfHeader.prepare({},),).to.deep.equal({},); + expect(pre({},),).to.deep.equal({},); },); it('should get token by default', () => { - expect(() => CsrfHeader.process({ + expect(() => post({ response: { headers: { 'x-csrf-token': 'def', @@ -32,26 +32,26 @@ describe('middlewares/csrf-header', () => { },),).to.not.throw(); },); it('should set token it has', () => { - expect(CsrfHeader.prepare({},),).to.deep.equal({ + expect(pre({},),).to.deep.equal({ headers: { 'x-csrf-token': 'def', }, },); },); it('should change no token if there\'s none', () => { - expect(() => CsrfHeader.process({ + expect(() => post({ response: { headers: {}, }, },),).to.not.throw(); },); it('should change no token if the response is incomplete', () => { - expect(() => CsrfHeader.process({ + expect(() => post({ response: {}, },),).to.not.throw(); },); it('should set token it has', () => { - expect(CsrfHeader.prepare({},),).to.deep.equal({ + expect(pre({},),).to.deep.equal({ headers: { 'x-csrf-token': 'def', }, diff --git a/test/middlewares/encoding.ts b/test/middlewares/encoding.ts index cb2c06a..e734163 100644 --- a/test/middlewares/encoding.ts +++ b/test/middlewares/encoding.ts @@ -1,22 +1,18 @@ -import Encoding from '../../src/middlewares/encoding'; +import { + prepare as pre, +} from '../../src/middlewares/encoding.js'; import { expect, } from 'chai'; import 'mocha'; -import Request from '../../src/routes/request'; +import Request from '../../src/routes/request.js'; describe('middlewares/encoding', () => { - it('should be a class', () => { - expect(Encoding,).to.be.a('function',); - },); it('should have a static method prepare', () => { - expect(Encoding.prepare,).to.be.a('function',); - },); - it('should have a static method process', () => { - expect(Encoding.process,).to.be.a('function',); + expect(pre,).to.be.a('function',); },); it('prepare should json-transform object to string', () => { - expect(Encoding.prepare({ + expect(pre({ body: { a: 'b', }, @@ -24,13 +20,13 @@ describe('middlewares/encoding', () => { },).body,).to.equal('{"a":"b"}',); },); it('prepare should json-transform array to string', () => { - expect(Encoding.prepare({ + expect(pre({ body: [ 'a', ], autohandle: 'json', },).body,).to.equal('["a"]',); },); it('prepare should form-transform object to string', () => { - expect(Encoding.prepare({ + expect(pre({ body: { a: 'b', }, @@ -38,7 +34,7 @@ describe('middlewares/encoding', () => { },).body,).to.equal('a=b',); },); it('prepare should not transform by default', () => { - expect(Encoding.prepare({ + expect(pre({ body: {}, },).body,).to.deep.equal({},); },); diff --git a/test/middlewares/failure-check.ts b/test/middlewares/failure-check.ts index 6e7bd35..943dfda 100644 --- a/test/middlewares/failure-check.ts +++ b/test/middlewares/failure-check.ts @@ -1,21 +1,17 @@ /* eslint-disable max-len */ -import FailureCheck from '../../src/middlewares/failure-check'; +import { + process as post, +} from '../../src/middlewares/failure-check.js'; import { expect, } from 'chai'; import 'mocha'; -import StandardResponse from '../../src/helper/standard-response'; -import Result from '../../src/messaging/result'; +import StandardResponse from '../../src/helper/standard-response.js'; +import Result from '../../src/messaging/result.js'; describe('middlewares/failure-check', () => { - it('should be a class', () => { - expect(FailureCheck,).to.be.a('function',); - },); - it('should have a static method prepare', () => { - expect(FailureCheck.prepare,).to.be.a('function',); - },); it('should have a static method process', () => { - expect(FailureCheck.process,).to.be.a('function',); + expect(post,).to.be.a('function',); },); const bodyForSuccessResponse : Array = [ { @@ -46,7 +42,7 @@ describe('middlewares/failure-check', () => { it(`process should throw error for ${ field } field as ${ bodyObject[field] } `, () => { - expect(() => FailureCheck.process(input, ),).to.throw( + expect(() => post(input, ),).to.throw( `The response was not failure, ${ field } field was ${ bodyObject[field] }`, ); },); @@ -85,17 +81,7 @@ describe('middlewares/failure-check', () => { it(`process should not throw error for ${ field } field as ${ bodyObject[field] } `, () => { - expect(() => FailureCheck.process(input, ),).to.not.throw(); + expect(() => post(input, ),).to.not.throw(); },); } - - it('prepare should return input', () => { - const input = { - headers: {}, - cookies: {}, - body: 'body', - url: 'url', - }; - expect(FailureCheck.prepare(input,),).to.equal(input,); - },); },); diff --git a/test/middlewares/json-validator.ts b/test/middlewares/json-validator.ts index b9ab597..1342ba4 100644 --- a/test/middlewares/json-validator.ts +++ b/test/middlewares/json-validator.ts @@ -1,35 +1,23 @@ -import JsonValidator from '../../src/middlewares/json-validator'; +import { + process as post, +} from '../../src/middlewares/json-validator.js'; import { expect, } from 'chai'; import 'mocha'; -import Result from '../../src/messaging/result'; +import Result from '../../src/messaging/result.js'; describe('middlewares/json-validator', () => { - it('should be a class', () => { - expect(JsonValidator,).to.be.a('function',); - },); - describe('.prepare()', () => { - it('should be a function', () => { - expect(JsonValidator.prepare,).to.be.a('function',); - },); - it('should return the unchanged param', () => { - const param = { - method: 'get', - url: 'https://localhost', - }; - expect(JsonValidator.prepare(param,),).to.be.equal(param,); - },); - },); describe('.process()', () => { it('should be a function', () => { - expect(JsonValidator.process,).to.be.a('function',); + expect(post,).to.be.a('function',); },); it('should throw if there is no type', () => { const response: Result = { id: 'example', validators: [], duration: 234242, + maxDuration: 193, response: { headers: {}, cookies: {}, @@ -38,7 +26,7 @@ describe('middlewares/json-validator', () => { body: '{{]]', }, }; - expect(() => JsonValidator.process(response,),) + expect(() => post(response,),) .to.throw('The content-type header is missing.',); },); it('should throw if the type is not json', () => { @@ -46,6 +34,7 @@ describe('middlewares/json-validator', () => { id: 'example', validators: [], duration: 234242, + maxDuration: 193, response: { headers: { 'content-type': 'application/jason', @@ -56,7 +45,7 @@ describe('middlewares/json-validator', () => { body: '{{]]', }, }; - expect(() => JsonValidator.process(response,),) + expect(() => post(response,),) .to.throw( 'The content-type application/jason is not application/json.', ); @@ -66,6 +55,7 @@ describe('middlewares/json-validator', () => { id: 'example', validators: [], duration: 234242, + maxDuration: 193, response: { headers: { 'content-type': 'application/json', @@ -76,7 +66,7 @@ describe('middlewares/json-validator', () => { body: '{{]]', }, }; - expect(() => JsonValidator.process(response,),) + expect(() => post(response,),) .to.throw( 'The JSON body is invalid. SyntaxError:', ); @@ -86,6 +76,7 @@ describe('middlewares/json-validator', () => { id: 'example', validators: [], duration: 234242, + maxDuration: 193, response: { headers: { 'content-type': 'application/json', @@ -96,7 +87,7 @@ describe('middlewares/json-validator', () => { body: '{}', }, }; - expect(() => JsonValidator.process(response,),).to.not.throw(); + expect(() => post(response,),).to.not.throw(); },); },); },); diff --git a/test/middlewares/max-time.ts b/test/middlewares/max-time.ts index 561b917..4a6f044 100644 --- a/test/middlewares/max-time.ts +++ b/test/middlewares/max-time.ts @@ -1,29 +1,16 @@ -import MaxTime from '../../src/middlewares/max-time'; +import { + process as post, +} from '../../src/middlewares/max-time.js'; import { expect, } from 'chai'; import 'mocha'; -import Result from '../../src/messaging/result'; +import Result from '../../src/messaging/result.js'; describe('middlewares/max-time', () => { - it('should be a class', () => { - expect(MaxTime,).to.be.a('function',); - },); - describe('.prepare()', () => { - it('should be a function', () => { - expect(MaxTime.prepare,).to.be.a('function',); - },); - it('should return the unchanged param', () => { - const param = { - method: 'get', - url: 'https://localhost', - }; - expect(MaxTime.prepare(param,),).to.be.equal(param,); - },); - },); describe('.process()', () => { it('should be a function', () => { - expect(MaxTime.process,).to.be.a('function',); + expect(post,).to.be.a('function',); },); it('should throw if the response is too slow', () => { const response: Result = { @@ -39,7 +26,7 @@ describe('middlewares/max-time', () => { body: '', }, }; - expect(() => MaxTime.process(response,),) + expect(() => post(response,),) .to.throw( 'The response time was above 193 ns', ); @@ -58,7 +45,7 @@ describe('middlewares/max-time', () => { body: '', }, }; - expect(() => MaxTime.process(response,),).to.not.throw(); + expect(() => post(response,),).to.not.throw(); },); it('should not throw if there is no max time', () => { const response: Result = { @@ -75,7 +62,7 @@ describe('middlewares/max-time', () => { body: '', }, }; - expect(() => MaxTime.process(response,),).to.not.throw(); + expect(() => post(response,),).to.not.throw(); },); },); },); diff --git a/test/middlewares/silent-server-validator.ts b/test/middlewares/silent-server-validator.ts index 11592ca..e382389 100644 --- a/test/middlewares/silent-server-validator.ts +++ b/test/middlewares/silent-server-validator.ts @@ -1,22 +1,15 @@ -import SSV from '../../src/middlewares/silent-server-validator'; +import { + process as post, +} from '../../src/middlewares/silent-server-validator.js'; import { expect, } from 'chai'; import 'mocha'; -import { - NeedleHttpVerbs, -} from 'needle'; -import Result from '../../src/messaging/result'; +import Result from '../../src/messaging/result.js'; describe('middlewares/silent-server-validator', () => { - it('should be a class', () => { - expect(SSV,).to.be.a('function',); - },); - it('should have a static method prepare', () => { - expect(SSV.prepare,).to.be.a('function',); - },); it('should have a static method process', () => { - expect(SSV.process,).to.be.a('function',); + expect(post,).to.be.a('function',); },); it('process should not throw if there are no headers', () => { const input = { @@ -33,7 +26,7 @@ describe('middlewares/silent-server-validator', () => { validators: [], }; expect( - () => SSV.process(input as Result,), + () => post(input as Result,), ).to.not.throw(); },); it('process should not throw if there is a Server header', () => { @@ -51,8 +44,9 @@ describe('middlewares/silent-server-validator', () => { duration: 0, id: '', validators: [], + maxDuration: 0, }; - expect(() => SSV.process(input as Result,),).to.throw( + expect(() => post(input as Result,),).to.throw( 'The header Server is set. Remove this', ); },); @@ -71,20 +65,11 @@ describe('middlewares/silent-server-validator', () => { duration: 0, id: '', validators: [], + maxDuration: 0, }; - expect(() => SSV.process(input as Result,),).to.throw( + expect(() => post(input as Result,),).to.throw( 'The header X-Powered-By is set. ' + 'It shares critical information with the world.', ); },); - it('prepare should return input', () => { - const input = { - method: 'head' as NeedleHttpVerbs, - headers: {}, - cookies: {}, - body: 'body', - url: 'url', - }; - expect(SSV.prepare(input,),).to.equal(input,); - },); },); diff --git a/test/middlewares/status-2xx.ts b/test/middlewares/status-2xx.ts index 0711b55..85c4ae5 100644 --- a/test/middlewares/status-2xx.ts +++ b/test/middlewares/status-2xx.ts @@ -1,22 +1,15 @@ /* eslint no-magic-numbers: 0 */ -import Status2xx from '../../src/middlewares/status-2xx'; +import { + process as post, +} from '../../src/middlewares/status-2xx.js'; import { expect, } from 'chai'; import 'mocha'; -import { - NeedleHttpVerbs, -} from 'needle'; describe('middlewares/status-2xx', () => { - it('should be a class', () => { - expect(Status2xx,).to.be.a('function',); - },); - it('should have a static method prepare', () => { - expect(Status2xx.prepare,).to.be.a('function',); - },); it('should have a static method process', () => { - expect(Status2xx.process,).to.be.a('function',); + expect(post,).to.be.a('function',); },); for (let i=0; i<100; i ++) { it(`process should throw for status ${ 100+i }`, () => { @@ -31,8 +24,9 @@ describe('middlewares/status-2xx', () => { duration: 0, id: '', validators: [], + maxDuration: 0, }; - expect(() => Status2xx.process(input,),).to.throw( + expect(() => post(input,),).to.throw( 'Request returned status below 200-299 range', ); },); @@ -50,8 +44,9 @@ describe('middlewares/status-2xx', () => { duration: 0, id: '', validators: [], + maxDuration: 0, }; - expect(() => Status2xx.process(input,),).to.not.throw(); + expect(() => post(input,),).to.not.throw(); },); } for (let i=0; i<700; i ++) { @@ -67,8 +62,9 @@ describe('middlewares/status-2xx', () => { duration: 0, id: '', validators: [], + maxDuration: 0, }; - expect(() => Status2xx.process(input,),).to.throw( + expect(() => post(input,),).to.throw( 'Request returned status above 200-299 range', ); },); @@ -86,19 +82,10 @@ describe('middlewares/status-2xx', () => { duration: 0, id: '', validators: [], + maxDuration: 0, }; - expect(() => Status2xx.process(input,),).to.throw( + expect(() => post(input,),).to.throw( 'Request returned no status', ); },); - it('prepare should return input', () => { - const input = { - method: 'head' as NeedleHttpVerbs, - headers: {}, - cookies: {}, - body: 'body', - url: 'url', - }; - expect(Status2xx.prepare(input,),).to.equal(input,); - },); },); diff --git a/test/middlewares/status-403.ts b/test/middlewares/status-403.ts index b0b1a7a..ef877fe 100644 --- a/test/middlewares/status-403.ts +++ b/test/middlewares/status-403.ts @@ -1,22 +1,15 @@ /* eslint no-magic-numbers: 0 */ -import Status403 from '../../src/middlewares/status-403'; +import { + process as post, +} from '../../src/middlewares/status-403.js'; import { expect, } from 'chai'; import 'mocha'; -import { - NeedleHttpVerbs, -} from 'needle'; describe('middlewares/status-403', () => { - it('should be a class', () => { - expect(Status403,).to.be.a('function',); - },); - it('should have a static method prepare', () => { - expect(Status403.prepare,).to.be.a('function',); - },); it('should have a static method process', () => { - expect(Status403.process,).to.be.a('function',); + expect(post,).to.be.a('function',); },); for (let i=100; i<403; i ++) { it(`process should throw for status ${ i }`, () => { @@ -30,9 +23,10 @@ describe('middlewares/status-403', () => { }, duration: 0, id: '', + maxDuration: 0, validators: [], }; - expect(() => Status403.process(input,),).to.throw( + expect(() => post(input,),).to.throw( `Request returned status ${ i }, not 403`, ); },); @@ -50,7 +44,7 @@ describe('middlewares/status-403', () => { id: '', validators: [], }; - expect(() => Status403.process(input,),).to.not.throw(); + expect(() => post(input,),).to.not.throw(); },); for (let i=404; i<1000; i ++) { it(`process should throw for status ${ i }`, () => { @@ -63,10 +57,11 @@ describe('middlewares/status-403', () => { uri: '', }, duration: 0, + maxDuration: 0, id: '', validators: [], }; - expect(() => Status403.process(input,),).to.throw( + expect(() => post(input,),).to.throw( `Request returned status ${ i }, not 403`, ); },); @@ -84,19 +79,10 @@ describe('middlewares/status-403', () => { duration: 0, id: '', validators: [], + maxDuration: 0, }; - expect(() => Status403.process(input,),).to.throw( + expect(() => post(input,),).to.throw( 'Request returned no status', ); },); - it('prepare should return input', () => { - const input = { - method: 'head' as NeedleHttpVerbs, - headers: {}, - cookies: {}, - body: 'body', - url: 'url', - }; - expect(Status403.prepare(input,),).to.equal(input,); - },); },); diff --git a/test/middlewares/status-404.ts b/test/middlewares/status-404.ts index 587d776..1286594 100644 --- a/test/middlewares/status-404.ts +++ b/test/middlewares/status-404.ts @@ -1,22 +1,15 @@ /* eslint no-magic-numbers: 0 */ -import Status404 from '../../src/middlewares/status-404'; +import { + process as post, +} from '../../src/middlewares/status-404.js'; import { expect, } from 'chai'; import 'mocha'; -import { - NeedleHttpVerbs, -} from 'needle'; describe('middlewares/status-404', () => { - it('should be a class', () => { - expect(Status404,).to.be.a('function',); - },); - it('should have a static method prepare', () => { - expect(Status404.prepare,).to.be.a('function',); - },); it('should have a static method process', () => { - expect(Status404.process,).to.be.a('function',); + expect(post,).to.be.a('function',); },); for (let i=100; i<404; i ++) { it(`process should throw for status ${ i }`, () => { @@ -31,8 +24,9 @@ describe('middlewares/status-404', () => { duration: 0, id: '', validators: [], + maxDuration: 0, }; - expect(() => Status404.process(input,),).to.throw( + expect(() => post(input,),).to.throw( `Request returned status ${ i }, not 404`, ); },); @@ -49,8 +43,9 @@ describe('middlewares/status-404', () => { duration: 0, id: '', validators: [], + maxDuration: 0, }; - expect(() => Status404.process(input,),).to.not.throw(); + expect(() => post(input,),).to.not.throw(); },); for (let i=405; i<1000; i ++) { it(`process should throw for status ${ i }`, () => { @@ -65,8 +60,9 @@ describe('middlewares/status-404', () => { duration: 0, id: '', validators: [], + maxDuration: 0, }; - expect(() => Status404.process(input,),).to.throw( + expect(() => post(input,),).to.throw( `Request returned status ${ i }, not 404`, ); },); @@ -84,19 +80,10 @@ describe('middlewares/status-404', () => { duration: 0, id: '', validators: [], + maxDuration: 0, }; - expect(() => Status404.process(input,),).to.throw( + expect(() => post(input,),).to.throw( 'Request returned no status', ); },); - it('prepare should return input', () => { - const input = { - method: 'head' as NeedleHttpVerbs, - headers: {}, - cookies: {}, - body: 'body', - url: 'url', - }; - expect(Status404.prepare(input,),).to.equal(input,); - },); },); diff --git a/test/middlewares/success-check.ts b/test/middlewares/success-check.ts index 0377150..9b67230 100644 --- a/test/middlewares/success-check.ts +++ b/test/middlewares/success-check.ts @@ -1,21 +1,17 @@ /* eslint-disable max-len */ -import SuccessCheck from '../../src/middlewares/success-check'; +import { + process as post, +} from '../../src/middlewares/success-check.js'; import { expect, } from 'chai'; import 'mocha'; -import StandardResponse from '../../src/helper/standard-response'; -import Result from '../../src/messaging/result'; +import StandardResponse from '../../src/helper/standard-response.js'; +import Result from '../../src/messaging/result.js'; describe('middlewares/success-check', () => { - it('should be a class', () => { - expect(SuccessCheck,).to.be.a('function',); - },); - it('should have a static method prepare', () => { - expect(SuccessCheck.prepare,).to.be.a('function',); - },); it('should have a static method process', () => { - expect(SuccessCheck.process,).to.be.a('function',); + expect(post,).to.be.a('function',); },); const bodyForFailureResponse : Array = [ { @@ -49,7 +45,7 @@ describe('middlewares/success-check', () => { it(`process should throw error for ${ field } field as ${ bodyObject[field] } `, () => { - expect(() => SuccessCheck.process(input, ),).to.throw( + expect(() => post(input, ),).to.throw( `The response was not success, ${ field } field was ${ bodyObject[field] }`, ); },); @@ -85,17 +81,7 @@ describe('middlewares/success-check', () => { it(`process should not throw error for ${ field } field as ${ bodyObject[field] } `, () => { - expect(() => SuccessCheck.process(input, ),).to.not.throw(); + expect(() => post(input, ),).to.not.throw(); },); } - - it('prepare should return input', () => { - const input = { - headers: {}, - cookies: {}, - body: 'body', - url: 'url', - }; - expect(SuccessCheck.prepare(input,),).to.equal(input,); - },); },); diff --git a/test/middlewares/user-agent.ts b/test/middlewares/user-agent.ts index 9b924eb..bf955a7 100644 --- a/test/middlewares/user-agent.ts +++ b/test/middlewares/user-agent.ts @@ -1,22 +1,18 @@ -import UserAgent from '../../src/middlewares/user-agent'; +import { + prepare as pre, +} from '../../src/middlewares/user-agent.js'; import { expect, } from 'chai'; import 'mocha'; -import Request from '../../src/routes/request'; +import Request from '../../src/routes/request.js'; describe('middlewares/user-agent', () => { - it('should be a class', () => { - expect(UserAgent,).to.be.a('function',); - },); it('should have a static method prepare', () => { - expect(UserAgent.prepare,).to.be.a('function',); - },); - it('should have a static method process', () => { - expect(UserAgent.process,).to.be.a('function',); + expect(pre,).to.be.a('function',); },); it('prepare should add a user agent header', () => { - expect(UserAgent.prepare({},).headers['user-agent'],).to.be.a( + expect(pre({},).headers['user-agent'],).to.be.a( 'string', ); },); diff --git a/test/middlewares/xml-validator.ts b/test/middlewares/xml-validator.ts index cb6663a..2887161 100644 --- a/test/middlewares/xml-validator.ts +++ b/test/middlewares/xml-validator.ts @@ -1,102 +1,91 @@ -import XMLValidator from '../../src/middlewares/xml-validator'; +import { + process as post, +} from '../../src/middlewares/xml-validator.js'; import { expect, } from 'chai'; import 'mocha'; -import Result from '../../src/messaging/result'; +import Result from '../../src/messaging/result.js'; describe('middlewares/xml-validator', () => { - it('should be a class', () => { - expect(XMLValidator,).to.be.a('function',); + it('should be a function', () => { + expect(post,).to.be.a('function',); },); - describe('.prepare()', () => { - it('should be a function', () => { - expect(XMLValidator.prepare,).to.be.a('function',); - },); - it('should return the unchanged param', () => { - const param = { - method: 'get', - url: 'https://localhost', - }; - expect(XMLValidator.prepare(param,),).to.be.equal(param,); - },); + it('should throw if there is no type', () => { + const response: Result = { + id: 'example', + validators: [], + maxDuration: 0, + duration: 234242, + response: { + headers: {}, + cookies: {}, + uri: '', + status: 0, + body: '{{]]', + }, + }; + expect(() => post(response,),) + .to.throw('The content-type header is missing.',); },); - describe('.process()', () => { - it('should be a function', () => { - expect(XMLValidator.process,).to.be.a('function',); - },); - it('should throw if there is no type', () => { - const response: Result = { - id: 'example', - validators: [], - duration: 234242, - response: { - headers: {}, - cookies: {}, - uri: '', - status: 0, - body: '{{]]', - }, - }; - expect(() => XMLValidator.process(response,),) - .to.throw('The content-type header is missing.',); - },); - it('should throw if the type is not xml', () => { - const response: Result = { - id: 'example', - validators: [], - duration: 234242, - response: { - headers: { - 'content-type': 'application/jason', - }, - cookies: {}, - uri: '', - status: 0, - body: '{{]]', + it('should throw if the type is not xml', () => { + const response: Result = { + id: 'example', + validators: [], + duration: 234242, + maxDuration: 0, + response: { + headers: { + 'content-type': 'application/jason', }, - }; - expect(() => XMLValidator.process(response,),) - .to.throw( - 'The content-type application/jason is not */xml.', - ); - },); - it('should throw if the body is not xml', () => { - const response: Result = { - id: 'example', - validators: [], - duration: 234242, - response: { - headers: { - 'content-type': 'text/xml', - }, - cookies: {}, - uri: '', - status: 0, - body: '<<>>', + cookies: {}, + uri: '', + status: 0, + body: '{{]]', + }, + }; + expect(() => post(response,),) + .to.throw( + 'The content-type application/jason is not */xml.', + ); + },); + it('should throw if the body is not xml', () => { + const response: Result = { + id: 'example', + validators: [], + duration: 234242, + maxDuration: 0, + response: { + headers: { + 'content-type': 'text/xml', }, - }; - expect(() => XMLValidator.process(response,),) - .to.throw( - 'The XML body is invalid.', - ); - },); - it('should not throw if the body is xml', () => { - const response: Result = { - id: 'example', - validators: [], - duration: 234242, - response: { - headers: { - 'content-type': 'text/xml', - }, - cookies: {}, - uri: '', - status: 0, - body: '', + cookies: {}, + uri: '', + status: 0, + body: '<<>>', + }, + }; + expect(() => post(response,),) + .to.throw( + 'The XML body is invalid.', + ); + },); + it('should not throw if the body is xml', () => { + const response: Result = { + id: 'example', + validators: [], + duration: 234242, + maxDuration: 0, + response: { + headers: { + 'content-type': 'text/xml', }, - }; - expect(() => XMLValidator.process(response,),).to.not.throw(); - },); + cookies: {}, + uri: '', + status: 0, + body: '', + }, + }; + expect(() => post(response,),).to.not.throw(); },); },);