Skip to content

Commit 94fc70f

Browse files
authored
feat: remove warnings about unsupported interactions (#433)
* Revert "feat: add mockDetails to non-http warnings (#428)" This reverts commit ef22f35. * Revert "chore: added warning for message comparison and added handling when interactions array in null or undefined (#422)" This reverts commit 1d35775. * chore: add changeset
1 parent b73846c commit 94fc70f

File tree

10 files changed

+33
-317
lines changed

10 files changed

+33
-317
lines changed

.changeset/six-towns-film.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@pactflow/openapi-pact-comparator": minor
3+
---
4+
5+
Remove warnings about unsupported interaction types
Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1 @@
1-
[
2-
{
3-
"code": "interaction.type.unsupported",
4-
"mockDetails": {
5-
"interactionDescription": "should be ignored",
6-
"interactionState": "[none]",
7-
"location": "[root].interactions[0].type",
8-
"value": "Asynchronous/Messages"
9-
},
10-
"message": "Non-HTTP messages cannot be verified against an HTTP-only OpenAPI Document.",
11-
"type": "warning"
12-
},
13-
{
14-
"code": "interaction.type.unsupported",
15-
"mockDetails": {
16-
"interactionDescription": "should be ignored",
17-
"interactionState": "[none]",
18-
"location": "[root].interactions[1].type",
19-
"value": "Synchronous/Messages"
20-
},
21-
"message": "Non-HTTP messages cannot be verified against an HTTP-only OpenAPI Document.",
22-
"type": "warning"
23-
},
24-
{
25-
"code": "interaction.type.unsupported",
26-
"mockDetails": {
27-
"interactionDescription": "should be ignored",
28-
"interactionState": "[none]",
29-
"location": "[root].interactions[2].type",
30-
"value": "not-a-real-type"
31-
},
32-
"message": "Non-HTTP messages cannot be verified against an HTTP-only OpenAPI Document.",
33-
"type": "warning"
34-
}
35-
]
1+
[]

src/__tests__/fixtures/pact-non-http-interactions-v3/oas.yaml

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/__tests__/fixtures/pact-non-http-interactions-v3/pact.json

Lines changed: 0 additions & 79 deletions
This file was deleted.

src/__tests__/fixtures/pact-non-http-interactions-v3/results.json

Lines changed: 0 additions & 73 deletions
This file was deleted.

src/__tests__/fixtures/pact-non-http-interactions/results.json

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
11
[
2-
{
3-
"code": "interaction.type.unsupported",
4-
"mockDetails": {
5-
"interactionState": "[none]",
6-
"location": "[root].interactions[0].type",
7-
"value": "Async/Messages"
8-
},
9-
"message": "Non-HTTP messages cannot be verified against an HTTP-only OpenAPI Document.",
10-
"type": "warning"
11-
},
122
{
133
"code": "request.body.incompatible",
144
"message": "Request body is incompatible with the request body schema in the spec file: must be object",

src/compare/index.ts

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,9 @@ export class Comparator {
6363

6464
const parsedPact = parsePact(pact);
6565

66-
const parsedInteractions = parsedPact.interactions || [];
67-
68-
for (const [index, interaction] of parsedInteractions.entries()) {
69-
if (interaction._nonHTTP) {
70-
yield {
71-
code: "interaction.type.unsupported",
72-
mockDetails: {
73-
...baseMockDetails(interaction),
74-
location: `[root].interactions[${index}].type`,
75-
value: interaction.type,
76-
},
77-
message: `Non-HTTP messages cannot be verified against an HTTP-only OpenAPI Document.`,
78-
type: "warning",
79-
};
66+
for (const [index, interaction] of parsedPact.interactions.entries()) {
67+
if (interaction._skip) {
68+
// non http/synchronous have been zero-ed out
8069
continue;
8170
}
8271

@@ -183,21 +172,5 @@ export class Comparator {
183172
this.#config,
184173
);
185174
}
186-
187-
if (parsedPact.messages) {
188-
for (const [index, message] of parsedPact.messages.entries()) {
189-
yield {
190-
code: "interaction.type.unsupported",
191-
mockDetails: {
192-
interactionDescription: message.description,
193-
interactionState: message.providerState || "[none]",
194-
location: `[root].messages[${index}]`,
195-
value: message,
196-
},
197-
message: `Non-HTTP messages cannot be verified against an HTTP-only OpenAPI Document.`,
198-
type: "warning",
199-
};
200-
}
201-
}
202175
}
203176
}

src/documents/pact.test.ts

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ describe("#parser", () => {
2525
],
2626
} as Pact;
2727

28-
const { request, response } = parse(json).interactions![0];
28+
const { request, response } = parse(json).interactions[0];
2929
expect(request.headers!["Content-Type"]).toEqual("text/json");
3030
expect(request.headers!["Accept"]).toEqual(
3131
"text/plain,application/json,text/json",
3232
);
3333
expect(response.headers!["Content-Type"]).toEqual("application/json");
3434
});
3535

36-
it("marks out non-HTTP interactions from v4 pact as skip `true`", () => {
36+
it("filters out non-HTTP interactions", () => {
3737
const request = {
3838
method: "GET",
3939
path: "/path",
@@ -66,35 +66,11 @@ describe("#parser", () => {
6666
};
6767

6868
const pact = parse(json as Pact);
69-
expect(pact.interactions!.length).toBe(4);
70-
expect(pact.interactions![0].description).toBe("no-type");
71-
expect(pact.interactions![1].description).toBe("http");
72-
expect(pact.interactions![2]._nonHTTP).toBe(true);
73-
expect(pact.interactions![3]._nonHTTP).toBe(true);
74-
});
75-
76-
it("if messages are present it parses it to be dealt with later", () => {
77-
const request = {
78-
method: "GET",
79-
path: "/path",
80-
};
81-
const response = {
82-
status: 200,
83-
};
84-
const json = {
85-
interactions: [{ description: "no-type", request, response }],
86-
messages: [
87-
{
88-
content: "some-message-content",
89-
},
90-
],
91-
};
92-
93-
const pact = parse(json as Pact);
94-
expect(pact.interactions!.length).toBe(1);
95-
expect(pact.interactions![0].description).toBe("no-type");
96-
expect(pact.messages!.length).toBe(1);
97-
expect(pact.messages![0]).toEqual({ content: "some-message-content" });
69+
expect(pact.interactions.length).toBe(4);
70+
expect(pact.interactions[0].description).toBe("no-type");
71+
expect(pact.interactions[1].description).toBe("http");
72+
expect(pact.interactions[2]._skip).toBe(true);
73+
expect(pact.interactions[3]._skip).toBe(true);
9874
});
9975

10076
it("should parse V4 body types", () => {
@@ -163,13 +139,13 @@ describe("#parser", () => {
163139

164140
const pact = parse(json as Pact);
165141

166-
expect(pact.interactions![0].response.body).toEqual({ hello: "world" });
167-
expect(pact.interactions![1].response.body).toEqual({ hello: "world" });
168-
expect(pact.interactions![2].response.body).toEqual("hello world");
169-
expect(pact.interactions![3].request.body).toEqual({ hello: "world" });
170-
expect(pact.interactions![4].request.body).toEqual({ hello: "world" });
171-
expect(pact.interactions![5].request.body).toEqual("hello world");
172-
expect(pact.interactions![6].request.body).toEqual("{ not: json }");
173-
expect(pact.interactions![7].request.body).toEqual("abcdef");
142+
expect(pact.interactions[0].response.body).toEqual({ hello: "world" });
143+
expect(pact.interactions[1].response.body).toEqual({ hello: "world" });
144+
expect(pact.interactions[2].response.body).toEqual("hello world");
145+
expect(pact.interactions[3].request.body).toEqual({ hello: "world" });
146+
expect(pact.interactions[4].request.body).toEqual({ hello: "world" });
147+
expect(pact.interactions[5].request.body).toEqual("hello world");
148+
expect(pact.interactions[6].request.body).toEqual("{ not: json }");
149+
expect(pact.interactions[7].request.body).toEqual("abcdef");
174150
});
175151
});

0 commit comments

Comments
 (0)