Skip to content

Commit f176378

Browse files
committed
Revert "feat: add mockDetails to non-http warnings (#428)"
This reverts commit ef22f35.
1 parent b73846c commit f176378

File tree

6 files changed

+22
-134
lines changed

6 files changed

+22
-134
lines changed
Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,17 @@
11
[
22
{
33
"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.",
4+
"message": "Non-HTTP Interaction is not supported, OPC can only compare HTTP interactions.",
115
"type": "warning"
126
},
137
{
148
"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.",
9+
"message": "Non-HTTP Interaction is not supported, OPC can only compare HTTP interactions.",
2210
"type": "warning"
2311
},
2412
{
2513
"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.",
14+
"message": "Non-HTTP Interaction is not supported, OPC can only compare HTTP interactions.",
3315
"type": "warning"
3416
}
3517
]
Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,7 @@
11
[
22
{
33
"code": "interaction.type.unsupported",
4-
"mockDetails": {
5-
"interactionDescription": "a product created event",
6-
"interactionState": "[none]",
7-
"location": "[root].messages[0]",
8-
"value": {
9-
"_id": "e7918bd59533f7fe75b86192865f89898df6cd3f",
10-
"contents": {
11-
"event": "CREATED",
12-
"id": "5cc989d0-d800-434c-b4bb-b1268499e850",
13-
"name": "product name",
14-
"type": "product series",
15-
"version": "v1"
16-
},
17-
"description": "a product created event",
18-
"matchingRules": {
19-
"body": {
20-
"$.event": {
21-
"combine": "AND",
22-
"matchers": [
23-
{
24-
"match": "regex",
25-
"regex": "^(CREATED|UPDATED|DELETED)$"
26-
}
27-
]
28-
},
29-
"$.id": {
30-
"combine": "AND",
31-
"matchers": [
32-
{
33-
"match": "type"
34-
}
35-
]
36-
},
37-
"$.name": {
38-
"combine": "AND",
39-
"matchers": [
40-
{
41-
"match": "type"
42-
}
43-
]
44-
},
45-
"$.type": {
46-
"combine": "AND",
47-
"matchers": [
48-
{
49-
"match": "type"
50-
}
51-
]
52-
},
53-
"$.version": {
54-
"combine": "AND",
55-
"matchers": [
56-
{
57-
"match": "regex",
58-
"regex": "v[a-zA-z0-9]+"
59-
}
60-
]
61-
}
62-
}
63-
},
64-
"metaData": {
65-
"contentType": "application/json",
66-
"kafka_topic": "products"
67-
}
68-
}
69-
},
70-
"message": "Non-HTTP messages cannot be verified against an HTTP-only OpenAPI Document.",
4+
"message": "Non-HTTP Interaction is not supported, OPC can only compare HTTP interactions.",
715
"type": "warning"
726
}
737
]

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
[
22
{
33
"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.",
4+
"message": "Non-HTTP Interaction is not supported, OPC can only compare HTTP interactions.",
105
"type": "warning"
116
},
127
{

src/compare/index.ts

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,15 @@ export class Comparator {
6565

6666
const parsedInteractions = parsedPact.interactions || [];
6767

68+
const UNSUPPORTED_INTERACTION_WARNING = {
69+
code: "interaction.type.unsupported",
70+
message: `Non-HTTP Interaction is not supported, OPC can only compare HTTP interactions.`,
71+
type: "warning",
72+
} as Result;
73+
6874
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-
};
75+
if (interaction._skip) {
76+
yield UNSUPPORTED_INTERACTION_WARNING;
8077
continue;
8178
}
8279

@@ -185,18 +182,8 @@ export class Comparator {
185182
}
186183

187184
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-
};
185+
for (const [_message] of parsedPact.messages.entries()) {
186+
yield UNSUPPORTED_INTERACTION_WARNING;
200187
}
201188
}
202189
}

src/documents/pact.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ describe("#parser", () => {
6969
expect(pact.interactions!.length).toBe(4);
7070
expect(pact.interactions![0].description).toBe("no-type");
7171
expect(pact.interactions![1].description).toBe("http");
72-
expect(pact.interactions![2]._nonHTTP).toBe(true);
73-
expect(pact.interactions![3]._nonHTTP).toBe(true);
72+
expect(pact.interactions![2]._skip).toBe(true);
73+
expect(pact.interactions![3]._skip).toBe(true);
7474
});
7575

7676
it("if messages are present it parses it to be dealt with later", () => {

src/documents/pact.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Ajv, { ErrorObject } from "ajv";
44
// a full schema can be found at https://github.com/pactflow/pact-schemas
55
// but we don't use that here, because we try to be permissive with input
66
export const Interaction = Type.Object({
7-
_nonHTTP: Type.Optional(Type.Boolean()),
7+
_skip: Type.Optional(Type.Boolean()),
88
type: Type.Optional(Type.String()),
99
description: Type.Optional(Type.String()),
1010
providerState: Type.Optional(Type.String()),
@@ -43,13 +43,6 @@ export const Interaction = Type.Object({
4343

4444
export type Interaction = Static<typeof Interaction>;
4545

46-
export const Message = Type.Object({
47-
description: Type.Optional(Type.String()),
48-
providerState: Type.Optional(Type.String()),
49-
});
50-
51-
export type Message = Static<typeof Message>;
52-
5346
export const Pact = Type.Object({
5447
metadata: Type.Optional(
5548
Type.Object({
@@ -67,7 +60,7 @@ export const Pact = Type.Object({
6760
}),
6861
),
6962
interactions: Type.Optional(Type.Array(Interaction)),
70-
messages: Type.Optional(Type.Array(Message)),
63+
messages: Type.Optional(Type.Array(Type.Unknown())),
7164
});
7265

7366
export type Pact = Static<typeof Pact>;
@@ -158,11 +151,6 @@ const interactionV4 = (i: Interaction): Interaction => ({
158151
},
159152
});
160153

161-
const interactionNonHTTP = (i: Interaction): Interaction => ({
162-
...i,
163-
_nonHTTP: true,
164-
});
165-
166154
const ajv = new Ajv();
167155
const validate = ajv.compile(Pact);
168156

@@ -190,7 +178,9 @@ export const parse = (pact: Pact): Pact => {
190178
return {
191179
metadata,
192180
interactions: interactions?.map((i: Interaction) =>
193-
supportedInteractions(i) ? interactionParser(i) : interactionNonHTTP(i),
181+
supportedInteractions(i)
182+
? interactionParser(i)
183+
: ({ _skip: true } as Interaction),
194184
),
195185
messages,
196186
};

0 commit comments

Comments
 (0)