Skip to content

Commit 9fdb280

Browse files
committed
test: 同步单测
1 parent 48cbf8e commit 9fdb280

File tree

12 files changed

+319
-558
lines changed

12 files changed

+319
-558
lines changed

test/example-dest/2.0/pet-store.ts

Lines changed: 89 additions & 220 deletions
Large diffs are not rendered by default.

test/example-dest/3.0/pet-store.ts

Lines changed: 88 additions & 209 deletions
Large diffs are not rendered by default.

test/example-dest/3.1/pet-store.ts

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,16 @@ import {zUpdatePetData,zUpdatePetResponse,zAddPetData,zAddPetResponse,zGetPetByI
2727
* @param [config] request config
2828
* @returns Successful operation
2929
*/
30-
export async function updatePet(data:Type.UpdatePetData,config?:AxiosRequestConfig): Promise<AxiosResponse<Type.UpdatePetResponse>> {
30+
export async function updatePet(data:Type.UpdatePetData,config?:AxiosRequestConfig) {
3131
zUpdatePetData.parse(data)
32-
const transformResponse = config?.transformResponse;
33-
config = {
34-
...config,
35-
transformResponse: [
36-
...Array.isArray(transformResponse) ? transformResponse : (transformResponse ? [transformResponse] : []),
37-
data => zUpdatePetResponse.parse(data),
38-
],
39-
};
40-
return axios({
32+
const resp = await axios<AxiosResponse<Type.UpdatePetResponse>>({
4133
method: "PUT",
4234
url: `/pet`,
4335
data: data,
4436
...config
45-
})
37+
});
38+
zUpdatePetResponse.parse(resp["data"]);
39+
return resp;
4640
}
4741
/**
4842
* @description Add a new pet to the store
@@ -52,42 +46,29 @@ data: data,
5246
* @param [config] request config
5347
* @returns Successful operation
5448
*/
55-
export async function addPet(data:Type.AddPetData,config?:AxiosRequestConfig): Promise<AxiosResponse<Type.AddPetResponse>> {
49+
export async function addPet(data:Type.AddPetData,config?:AxiosRequestConfig) {
5650
zAddPetData.parse(data)
57-
const transformResponse = config?.transformResponse;
58-
config = {
59-
...config,
60-
transformResponse: [
61-
...Array.isArray(transformResponse) ? transformResponse : (transformResponse ? [transformResponse] : []),
62-
data => zAddPetResponse.parse(data),
63-
],
64-
};
65-
return axios({
51+
const resp = await axios<AxiosResponse<Type.AddPetResponse>>({
6652
method: "POST",
6753
url: `/pet`,
6854
data: data,
6955
...config
70-
})
56+
});
57+
zAddPetResponse.parse(resp["data"]);
58+
return resp;
7159
}
7260
/**
7361
* @description Returns a pet when 0 < ID <= 10. ID > 10 or nonintegers will simulate API error conditions
7462
* @summary Find pet by ID
7563
* @param petId ID of pet that needs to be fetched
7664
* @param [config] request config
7765
*/
78-
export async function getPetById(petId:Type.GetPetByIdPath,config?:AxiosRequestConfig): Promise<AxiosResponse<unknown>> {
66+
export async function getPetById(petId:Type.GetPetByIdPath,config?:AxiosRequestConfig) {
7967
zGetPetByIdPath.parse(petId)
80-
const transformResponse = config?.transformResponse;
81-
config = {
82-
...config,
83-
transformResponse: [
84-
...Array.isArray(transformResponse) ? transformResponse : (transformResponse ? [transformResponse] : []),
85-
data => data,
86-
],
87-
};
88-
return axios({
68+
const resp = await axios<AxiosResponse<unknown>>({
8969
method: "GET",
9070
url: `/pet/${petId}`,
9171
...config
92-
})
72+
});
73+
return resp;
9374
}

test/printer/arg.test.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,16 @@ it('1*path + 1*query + 1*header', () => {
7676
* @param [config] request config
7777
* @returns pet name
7878
*/
79-
export async function getPet(petId:Type.GetPetPath,data:Type.GetPetData,xAuthKey?:Type.GetPetHeaders,categoryId?:Type.GetPetParams,config?:AxiosRequestConfig): Promise<AxiosResponse<Type.GetPetResponse>> {
80-
return axios({
79+
export async function getPet(petId:Type.GetPetPath,data:Type.GetPetData,xAuthKey?:Type.GetPetHeaders,categoryId?:Type.GetPetParams,config?:AxiosRequestConfig) {
80+
const resp = await axios<AxiosResponse<Type.GetPetResponse>>({
8181
method: "GET",
8282
url: \`/pets/\${petId}\`,
8383
data: data,
8484
headers: {"x-auth-key": xAuthKey},
8585
params: {"category-id": categoryId},
8686
...config
87-
})
87+
});
88+
return resp;
8889
}"
8990
`);
9091
expect(result.type.code).toMatchInlineSnapshot(`
@@ -174,15 +175,16 @@ it('n*path + 1*query + 1*header', () => {
174175
* @param [categoryId] request params "category-id"
175176
* @param [config] request config
176177
*/
177-
export async function getPet(path:Type.GetPetPath,data:Type.GetPetData,xAuthKey?:Type.GetPetHeaders,categoryId?:Type.GetPetParams,config?:AxiosRequestConfig): Promise<AxiosResponse<unknown>> {
178-
return axios({
178+
export async function getPet(path:Type.GetPetPath,data:Type.GetPetData,xAuthKey?:Type.GetPetHeaders,categoryId?:Type.GetPetParams,config?:AxiosRequestConfig) {
179+
const resp = await axios<AxiosResponse<unknown>>({
179180
method: "GET",
180181
url: \`/zoo/\${path["zoo-id"]}/pets/\${path["pet-id"]}\`,
181182
data: data,
182183
headers: {"x-auth-key": xAuthKey},
183184
params: {"category-id": categoryId},
184185
...config
185-
})
186+
});
187+
return resp;
186188
}"
187189
`);
188190
expect(result.type.code).toMatchInlineSnapshot(`
@@ -283,15 +285,16 @@ it('n*path + n*query + 1*header', () => {
283285
* @param [params] request params
284286
* @param [config] request config
285287
*/
286-
export async function getPet(path:Type.GetPetPath,data:Type.GetPetData,xAuthKey?:Type.GetPetHeaders,params?:Type.GetPetParams,config?:AxiosRequestConfig): Promise<AxiosResponse<unknown>> {
287-
return axios({
288+
export async function getPet(path:Type.GetPetPath,data:Type.GetPetData,xAuthKey?:Type.GetPetHeaders,params?:Type.GetPetParams,config?:AxiosRequestConfig) {
289+
const resp = await axios<AxiosResponse<unknown>>({
288290
method: "GET",
289291
url: \`/zoo/\${path["zoo-id"]}/pets/\${path["pet-id"]}\`,
290292
data: data,
291293
headers: {"x-auth-key": xAuthKey},
292294
params: params,
293295
...config
294-
})
296+
});
297+
return resp;
295298
}"
296299
`);
297300
expect(result.type.code).toMatchInlineSnapshot(`
@@ -405,15 +408,16 @@ it('n*path + n*query + n*header', () => {
405408
* @param [params] request params
406409
* @param [config] request config
407410
*/
408-
export async function getPet(path:Type.GetPetPath,data:Type.GetPetData,headers?:Type.GetPetHeaders,params?:Type.GetPetParams,config?:AxiosRequestConfig): Promise<AxiosResponse<unknown>> {
409-
return axios({
411+
export async function getPet(path:Type.GetPetPath,data:Type.GetPetData,headers?:Type.GetPetHeaders,params?:Type.GetPetParams,config?:AxiosRequestConfig) {
412+
const resp = await axios<AxiosResponse<unknown>>({
410413
method: "GET",
411414
url: \`/zoo/\${path["zoo-id"]}/pets/\${path["pet-id"]}\`,
412415
data: data,
413416
headers: headers,
414417
params: params,
415418
...config
416-
})
419+
});
420+
return resp;
417421
}"
418422
`);
419423
expect(result.type.code).toMatchInlineSnapshot(`
@@ -486,12 +490,13 @@ it('path name unique', () => {
486490
* @param type request path "type"
487491
* @param [config] request config
488492
*/
489-
export async function getPet(type:Type.GetPetPath,config?:AxiosRequestConfig): Promise<AxiosResponse<unknown>> {
490-
return axios({
493+
export async function getPet(type:Type.GetPetPath,config?:AxiosRequestConfig) {
494+
const resp = await axios<AxiosResponse<unknown>>({
491495
method: "GET",
492496
url: \`/pets/\${type}\`,
493497
...config
494-
})
498+
});
499+
return resp;
495500
}"
496501
`);
497502
expect(result.type.code).toMatchInlineSnapshot(`"export type GetPetPath = string;"`);

test/printer/options.test.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ it('axios 模块导入名称默认', () => {
2626
"/**
2727
* @param [config] request config
2828
*/
29-
export async function get(config?:AxiosRequestConfig): Promise<AxiosResponse<unknown>> {
30-
return axios({
29+
export async function get(config?:AxiosRequestConfig) {
30+
const resp = await axios<AxiosResponse<unknown>>({
3131
method: "GET",
3232
url: \`/\`,
3333
...config
34-
})
34+
});
35+
return resp;
3536
}"
3637
`);
3738
expect(result.type.code).toMatchInlineSnapshot(`""`);
@@ -65,12 +66,13 @@ it('axios 模块导入名称指定', () => {
6566
"/**
6667
* @param [config] request config
6768
*/
68-
export async function get(config?:AxiosRequestConfig): Promise<AxiosResponse<unknown>> {
69-
return axios({
69+
export async function get(config?:AxiosRequestConfig) {
70+
const resp = await axios<AxiosResponse<unknown>>({
7071
method: "GET",
7172
url: \`/\`,
7273
...config
73-
})
74+
});
75+
return resp;
7476
}"
7577
`);
7678
expect(result.type.code).toMatchInlineSnapshot(`""`);
@@ -104,12 +106,13 @@ it('axios 默认导入名称为空', () => {
104106
"/**
105107
* @param [config] request config
106108
*/
107-
export async function get(config?:AxiosRequestConfig): Promise<AxiosResponse<unknown>> {
108-
return axios({
109+
export async function get(config?:AxiosRequestConfig) {
110+
const resp = await axios<AxiosResponse<unknown>>({
109111
method: "GET",
110112
url: \`/\`,
111113
...config
112-
})
114+
});
115+
return resp;
113116
}"
114117
`);
115118
expect(result.type.code).toMatchInlineSnapshot(`""`);
@@ -147,12 +150,13 @@ it('axios 模块和类型指定文件', () => {
147150
"/**
148151
* @param [config] request config
149152
*/
150-
export async function get(config?:AxiosRequestConfig): Promise<AxiosResponse<unknown>> {
151-
return axios({
153+
export async function get(config?:AxiosRequestConfig) {
154+
const resp = await axios<AxiosResponse<unknown>>({
152155
method: "GET",
153156
url: \`/\`,
154157
...config
155-
})
158+
});
159+
return resp;
156160
}"
157161
`);
158162
expect(result.type.code).toMatchInlineSnapshot(`""`);

0 commit comments

Comments
 (0)