forked from PaloAltoNetworks/docusaurus-openapi-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenapi.test.ts
More file actions
58 lines (50 loc) · 2.04 KB
/
Copy pathopenapi.test.ts
File metadata and controls
58 lines (50 loc) · 2.04 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
/* ============================================================================
* Copyright (c) Palo Alto Networks
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* ========================================================================== */
import path from "path";
// eslint-disable-next-line import/no-extraneous-dependencies
import { posixPath } from "@docusaurus/utils";
import { readOpenapiFiles } from ".";
// npx jest packages/docusaurus-plugin-openapi/src/openapi/openapi.test.ts --watch
describe("openapi", () => {
describe("readOpenapiFiles", () => {
it("readOpenapiFiles", async () => {
const results = await readOpenapiFiles(
posixPath(path.join(__dirname, "__fixtures__/examples"))
);
const categoryMeta = results.find((x) =>
x.source.endsWith("_category_.json")
);
expect(categoryMeta).toBeFalsy();
// console.log(results);
const yaml = results.find((x) => x.source.endsWith("openapi.yaml"));
expect(yaml).toBeTruthy();
expect(yaml?.sourceDirName).toBe(".");
expect(yaml?.data.tags).toBeDefined();
expect(yaml?.data["x-tagGroups"]).toBeDefined();
expect(
yaml?.data.components?.schemas?.HelloString["x-tags"]
).toBeDefined();
});
});
describe("doc card markdown", () => {
it("preserves markdown and html in tag descriptions", async () => {
const results = await readOpenapiFiles(
posixPath(path.join(__dirname, "__fixtures__/docCards"))
);
const yaml = results.find((x) => x.source.endsWith("openapi.yaml"));
expect(yaml).toBeTruthy();
const tag = yaml?.data.tags?.find((t) => t.name === "docCards");
expect(tag?.description).toBe(
"This tag shows **markdown** and <b>HTML</b> in the doc card."
);
const op = yaml?.data.paths?.["/docs"]?.get;
expect(op?.description?.trim()).toBe(
"Returns documentation with **markdown** and <b>HTML</b> in descriptions."
);
});
});
});