From 85f1bc0cb2c9048fa6b24caa911ba5f87f3a9e40 Mon Sep 17 00:00:00 2001 From: Chris Miaskowski Date: Mon, 15 Oct 2018 16:13:58 +0200 Subject: [PATCH] feat(mocker): take http request into account --- .../HttpOperationConfigNegotiator.ts | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/http/src/mocker/negotiator/HttpOperationConfigNegotiator.ts b/packages/http/src/mocker/negotiator/HttpOperationConfigNegotiator.ts index 10c77f59d..ff19823d8 100644 --- a/packages/http/src/mocker/negotiator/HttpOperationConfigNegotiator.ts +++ b/packages/http/src/mocker/negotiator/HttpOperationConfigNegotiator.ts @@ -20,8 +20,14 @@ export default class HttpOperationConfigNegotiator implements IOperationConfigNe public negotiate(opts: IMockerOpts): Promise { try { - const { resource, input, config: desiredConfig } = opts; + const { resource, input, config } = opts; const httpRequest = opts.input.data; + const desiredConfig = Object.assign({ + dynamic: this.getDynamic(httpRequest), + code: this.getStatusCode(httpRequest), + mediaType: this.getContentType(httpRequest), + exampleKey: this.getExampleKey(httpRequest) + }, config); let httpOperationConfig: IHttpOperationConfig; if (input.validations.input.length > 0) { @@ -39,4 +45,21 @@ export default class HttpOperationConfigNegotiator implements IOperationConfigNe }); } } + + private getContentType(httpRequest: IHttpRequest): string | undefined { + return (httpRequest.query && httpRequest.query['_contentType']) || + (httpRequest.headers && httpRequest.headers['Content-Type']); + } + + private getExampleKey(httpRequest: IHttpRequest): string | undefined { + return (httpRequest.query && httpRequest.query['_exampleKey']); + } + + private getStatusCode(httpRequest: IHttpRequest): string | undefined { + return (httpRequest.query && httpRequest.query['_code']); + } + + private getDynamic(httpRequest: IHttpRequest): boolean | undefined { + return (httpRequest.query && httpRequest.query['_dynamic'] === 'true'); + } }