Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/__tests__/fixtures/request-parameters-header/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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": {
Expand All @@ -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": {
Expand All @@ -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": {
Expand All @@ -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": {
Expand All @@ -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": {
Expand Down
23 changes: 13 additions & 10 deletions src/__tests__/fixtures/request-parameters-header/pact.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"interactions": [
{
"description": "should pass when header matches the spec",
"providerState": "",
"request": {
"method": "GET",
"path": "/path",
Expand All @@ -24,7 +23,6 @@
},
{
"description": "should pass for 4xx responses",
"providerState": "",
"request": {
"method": "GET",
"path": "/path",
Expand All @@ -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",
Expand Down Expand Up @@ -90,7 +100,6 @@
},
{
"description": "should warn when header is not defined in spec",
"providerState": "",
"request": {
"method": "GET",
"path": "/path",
Expand All @@ -108,7 +117,6 @@
},
{
"description": "should error when required header is missing",
"providerState": "",
"request": {
"method": "GET",
"path": "/path",
Expand All @@ -123,7 +131,6 @@
},
{
"description": "should error when required header does not match the spec",
"providerState": "",
"request": {
"method": "GET",
"path": "/path",
Expand All @@ -140,7 +147,6 @@
},
{
"description": "should error when optional header does not match the spec",
"providerState": "",
"request": {
"method": "GET",
"path": "/path",
Expand All @@ -158,7 +164,6 @@
},
{
"description": "should error when header does not match the array spec",
"providerState": "",
"request": {
"method": "GET",
"path": "/path",
Expand All @@ -176,7 +181,6 @@
},
{
"description": "should warn when spec is missing accept and content-type",
"providerState": "",
"request": {
"method": "GET",
"path": "/no-response",
Expand All @@ -193,7 +197,6 @@
},
{
"description": "should error about incorrect request content type",
"providerState": "",
"request": {
"method": "POST",
"path": "/submit",
Expand Down
16 changes: 8 additions & 8 deletions src/__tests__/fixtures/request-parameters-header/results.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand All @@ -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": {
Expand All @@ -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": {
Expand All @@ -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": {
Expand All @@ -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": {
Expand All @@ -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": {
Expand All @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion src/compare/requestHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function* compareReqHeader(
if (
requestAccept &&
availableResponseContentType.length &&
!findMatchingType(requestAccept, availableResponseContentType)
!findMatchingType(requestAccept, allAvailableResponseContentTypes)
) {
yield {
code: "request.accept.incompatible",
Expand Down