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
52 changes: 48 additions & 4 deletions src/__tests__/fixtures/response-header/baseline.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,55 @@
[
{
"code": "response.header.undefined",
"message": "Standard http response header is not defined in the spec file: content-length",
"mockDetails": {
"interactionDescription": "should pass with 204 status, ignoring content-length and content-type",
"interactionState": "[none]",
"location": "[root].interactions[2].response.headers.content-length",
"value": "0"
},
"specDetails": {
"location": "[root].paths./delete.delete.responses.204",
"pathMethod": "delete",
"pathName": "/delete",
"value": {
"description": "OK",
"content": {}
}
},
"type": "warning"
},
{
"code": "response.content-type.unknown",
"message": "Response Content-Type header is defined but the spec does not specify any mime-types to produce",
"mockDetails": {
"interactionDescription": "should pass with 204 status, ignoring content-length and content-type",
"interactionState": "[none]",
"location": "[root].interactions[2].response.headers.content-type",
"value": "text/plain"
},
"specDetails": {
"location": "[root].paths./delete.delete",
"pathMethod": "delete",
"pathName": "/delete",
"value": {
"responses": {
"204": {
"description": "OK",
"content": {}
}
}
}
},
"type": "warning"
},
{
"code": "response.header.undefined",
"message": "Standard http response header is not defined in the spec file: age",
"mockDetails": {
"interactionDescription": "should warn about missing standard response headers",
"interactionState": "[none]",
"location": "[root].interactions[2].response.headers.age",
"location": "[root].interactions[3].response.headers.age",
"value": "60"
},
"specDetails": {
Expand Down Expand Up @@ -41,7 +85,7 @@
"mockDetails": {
"interactionDescription": "should error on incompatible response headers",
"interactionState": "[none]",
"location": "[root].interactions[3].response.headers.specified",
"location": "[root].interactions[4].response.headers.specified",
"value": "abc"
},
"specDetails": {
Expand All @@ -62,7 +106,7 @@
"mockDetails": {
"interactionDescription": "should error on unspecified response headers",
"interactionState": "[none]",
"location": "[root].interactions[4].response.headers.unspecified",
"location": "[root].interactions[5].response.headers.unspecified",
"value": "foo"
},
"specDetails": {
Expand Down Expand Up @@ -98,7 +142,7 @@
"mockDetails": {
"interactionDescription": "should error on unknown response content type",
"interactionState": "[none]",
"location": "[root].interactions[5].response.headers.Content-Type",
"location": "[root].interactions[6].response.headers.Content-Type",
"value": "text/html"
},
"specDetails": {
Expand Down
6 changes: 6 additions & 0 deletions src/__tests__/fixtures/response-header/oas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ paths:
content:
application/json:
schema: {}
/delete:
delete:
responses:
"204":
description: OK
content: {}
20 changes: 14 additions & 6 deletions src/__tests__/fixtures/response-header/pact.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"interactions": [
{
"description": "should pass with successful headers",
"providerState": "",
"request": {
"method": "GET",
"path": "/path"
Expand All @@ -18,7 +17,6 @@
},
{
"description": "should pass about specified standard http response header",
"providerState": "",
"request": {
"method": "GET",
"path": "/path"
Expand All @@ -31,9 +29,22 @@
}
}
},
{
"description": "should pass with 204 status, ignoring content-length and content-type",
"request": {
"method": "DELETE",
"path": "/delete"
},
"response": {
"status": 204,
"headers": {
"content-length": "0",
"content-type": "text/plain"
}
}
},
{
"description": "should warn about missing standard response headers",
"providerState": "",
"request": {
"method": "GET",
"path": "/path"
Expand All @@ -48,7 +59,6 @@
},
{
"description": "should error on incompatible response headers",
"providerState": "",
"request": {
"method": "GET",
"path": "/path"
Expand All @@ -63,7 +73,6 @@
},
{
"description": "should error on unspecified response headers",
"providerState": "",
"request": {
"method": "GET",
"path": "/path"
Expand All @@ -78,7 +87,6 @@
},
{
"description": "should error on unknown response content type",
"providerState": "",
"request": {
"method": "GET",
"path": "/different-response-types"
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/fixtures/response-header/results.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"mockDetails": {
"interactionDescription": "should warn about missing standard response headers",
"interactionState": "[none]",
"location": "[root].interactions[2].response.headers.age"
"location": "[root].interactions[3].response.headers.age"
},
"specDetails": {
"location": "[root].paths./path.get",
Expand Down Expand Up @@ -44,7 +44,7 @@
"mockDetails": {
"interactionDescription": "should error on incompatible response headers",
"interactionState": "[none]",
"location": "[root].interactions[3].response.headers.specified",
"location": "[root].interactions[4].response.headers.specified",
"value": "abc"
},
"specDetails": {
Expand All @@ -61,7 +61,7 @@
"mockDetails": {
"interactionDescription": "should error on unspecified response headers",
"interactionState": "[none]",
"location": "[root].interactions[4].response.headers.unspecified",
"location": "[root].interactions[5].response.headers.unspecified",
"value": "foo"
},
"specDetails": {
Expand Down Expand Up @@ -89,7 +89,7 @@
"mockDetails": {
"interactionDescription": "should error on unknown response content type",
"interactionState": "[none]",
"location": "[root].interactions[5].response.headers.content-type",
"location": "[root].interactions[6].response.headers.content-type",
"value": "text/html"
},
"specDetails": {
Expand Down
7 changes: 7 additions & 0 deletions src/compare/responseHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ export function* compareResHeader(
interaction.response.headers as Record<string, string>,
);

// no content response
// -------------------
if (interaction.response.status === 204) {
responseHeaders.delete("content-length");
responseHeaders.delete("content-type");
}

// response content-type
// ---------------------
const responseContentType =
Expand Down