Skip to content

Commit

Permalink
feat(mocker): take http request into account
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Miaskowski committed Oct 15, 2018
1 parent 08c4d7f commit 85f1bc0
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ export default class HttpOperationConfigNegotiator implements IOperationConfigNe

public negotiate(opts: IMockerOpts<IHttpOperation, IHttpRequest, IHttpOperationConfig>): Promise<IHttpOperationConfigNegotiationResult> {
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) {
Expand All @@ -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');
}
}

0 comments on commit 85f1bc0

Please sign in to comment.