Skip to content

Commit 030b9cc

Browse files
authored
fix: ignore other errors when unable to match path/method (#45)
1 parent 2a15c49 commit 030b9cc

File tree

4 files changed

+126
-1
lines changed

4 files changed

+126
-1
lines changed

src/__tests__/fixtures/request-parameters-path/baseline.json

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,5 +338,90 @@
338338
}
339339
},
340340
"type": "error"
341+
},
342+
{
343+
"code": "request.path-or-method.unknown",
344+
"message": "Path or method not defined in spec file: POST /integer/1",
345+
"mockDetails": {
346+
"interactionDescription": "should not raise subsequent errors when request.path-or-method.unknown",
347+
"interactionState": "[none]",
348+
"location": "[root].interactions[10].request.path",
349+
"value": "/integer/1"
350+
},
351+
"specDetails": {
352+
"location": "[root].paths",
353+
"pathMethod": null,
354+
"pathName": null,
355+
"value": {
356+
"/integer/{id}": {
357+
"get": {
358+
"parameters": [
359+
{
360+
"in": "path",
361+
"name": "id",
362+
"required": true,
363+
"schema": {
364+
"type": "integer"
365+
}
366+
}
367+
],
368+
"responses": {
369+
"200": {
370+
"description": "description"
371+
}
372+
}
373+
}
374+
},
375+
"/boolean/{id}": {
376+
"get": {
377+
"parameters": [
378+
{
379+
"in": "path",
380+
"name": "id",
381+
"required": true,
382+
"schema": {
383+
"type": "boolean"
384+
}
385+
}
386+
],
387+
"responses": {
388+
"200": {
389+
"description": "description"
390+
}
391+
}
392+
}
393+
},
394+
"/exploded-object/{id}": {
395+
"get": {
396+
"parameters": [
397+
{
398+
"in": "path",
399+
"name": "id",
400+
"required": true,
401+
"schema": {
402+
"type": "object",
403+
"properties": {
404+
"string": {
405+
"type": "string"
406+
},
407+
"number": {
408+
"type": "number"
409+
}
410+
}
411+
},
412+
"style": "simple",
413+
"explode": true
414+
}
415+
],
416+
"responses": {
417+
"200": {
418+
"description": "description"
419+
}
420+
}
421+
}
422+
}
423+
}
424+
},
425+
"type": "error"
341426
}
342427
]

src/__tests__/fixtures/request-parameters-path/pact.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,22 @@
101101
"response": {
102102
"status": 200
103103
}
104+
},
105+
{
106+
"description": "should not raise subsequent errors when request.path-or-method.unknown",
107+
"request": {
108+
"method": "POST",
109+
"path": "/integer/1",
110+
"headers": {
111+
"additional": "ignored error"
112+
}
113+
},
114+
"response": {
115+
"status": 200,
116+
"headers": {
117+
"accept": "should not be here!"
118+
}
119+
}
104120
}
105121
]
106122
}

src/__tests__/fixtures/request-parameters-path/results.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,5 +182,21 @@
182182
"pathName": null
183183
},
184184
"type": "error"
185+
},
186+
{
187+
"code": "request.path-or-method.unknown",
188+
"message": "Path or method not defined in spec file: POST /integer/1",
189+
"mockDetails": {
190+
"interactionDescription": "should not raise subsequent errors when request.path-or-method.unknown",
191+
"interactionState": "[none]",
192+
"location": "[root].interactions[10].request.path",
193+
"value": "/integer/1"
194+
},
195+
"specDetails": {
196+
"location": "[root].paths",
197+
"pathMethod": null,
198+
"pathName": null
199+
},
200+
"type": "error"
185201
}
186202
]

src/compare/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,15 @@ export class Comparator {
100100
continue;
101101
}
102102

103-
yield* compareReqPath(this.#ajvCoerce, route, interaction, index);
103+
const results = Array.from(
104+
compareReqPath(this.#ajvCoerce, route, interaction, index),
105+
);
106+
107+
if (results.length) {
108+
yield* results;
109+
continue;
110+
}
111+
104112
yield* compareReqHeader(this.#ajvCoerce, route, interaction, index);
105113
yield* compareReqQuery(this.#ajvCoerce, route, interaction, index);
106114
yield* compareReqBody(this.#ajvNocoerce, route, interaction, index);

0 commit comments

Comments
 (0)