From 069da08b22c748cc0dd929ea28e2cfac564b9a8f Mon Sep 17 00:00:00 2001 From: Matt Fellows Date: Tue, 29 Mar 2022 16:18:20 +1100 Subject: [PATCH] fix: content type detection now considers matchers --- src/v3/pact.ts | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/v3/pact.ts b/src/v3/pact.ts index 932dc9a03..44877c5da 100644 --- a/src/v3/pact.ts +++ b/src/v3/pact.ts @@ -22,6 +22,12 @@ export enum SpecificationVersion { SPECIFICATION_VERSION_V3 = 4, } +const matcherValueOrString = (obj: unknown): string => { + if (typeof obj === 'string') return obj; + + return JSON.stringify(obj); +}; + const contentTypeFromHeaders = ( headers: TemplateHeaders | undefined, defaultContentType: string @@ -29,7 +35,7 @@ const contentTypeFromHeaders = ( let contentType: string | MatchersV3.Matcher = defaultContentType; forEachObjIndexed((v, k) => { if (`${k}`.toLowerCase() === 'content-type') { - contentType = v; + contentType = matcherValueOrString(v); } }, headers || {}); @@ -70,18 +76,6 @@ export interface PactV3Options { logLevel?: 'trace' | 'debug' | 'info' | 'warn' | 'error'; } -// const logInvalidOperation = (op: string) => { -// throw new Error( -// `unable to call operation ${op}, this is probably a bug in Pact JS` -// ); -// }; - -const matcherValueOrString = (obj: unknown): string => { - if (typeof obj === 'string') return obj; - - return JSON.stringify(obj); -}; - const readBinaryData = (file: string): Buffer => { try { const body = fs.readFileSync(file);