-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.test.ts
45 lines (43 loc) · 1.25 KB
/
main.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { expect, test } from "@jest/globals";
import { MustHaveOperationDescription } from "../main";
import { TestHelpers } from "@useoptic/rulesets-base";
import { OpenAPIV3 } from "@useoptic/openapi-utilities";
test("MustHaveOperationDescription", async () => {
const beforeApiSpec: OpenAPIV3.Document = {
...TestHelpers.createEmptySpec(),
};
const afterApiSpec: OpenAPIV3.Document = {
...TestHelpers.createEmptySpec(),
paths: {
'/api/users': {
get: {
description: "get the list of users",
responses: {
'200': {
description: 'successfully fetched users',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
user_id: {
type: 'string'
}
}
}
}
}
}
}
}
}
}
};
const ruleResults = await TestHelpers.runRulesWithInputs(
[MustHaveOperationDescription],
beforeApiSpec,
afterApiSpec
);
expect(ruleResults.length > 0).toBe(true);
expect(ruleResults.every((result) => result.passed)).toBe(true);
});