Skip to content

Commit c825eeb

Browse files
committed
test: 更新单元测试
1 parent 235e4d6 commit c825eeb

File tree

5 files changed

+60
-29
lines changed

5 files changed

+60
-29
lines changed

test/generators/Logger.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ test('Logger', async () => {
1212
logger.pipeProcessEvent({
1313
index: 5,
1414
count: 99,
15+
name: 'test',
1516
stage: 'generated',
1617
filePath: '/a/b/c/d/e/f',
1718
options: {
1819
cwd: '/a/b/c',
1920
dest: '',
20-
name: 'test',
2121
document: {
2222
info: {
2323
title: 'test',

test/generators/commands.test.ts

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,16 @@ test('resolveConfig', async () => {
2525
expect(() => resolveConfig(cwd)).toThrow('配置文件未找到');
2626

2727
const file = path.join(cwd, configFileNameOrder[0]);
28-
fs.writeFileSync(file, '', 'utf8');
29-
expect(() => resolveConfig(cwd)).toThrow('#/openAPIs - Required');
3028

3129
fs.writeFileSync(
3230
file,
3331
`module.exports = {
34-
openAPIs: []
35-
};`,
36-
'utf8',
37-
);
38-
expect(() => resolveConfig(cwd)).toThrow('#/openAPIs - Array must contain at least 1 element(s)');
3932
40-
fs.writeFileSync(
41-
file,
42-
`module.exports = {
43-
openAPIs: [{name: "test"}]
44-
};`,
45-
'utf8',
46-
);
47-
expect(() => resolveConfig(cwd)).toThrow('#/openAPIs/0/document - Invalid input');
33+
modules: {
34+
"test": {"document": "test.openapi.json"}
35+
}
4836
49-
fs.writeFileSync(
50-
file,
51-
`module.exports = {
52-
openAPIs: [{name: "test", "document": "test.openapi.json"}]
53-
};`,
37+
};`,
5438
'utf8',
5539
);
5640
expect(() => resolveConfig(cwd)).not.toThrow();
@@ -76,8 +60,12 @@ test('run', async () => {
7660
fs.writeFileSync(
7761
file,
7862
`module.exports = {
79-
openAPIs: [{name: "test", "document": "test.openapi.json"}]
80-
};`,
63+
64+
modules: {
65+
"test": "test.openapi.json"
66+
}
67+
68+
};`,
8169
'utf8',
8270
);
8371

test/generators/generator.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ test('Generator', async () => {
77
const [tempDir, clean] = createTempDirname();
88
const generator = new Generator({
99
cwd: tempDir,
10-
openAPIs: [
11-
{
12-
name: 'petStore3',
10+
modules: {
11+
petStore3: {
1312
document: path.join(__dirname, '../example-json/3.0/pet-store.json'),
1413
},
15-
],
14+
},
1615
});
1716

1817
const fn1 = vi.fn();

test/printer/path.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,46 @@ test('1路径 + 1请求', () => {
3333
`);
3434
});
3535

36+
test('1路径 + 1请求 * module', () => {
37+
const printer = new Printer({
38+
info: {
39+
title: 'api',
40+
version: 'v1',
41+
},
42+
openapi: '3.0.0',
43+
paths: {
44+
'/api/abc': {
45+
get: {},
46+
},
47+
},
48+
});
49+
50+
expect(
51+
printer.print({
52+
module: 'TTT',
53+
hideImports: true,
54+
}),
55+
).toMatchInlineSnapshot(`
56+
"/**
57+
* @module TTT
58+
* @title api
59+
* @version v1
60+
*/
61+
62+
/**
63+
* @module TTT
64+
* @param [config] request config
65+
*/
66+
export async function getApiAbc(config?:AxiosRequestConfig): AxiosPromise<unknown> {
67+
return axios({
68+
method: "get",
69+
url:resolveURL(BASE_URL,"/api/abc"),
70+
...config
71+
});
72+
}"
73+
`);
74+
});
75+
3676
test('1路径 + 2请求', () => {
3777
const printer = new Printer({
3878
info: {

test/printer/schemas.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,11 @@ test('printComponents AllOf primitive', () => {
173173
hideImports: true,
174174
}),
175175
).toMatchInlineSnapshot(`
176-
"export type Order = (
176+
"export type User = ({
177+
username:string;
178+
}) | null;
179+
180+
export type Order = (
177181
/**
178182
* @description test1
179183
* @deprecated
@@ -185,7 +189,7 @@ test('printComponents AllOf primitive', () => {
185189
/**
186190
* @description test2
187191
*/
188-
unknown
192+
User
189193
);"
190194
`);
191195
});

0 commit comments

Comments
 (0)