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
8 changes: 4 additions & 4 deletions src/__tests__/fixtures/request-parameters-path/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"mockDetails": {
"interactionDescription": "should error when path does not match integer spec",
"interactionState": "[none]",
"location": "[root].interactions[3].request.path",
"location": "[root].interactions[4].request.path",
"value": "/integer/abc"
},
"specDetails": {
Expand Down Expand Up @@ -90,7 +90,7 @@
"mockDetails": {
"interactionDescription": "should error when path does not match boolean spec",
"interactionState": "[none]",
"location": "[root].interactions[4].request.path",
"location": "[root].interactions[5].request.path",
"value": "/boolean/abc"
},
"specDetails": {
Expand Down Expand Up @@ -175,7 +175,7 @@
"mockDetails": {
"interactionDescription": "should error when path and method does not exist in spec",
"interactionState": "[none]",
"location": "[root].interactions[7].request.path",
"location": "[root].interactions[8].request.path",
"value": "/does-not-exist"
},
"specDetails": {
Expand Down Expand Up @@ -260,7 +260,7 @@
"mockDetails": {
"interactionDescription": "should error when path does not exist in spec",
"interactionState": "[none]",
"location": "[root].interactions[8].request.path",
"location": "[root].interactions[9].request.path",
"value": "/integer/1"
},
"specDetails": {
Expand Down
10 changes: 10 additions & 0 deletions src/__tests__/fixtures/request-parameters-path/pact.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@
"status": 200
}
},
{
"description": "should pass when path does not start with /",
"request": {
"method": "GET",
"path": "integer/1"
},
"response": {
"status": 200
}
},
{
"description": "should error when path does not match integer spec",
"request": {
Expand Down
12 changes: 6 additions & 6 deletions src/__tests__/fixtures/request-parameters-path/results.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"mockDetails": {
"interactionDescription": "should error when path does not match integer spec",
"interactionState": "[none]",
"location": "[root].interactions[3].request.path",
"location": "[root].interactions[4].request.path",
"value": "/integer/abc"
},
"specDetails": {
Expand Down Expand Up @@ -38,7 +38,7 @@
"mockDetails": {
"interactionDescription": "should error when path does not match boolean spec",
"interactionState": "[none]",
"location": "[root].interactions[4].request.path",
"location": "[root].interactions[5].request.path",
"value": "/boolean/abc"
},
"specDetails": {
Expand Down Expand Up @@ -71,7 +71,7 @@
"mockDetails": {
"interactionDescription": "should error when path does not match object spec",
"interactionState": "[none]",
"location": "[root].interactions[5].request.path",
"location": "[root].interactions[6].request.path",
"value": "/exploded-object/string=abc,number=abc"
},
"specDetails": {
Expand Down Expand Up @@ -114,7 +114,7 @@
"mockDetails": {
"interactionDescription": "should error when path does not match object spec",
"interactionState": "[none]",
"location": "[root].interactions[6].request.path",
"location": "[root].interactions[7].request.path",
"value": "/exploded-object/string=abc,number=abc"
},
"specDetails": {
Expand Down Expand Up @@ -157,7 +157,7 @@
"mockDetails": {
"interactionDescription": "should error when path and method does not exist in spec",
"interactionState": "[none]",
"location": "[root].interactions[7].request.path",
"location": "[root].interactions[8].request.path",
"value": "/does-not-exist"
},
"specDetails": {
Expand All @@ -173,7 +173,7 @@
"mockDetails": {
"interactionDescription": "should error when path does not exist in spec",
"interactionState": "[none]",
"location": "[root].interactions[8].request.path",
"location": "[root].interactions[9].request.path",
"value": "/integer/1"
},
"specDetails": {
Expand Down
3 changes: 2 additions & 1 deletion src/compare/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class Comparator {

for (const [index, interaction] of parsedPact.interactions.entries()) {
const { method, path, query } = interaction.request;
const pathWithLeadingSlash = path.startsWith("/") ? path : `/${path}`;
// in pact, query is either a string or an object of only one level deep
const stringQuery =
typeof query === "string"
Expand All @@ -75,7 +76,7 @@ export class Comparator {
.substring(1);
const route = this.#router.find(
method.toUpperCase() as HTTPMethod,
[path, stringQuery].filter(Boolean).join("?"),
[pathWithLeadingSlash, stringQuery].filter(Boolean).join("?"),
);

if (!route) {
Expand Down