Skip to content

Commit

Permalink
test: 同步单测
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudcome committed Feb 17, 2025
1 parent 48cbf8e commit 9fdb280
Show file tree
Hide file tree
Showing 12 changed files with 319 additions and 558 deletions.
309 changes: 89 additions & 220 deletions test/example-dest/2.0/pet-store.ts

Large diffs are not rendered by default.

297 changes: 88 additions & 209 deletions test/example-dest/3.0/pet-store.ts

Large diffs are not rendered by default.

47 changes: 14 additions & 33 deletions test/example-dest/3.1/pet-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,16 @@ import {zUpdatePetData,zUpdatePetResponse,zAddPetData,zAddPetResponse,zGetPetByI
* @param [config] request config
* @returns Successful operation
*/
export async function updatePet(data:Type.UpdatePetData,config?:AxiosRequestConfig): Promise<AxiosResponse<Type.UpdatePetResponse>> {
export async function updatePet(data:Type.UpdatePetData,config?:AxiosRequestConfig) {
zUpdatePetData.parse(data)
const transformResponse = config?.transformResponse;
config = {
...config,
transformResponse: [
...Array.isArray(transformResponse) ? transformResponse : (transformResponse ? [transformResponse] : []),
data => zUpdatePetResponse.parse(data),
],
};
return axios({
const resp = await axios<AxiosResponse<Type.UpdatePetResponse>>({
method: "PUT",
url: `/pet`,
data: data,
...config
})
});
zUpdatePetResponse.parse(resp["data"]);
return resp;
}
/**
* @description Add a new pet to the store
Expand All @@ -52,42 +46,29 @@ data: data,
* @param [config] request config
* @returns Successful operation
*/
export async function addPet(data:Type.AddPetData,config?:AxiosRequestConfig): Promise<AxiosResponse<Type.AddPetResponse>> {
export async function addPet(data:Type.AddPetData,config?:AxiosRequestConfig) {
zAddPetData.parse(data)
const transformResponse = config?.transformResponse;
config = {
...config,
transformResponse: [
...Array.isArray(transformResponse) ? transformResponse : (transformResponse ? [transformResponse] : []),
data => zAddPetResponse.parse(data),
],
};
return axios({
const resp = await axios<AxiosResponse<Type.AddPetResponse>>({
method: "POST",
url: `/pet`,
data: data,
...config
})
});
zAddPetResponse.parse(resp["data"]);
return resp;
}
/**
* @description Returns a pet when 0 < ID <= 10. ID > 10 or nonintegers will simulate API error conditions
* @summary Find pet by ID
* @param petId ID of pet that needs to be fetched
* @param [config] request config
*/
export async function getPetById(petId:Type.GetPetByIdPath,config?:AxiosRequestConfig): Promise<AxiosResponse<unknown>> {
export async function getPetById(petId:Type.GetPetByIdPath,config?:AxiosRequestConfig) {
zGetPetByIdPath.parse(petId)
const transformResponse = config?.transformResponse;
config = {
...config,
transformResponse: [
...Array.isArray(transformResponse) ? transformResponse : (transformResponse ? [transformResponse] : []),
data => data,
],
};
return axios({
const resp = await axios<AxiosResponse<unknown>>({
method: "GET",
url: `/pet/${petId}`,
...config
})
});
return resp;
}
35 changes: 20 additions & 15 deletions test/printer/arg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,16 @@ it('1*path + 1*query + 1*header', () => {
* @param [config] request config
* @returns pet name
*/
export async function getPet(petId:Type.GetPetPath,data:Type.GetPetData,xAuthKey?:Type.GetPetHeaders,categoryId?:Type.GetPetParams,config?:AxiosRequestConfig): Promise<AxiosResponse<Type.GetPetResponse>> {
return axios({
export async function getPet(petId:Type.GetPetPath,data:Type.GetPetData,xAuthKey?:Type.GetPetHeaders,categoryId?:Type.GetPetParams,config?:AxiosRequestConfig) {
const resp = await axios<AxiosResponse<Type.GetPetResponse>>({
method: "GET",
url: \`/pets/\${petId}\`,
data: data,
headers: {"x-auth-key": xAuthKey},
params: {"category-id": categoryId},
...config
})
});
return resp;
}"
`);
expect(result.type.code).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -174,15 +175,16 @@ it('n*path + 1*query + 1*header', () => {
* @param [categoryId] request params "category-id"
* @param [config] request config
*/
export async function getPet(path:Type.GetPetPath,data:Type.GetPetData,xAuthKey?:Type.GetPetHeaders,categoryId?:Type.GetPetParams,config?:AxiosRequestConfig): Promise<AxiosResponse<unknown>> {
return axios({
export async function getPet(path:Type.GetPetPath,data:Type.GetPetData,xAuthKey?:Type.GetPetHeaders,categoryId?:Type.GetPetParams,config?:AxiosRequestConfig) {
const resp = await axios<AxiosResponse<unknown>>({
method: "GET",
url: \`/zoo/\${path["zoo-id"]}/pets/\${path["pet-id"]}\`,
data: data,
headers: {"x-auth-key": xAuthKey},
params: {"category-id": categoryId},
...config
})
});
return resp;
}"
`);
expect(result.type.code).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -283,15 +285,16 @@ it('n*path + n*query + 1*header', () => {
* @param [params] request params
* @param [config] request config
*/
export async function getPet(path:Type.GetPetPath,data:Type.GetPetData,xAuthKey?:Type.GetPetHeaders,params?:Type.GetPetParams,config?:AxiosRequestConfig): Promise<AxiosResponse<unknown>> {
return axios({
export async function getPet(path:Type.GetPetPath,data:Type.GetPetData,xAuthKey?:Type.GetPetHeaders,params?:Type.GetPetParams,config?:AxiosRequestConfig) {
const resp = await axios<AxiosResponse<unknown>>({
method: "GET",
url: \`/zoo/\${path["zoo-id"]}/pets/\${path["pet-id"]}\`,
data: data,
headers: {"x-auth-key": xAuthKey},
params: params,
...config
})
});
return resp;
}"
`);
expect(result.type.code).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -405,15 +408,16 @@ it('n*path + n*query + n*header', () => {
* @param [params] request params
* @param [config] request config
*/
export async function getPet(path:Type.GetPetPath,data:Type.GetPetData,headers?:Type.GetPetHeaders,params?:Type.GetPetParams,config?:AxiosRequestConfig): Promise<AxiosResponse<unknown>> {
return axios({
export async function getPet(path:Type.GetPetPath,data:Type.GetPetData,headers?:Type.GetPetHeaders,params?:Type.GetPetParams,config?:AxiosRequestConfig) {
const resp = await axios<AxiosResponse<unknown>>({
method: "GET",
url: \`/zoo/\${path["zoo-id"]}/pets/\${path["pet-id"]}\`,
data: data,
headers: headers,
params: params,
...config
})
});
return resp;
}"
`);
expect(result.type.code).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -486,12 +490,13 @@ it('path name unique', () => {
* @param type request path "type"
* @param [config] request config
*/
export async function getPet(type:Type.GetPetPath,config?:AxiosRequestConfig): Promise<AxiosResponse<unknown>> {
return axios({
export async function getPet(type:Type.GetPetPath,config?:AxiosRequestConfig) {
const resp = await axios<AxiosResponse<unknown>>({
method: "GET",
url: \`/pets/\${type}\`,
...config
})
});
return resp;
}"
`);
expect(result.type.code).toMatchInlineSnapshot(`"export type GetPetPath = string;"`);
Expand Down
28 changes: 16 additions & 12 deletions test/printer/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ it('axios 模块导入名称默认', () => {
"/**
* @param [config] request config
*/
export async function get(config?:AxiosRequestConfig): Promise<AxiosResponse<unknown>> {
return axios({
export async function get(config?:AxiosRequestConfig) {
const resp = await axios<AxiosResponse<unknown>>({
method: "GET",
url: \`/\`,
...config
})
});
return resp;
}"
`);
expect(result.type.code).toMatchInlineSnapshot(`""`);
Expand Down Expand Up @@ -65,12 +66,13 @@ it('axios 模块导入名称指定', () => {
"/**
* @param [config] request config
*/
export async function get(config?:AxiosRequestConfig): Promise<AxiosResponse<unknown>> {
return axios({
export async function get(config?:AxiosRequestConfig) {
const resp = await axios<AxiosResponse<unknown>>({
method: "GET",
url: \`/\`,
...config
})
});
return resp;
}"
`);
expect(result.type.code).toMatchInlineSnapshot(`""`);
Expand Down Expand Up @@ -104,12 +106,13 @@ it('axios 默认导入名称为空', () => {
"/**
* @param [config] request config
*/
export async function get(config?:AxiosRequestConfig): Promise<AxiosResponse<unknown>> {
return axios({
export async function get(config?:AxiosRequestConfig) {
const resp = await axios<AxiosResponse<unknown>>({
method: "GET",
url: \`/\`,
...config
})
});
return resp;
}"
`);
expect(result.type.code).toMatchInlineSnapshot(`""`);
Expand Down Expand Up @@ -147,12 +150,13 @@ it('axios 模块和类型指定文件', () => {
"/**
* @param [config] request config
*/
export async function get(config?:AxiosRequestConfig): Promise<AxiosResponse<unknown>> {
return axios({
export async function get(config?:AxiosRequestConfig) {
const resp = await axios<AxiosResponse<unknown>>({
method: "GET",
url: \`/\`,
...config
})
});
return resp;
}"
`);
expect(result.type.code).toMatchInlineSnapshot(`""`);
Expand Down
Loading

0 comments on commit 9fdb280

Please sign in to comment.