Skip to content

Commit 9711e42

Browse files
committed
Revert "chore: added warning for message comparison and added handling when interactions array in null or undefined (#422)"
This reverts commit 1d35775.
1 parent f176378 commit 9711e42

File tree

9 files changed

+23
-200
lines changed

9 files changed

+23
-200
lines changed
Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1 @@
1-
[
2-
{
3-
"code": "interaction.type.unsupported",
4-
"message": "Non-HTTP Interaction is not supported, OPC can only compare HTTP interactions.",
5-
"type": "warning"
6-
},
7-
{
8-
"code": "interaction.type.unsupported",
9-
"message": "Non-HTTP Interaction is not supported, OPC can only compare HTTP interactions.",
10-
"type": "warning"
11-
},
12-
{
13-
"code": "interaction.type.unsupported",
14-
"message": "Non-HTTP Interaction is not supported, OPC can only compare HTTP interactions.",
15-
"type": "warning"
16-
}
17-
]
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 & 7 deletions
This file was deleted.

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
[
2-
{
3-
"code": "interaction.type.unsupported",
4-
"message": "Non-HTTP Interaction is not supported, OPC can only compare HTTP interactions.",
5-
"type": "warning"
6-
},
72
{
83
"code": "request.body.incompatible",
94
"message": "Request body is incompatible with the request body schema in the spec file: must be object",

src/compare/index.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,9 @@ export class Comparator {
6363

6464
const parsedPact = parsePact(pact);
6565

66-
const parsedInteractions = parsedPact.interactions || [];
67-
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-
74-
for (const [index, interaction] of parsedInteractions.entries()) {
66+
for (const [index, interaction] of parsedPact.interactions.entries()) {
7567
if (interaction._skip) {
76-
yield UNSUPPORTED_INTERACTION_WARNING;
68+
// non http/synchronous have been zero-ed out
7769
continue;
7870
}
7971

@@ -180,11 +172,5 @@ export class Comparator {
180172
this.#config,
181173
);
182174
}
183-
184-
if (parsedPact.messages) {
185-
for (const [_message] of parsedPact.messages.entries()) {
186-
yield UNSUPPORTED_INTERACTION_WARNING;
187-
}
188-
}
189175
}
190176
}

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]._skip).toBe(true);
73-
expect(pact.interactions![3]._skip).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
});

src/documents/pact.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ export const Pact = Type.Object({
5959
),
6060
}),
6161
),
62-
interactions: Type.Optional(Type.Array(Interaction)),
63-
messages: Type.Optional(Type.Array(Type.Unknown())),
62+
interactions: Type.Array(Interaction),
6463
});
6564

6665
export type Pact = Static<typeof Pact>;
@@ -155,12 +154,11 @@ const ajv = new Ajv();
155154
const validate = ajv.compile(Pact);
156155

157156
export const parse = (pact: Pact): Pact => {
158-
const { metadata, interactions, messages } = pact;
157+
const { metadata, interactions } = pact;
159158

160159
const isValid = validate({
161160
metadata,
162-
interactions: interactions?.filter(supportedInteractions),
163-
messages,
161+
interactions: interactions.filter(supportedInteractions),
164162
});
165163
if (!isValid) {
166164
throw new ParserError(validate.errors!);
@@ -177,12 +175,11 @@ export const parse = (pact: Pact): Pact => {
177175

178176
return {
179177
metadata,
180-
interactions: interactions?.map((i: Interaction) =>
178+
interactions: interactions.map((i: Interaction) =>
181179
supportedInteractions(i)
182180
? interactionParser(i)
183181
: ({ _skip: true } as Interaction),
184182
),
185-
messages,
186183
};
187184
};
188185

src/results/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ type WarningCode =
2626
| "request.query.unknown"
2727
| "response.content-type.unknown"
2828
| "response.header.undefined"
29-
| "response.status.default"
30-
| "interaction.type.unsupported";
29+
| "response.status.default";
3130

3231
export interface Result {
3332
code: ErrorCode | WarningCode;

0 commit comments

Comments
 (0)