diff --git a/src/__tests__/fixtures/request-parameters-header/baseline.json b/src/__tests__/fixtures/request-parameters-header/baseline.json index 2ad5e26..0db6033 100644 --- a/src/__tests__/fixtures/request-parameters-header/baseline.json +++ b/src/__tests__/fixtures/request-parameters-header/baseline.json @@ -5,7 +5,7 @@ "mockDetails": { "interactionDescription": "should warn when header is not defined in spec", "interactionState": "[none]", - "location": "[root].interactions[3].request.headers.x-surprise", + "location": "[root].interactions[4].request.headers.x-surprise", "value": "unexpected header" }, "specDetails": { @@ -83,10 +83,9 @@ "mockDetails": { "interactionDescription": "should error when required header is missing", "interactionState": "[none]", - "location": "[root].interactions[4]", + "location": "[root].interactions[5]", "value": { "description": "should error when required header is missing", - "providerState": "", "request": { "method": "GET", "path": "/path", @@ -121,7 +120,7 @@ "mockDetails": { "interactionDescription": "should error when required header does not match the spec", "interactionState": "[none]", - "location": "[root].interactions[5].request.headers.x-required-number", + "location": "[root].interactions[6].request.headers.x-required-number", "value": "abc" }, "specDetails": { @@ -145,7 +144,7 @@ "mockDetails": { "interactionDescription": "should error when optional header does not match the spec", "interactionState": "[none]", - "location": "[root].interactions[6].request.headers.x-optional-number", + "location": "[root].interactions[7].request.headers.x-optional-number", "value": "abc" }, "specDetails": { @@ -169,7 +168,7 @@ "mockDetails": { "interactionDescription": "should warn when spec is missing accept and content-type", "interactionState": "[none]", - "location": "[root].interactions[8].request.headers.accept", + "location": "[root].interactions[9].request.headers.accept", "value": "application/json" }, "specDetails": { @@ -193,7 +192,7 @@ "mockDetails": { "interactionDescription": "should warn when spec is missing accept and content-type", "interactionState": "[none]", - "location": "[root].interactions[8].response.headers.Content-Type", + "location": "[root].interactions[9].response.headers.Content-Type", "value": "application/json" }, "specDetails": { @@ -217,7 +216,7 @@ "mockDetails": { "interactionDescription": "should error about incorrect request content type", "interactionState": "[none]", - "location": "[root].interactions[9].request.headers.content-type", + "location": "[root].interactions[10].request.headers.content-type", "value": "unknown" }, "specDetails": { diff --git a/src/__tests__/fixtures/request-parameters-header/pact.json b/src/__tests__/fixtures/request-parameters-header/pact.json index 01cef0c..4a20d93 100644 --- a/src/__tests__/fixtures/request-parameters-header/pact.json +++ b/src/__tests__/fixtures/request-parameters-header/pact.json @@ -4,7 +4,6 @@ "interactions": [ { "description": "should pass when header matches the spec", - "providerState": "", "request": { "method": "GET", "path": "/path", @@ -24,7 +23,6 @@ }, { "description": "should pass for 4xx responses", - "providerState": "", "request": { "method": "GET", "path": "/path", @@ -39,9 +37,21 @@ } } }, + { + "description": "should pass when requested content-type is supported, even if not for current response status", + "request": { + "method": "GET", + "path": "/path", + "headers": { + "accept": "application/json" + } + }, + "response": { + "status": 400 + } + }, { "description": "should pass for standard headers not defined in spec", - "providerState": "", "request": { "method": "GET", "path": "/path", @@ -90,7 +100,6 @@ }, { "description": "should warn when header is not defined in spec", - "providerState": "", "request": { "method": "GET", "path": "/path", @@ -108,7 +117,6 @@ }, { "description": "should error when required header is missing", - "providerState": "", "request": { "method": "GET", "path": "/path", @@ -123,7 +131,6 @@ }, { "description": "should error when required header does not match the spec", - "providerState": "", "request": { "method": "GET", "path": "/path", @@ -140,7 +147,6 @@ }, { "description": "should error when optional header does not match the spec", - "providerState": "", "request": { "method": "GET", "path": "/path", @@ -158,7 +164,6 @@ }, { "description": "should error when header does not match the array spec", - "providerState": "", "request": { "method": "GET", "path": "/path", @@ -176,7 +181,6 @@ }, { "description": "should warn when spec is missing accept and content-type", - "providerState": "", "request": { "method": "GET", "path": "/no-response", @@ -193,7 +197,6 @@ }, { "description": "should error about incorrect request content type", - "providerState": "", "request": { "method": "POST", "path": "/submit", diff --git a/src/__tests__/fixtures/request-parameters-header/results.json b/src/__tests__/fixtures/request-parameters-header/results.json index 14dacf4..6248ed4 100644 --- a/src/__tests__/fixtures/request-parameters-header/results.json +++ b/src/__tests__/fixtures/request-parameters-header/results.json @@ -5,7 +5,7 @@ "mockDetails": { "interactionDescription": "should warn when header is not defined in spec", "interactionState": "[none]", - "location": "[root].interactions[3].request.headers.x-surprise", + "location": "[root].interactions[4].request.headers.x-surprise", "value": "unexpected header" }, "specDetails": { @@ -83,7 +83,7 @@ "mockDetails": { "interactionDescription": "should error when required header is missing", "interactionState": "[none]", - "location": "[root].interactions[4].request.headers.x-required-number", + "location": "[root].interactions[5].request.headers.x-required-number", "value": null }, "specDetails": { @@ -107,7 +107,7 @@ "mockDetails": { "interactionDescription": "should error when required header does not match the spec", "interactionState": "[none]", - "location": "[root].interactions[5].request.headers.x-required-number", + "location": "[root].interactions[6].request.headers.x-required-number", "value": "abc" }, "specDetails": { @@ -124,7 +124,7 @@ "mockDetails": { "interactionDescription": "should error when optional header does not match the spec", "interactionState": "[none]", - "location": "[root].interactions[6].request.headers.x-optional-number", + "location": "[root].interactions[7].request.headers.x-optional-number", "value": "abc" }, "specDetails": { @@ -141,7 +141,7 @@ "mockDetails": { "interactionDescription": "should error when header does not match the array spec", "interactionState": "[none]", - "location": "[root].interactions[7].request.headers.x-optional-array.2", + "location": "[root].interactions[8].request.headers.x-optional-array.2", "value": "abc" }, "specDetails": { @@ -158,7 +158,7 @@ "mockDetails": { "interactionDescription": "should warn when spec is missing accept and content-type", "interactionState": "[none]", - "location": "[root].interactions[8].request.headers.accept", + "location": "[root].interactions[9].request.headers.accept", "value": "application/json" }, "specDetails": { @@ -182,7 +182,7 @@ "mockDetails": { "interactionDescription": "should warn when spec is missing accept and content-type", "interactionState": "[none]", - "location": "[root].interactions[8].response.headers.content-type", + "location": "[root].interactions[9].response.headers.content-type", "value": "application/json" }, "specDetails": { @@ -206,7 +206,7 @@ "mockDetails": { "interactionDescription": "should error about incorrect request content type", "interactionState": "[none]", - "location": "[root].interactions[9].request.headers.content-type", + "location": "[root].interactions[10].request.headers.content-type", "value": "unknown" }, "specDetails": { diff --git a/src/compare/requestHeader.ts b/src/compare/requestHeader.ts index 42c789a..fd0d32d 100644 --- a/src/compare/requestHeader.ts +++ b/src/compare/requestHeader.ts @@ -83,7 +83,7 @@ export function* compareReqHeader( if ( requestAccept && availableResponseContentType.length && - !findMatchingType(requestAccept, availableResponseContentType) + !findMatchingType(requestAccept, allAvailableResponseContentTypes) ) { yield { code: "request.accept.incompatible",