Skip to content

Commit

Permalink
fix: content type detection now considers matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Mar 29, 2022
1 parent c77301a commit 069da08
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/v3/pact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,20 @@ 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
) => {
let contentType: string | MatchersV3.Matcher<string> = defaultContentType;
forEachObjIndexed((v, k) => {
if (`${k}`.toLowerCase() === 'content-type') {
contentType = v;
contentType = matcherValueOrString(v);
}
}, headers || {});

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 069da08

Please sign in to comment.