Skip to content

Commit 9b2e112

Browse files
committed
fix test paths
1 parent 50fa150 commit 9b2e112

File tree

2 files changed

+254
-12
lines changed

2 files changed

+254
-12
lines changed

packages/rtk-query-codegen-openapi/test/__snapshots__/cli.test.ts.snap

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,223 @@ export type User = {
219219
};
220220
221221
`;
222+
223+
exports[`CLI options testing paths are relative to configfile, not to cwd 1`] = `
224+
import { api } from '../fixtures/emptyApi';
225+
const injectedRtkApi = api.injectEndpoints({
226+
endpoints: (build) => ({
227+
updatePet: build.mutation<UpdatePetApiResponse, UpdatePetApiArg>({
228+
query: (queryArg) => ({ url: \`/pet\`, method: 'PUT', body: queryArg.pet }),
229+
}),
230+
addPet: build.mutation<AddPetApiResponse, AddPetApiArg>({
231+
query: (queryArg) => ({ url: \`/pet\`, method: 'POST', body: queryArg.pet }),
232+
}),
233+
findPetsByStatus: build.query<FindPetsByStatusApiResponse, FindPetsByStatusApiArg>({
234+
query: (queryArg) => ({ url: \`/pet/findByStatus\`, params: { status: queryArg.status } }),
235+
}),
236+
findPetsByTags: build.query<FindPetsByTagsApiResponse, FindPetsByTagsApiArg>({
237+
query: (queryArg) => ({ url: \`/pet/findByTags\`, params: { tags: queryArg.tags } }),
238+
}),
239+
getPetById: build.query<GetPetByIdApiResponse, GetPetByIdApiArg>({
240+
query: (queryArg) => ({ url: \`/pet/\${queryArg.petId}\` }),
241+
}),
242+
updatePetWithForm: build.mutation<UpdatePetWithFormApiResponse, UpdatePetWithFormApiArg>({
243+
query: (queryArg) => ({
244+
url: \`/pet/\${queryArg.petId}\`,
245+
method: 'POST',
246+
params: { name: queryArg.name, status: queryArg.status },
247+
}),
248+
}),
249+
deletePet: build.mutation<DeletePetApiResponse, DeletePetApiArg>({
250+
query: (queryArg) => ({ url: \`/pet/\${queryArg.petId}\`, method: 'DELETE', headers: { api_key: queryArg.apiKey } }),
251+
}),
252+
uploadFile: build.mutation<UploadFileApiResponse, UploadFileApiArg>({
253+
query: (queryArg) => ({
254+
url: \`/pet/\${queryArg.petId}/uploadImage\`,
255+
method: 'POST',
256+
body: queryArg.body,
257+
params: { additionalMetadata: queryArg.additionalMetadata },
258+
}),
259+
}),
260+
getInventory: build.query<GetInventoryApiResponse, GetInventoryApiArg>({
261+
query: () => ({ url: \`/store/inventory\` }),
262+
}),
263+
placeOrder: build.mutation<PlaceOrderApiResponse, PlaceOrderApiArg>({
264+
query: (queryArg) => ({ url: \`/store/order\`, method: 'POST', body: queryArg.order }),
265+
}),
266+
getOrderById: build.query<GetOrderByIdApiResponse, GetOrderByIdApiArg>({
267+
query: (queryArg) => ({ url: \`/store/order/\${queryArg.orderId}\` }),
268+
}),
269+
deleteOrder: build.mutation<DeleteOrderApiResponse, DeleteOrderApiArg>({
270+
query: (queryArg) => ({ url: \`/store/order/\${queryArg.orderId}\`, method: 'DELETE' }),
271+
}),
272+
createUser: build.mutation<CreateUserApiResponse, CreateUserApiArg>({
273+
query: (queryArg) => ({ url: \`/user\`, method: 'POST', body: queryArg.user }),
274+
}),
275+
createUsersWithListInput: build.mutation<CreateUsersWithListInputApiResponse, CreateUsersWithListInputApiArg>({
276+
query: (queryArg) => ({ url: \`/user/createWithList\`, method: 'POST', body: queryArg.body }),
277+
}),
278+
loginUser: build.query<LoginUserApiResponse, LoginUserApiArg>({
279+
query: (queryArg) => ({
280+
url: \`/user/login\`,
281+
params: { username: queryArg.username, password: queryArg.password },
282+
}),
283+
}),
284+
logoutUser: build.query<LogoutUserApiResponse, LogoutUserApiArg>({
285+
query: () => ({ url: \`/user/logout\` }),
286+
}),
287+
getUserByName: build.query<GetUserByNameApiResponse, GetUserByNameApiArg>({
288+
query: (queryArg) => ({ url: \`/user/\${queryArg.username}\` }),
289+
}),
290+
updateUser: build.mutation<UpdateUserApiResponse, UpdateUserApiArg>({
291+
query: (queryArg) => ({ url: \`/user/\${queryArg.username}\`, method: 'PUT', body: queryArg.user }),
292+
}),
293+
deleteUser: build.mutation<DeleteUserApiResponse, DeleteUserApiArg>({
294+
query: (queryArg) => ({ url: \`/user/\${queryArg.username}\`, method: 'DELETE' }),
295+
}),
296+
}),
297+
overrideExisting: false,
298+
});
299+
export { injectedRtkApi as enhancedApi };
300+
export type UpdatePetApiResponse = /** status 200 Successful operation */ Pet;
301+
export type UpdatePetApiArg = {
302+
/** Update an existent pet in the store */
303+
pet: Pet;
304+
};
305+
export type AddPetApiResponse = /** status 200 Successful operation */ Pet;
306+
export type AddPetApiArg = {
307+
/** Create a new pet in the store */
308+
pet: Pet;
309+
};
310+
export type FindPetsByStatusApiResponse = /** status 200 successful operation */ Pet[];
311+
export type FindPetsByStatusApiArg = {
312+
/** Status values that need to be considered for filter */
313+
status?: 'available' | 'pending' | 'sold';
314+
};
315+
export type FindPetsByTagsApiResponse = /** status 200 successful operation */ Pet[];
316+
export type FindPetsByTagsApiArg = {
317+
/** Tags to filter by */
318+
tags?: string[];
319+
};
320+
export type GetPetByIdApiResponse = /** status 200 successful operation */ Pet;
321+
export type GetPetByIdApiArg = {
322+
/** ID of pet to return */
323+
petId: number;
324+
};
325+
export type UpdatePetWithFormApiResponse = unknown;
326+
export type UpdatePetWithFormApiArg = {
327+
/** ID of pet that needs to be updated */
328+
petId: number;
329+
/** Name of pet that needs to be updated */
330+
name?: string;
331+
/** Status of pet that needs to be updated */
332+
status?: string;
333+
};
334+
export type DeletePetApiResponse = unknown;
335+
export type DeletePetApiArg = {
336+
apiKey?: string;
337+
/** Pet id to delete */
338+
petId: number;
339+
};
340+
export type UploadFileApiResponse = /** status 200 successful operation */ ApiResponse;
341+
export type UploadFileApiArg = {
342+
/** ID of pet to update */
343+
petId: number;
344+
/** Additional Metadata */
345+
additionalMetadata?: string;
346+
body: Blob;
347+
};
348+
export type GetInventoryApiResponse = /** status 200 successful operation */ {
349+
[key: string]: number;
350+
};
351+
export type GetInventoryApiArg = void;
352+
export type PlaceOrderApiResponse = /** status 200 successful operation */ Order;
353+
export type PlaceOrderApiArg = {
354+
order: Order;
355+
};
356+
export type GetOrderByIdApiResponse = /** status 200 successful operation */ Order;
357+
export type GetOrderByIdApiArg = {
358+
/** ID of order that needs to be fetched */
359+
orderId: number;
360+
};
361+
export type DeleteOrderApiResponse = unknown;
362+
export type DeleteOrderApiArg = {
363+
/** ID of the order that needs to be deleted */
364+
orderId: number;
365+
};
366+
export type CreateUserApiResponse = unknown;
367+
export type CreateUserApiArg = {
368+
/** Created user object */
369+
user: User;
370+
};
371+
export type CreateUsersWithListInputApiResponse = /** status 200 Successful operation */ User;
372+
export type CreateUsersWithListInputApiArg = {
373+
body: User[];
374+
};
375+
export type LoginUserApiResponse = /** status 200 successful operation */ string;
376+
export type LoginUserApiArg = {
377+
/** The user name for login */
378+
username?: string;
379+
/** The password for login in clear text */
380+
password?: string;
381+
};
382+
export type LogoutUserApiResponse = unknown;
383+
export type LogoutUserApiArg = void;
384+
export type GetUserByNameApiResponse = /** status 200 successful operation */ User;
385+
export type GetUserByNameApiArg = {
386+
/** The name that needs to be fetched. Use user1 for testing. */
387+
username: string;
388+
};
389+
export type UpdateUserApiResponse = unknown;
390+
export type UpdateUserApiArg = {
391+
/** name that need to be deleted */
392+
username: string;
393+
/** Update an existent user in the store */
394+
user: User;
395+
};
396+
export type DeleteUserApiResponse = unknown;
397+
export type DeleteUserApiArg = {
398+
/** The name that needs to be deleted */
399+
username: string;
400+
};
401+
export type Category = {
402+
id?: number;
403+
name?: string;
404+
};
405+
export type Tag = {
406+
id?: number;
407+
name?: string;
408+
};
409+
export type Pet = {
410+
id?: number;
411+
name: string;
412+
category?: Category;
413+
photoUrls: string[];
414+
tags?: Tag[];
415+
status?: 'available' | 'pending' | 'sold';
416+
};
417+
export type ApiResponse = {
418+
code?: number;
419+
type?: string;
420+
message?: string;
421+
};
422+
export type Order = {
423+
id?: number;
424+
petId?: number;
425+
quantity?: number;
426+
shipDate?: string;
427+
status?: 'placed' | 'approved' | 'delivered';
428+
complete?: boolean;
429+
};
430+
export type User = {
431+
id?: number;
432+
username?: string;
433+
firstName?: string;
434+
lastName?: string;
435+
email?: string;
436+
password?: string;
437+
phone?: string;
438+
userStatus?: number;
439+
};
440+
441+
`;

packages/rtk-query-codegen-openapi/test/cli.test.ts

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@ import path from 'path';
55
import del from 'del';
66

77
function cli(args: string[], cwd: string): Promise<{ error: ExecException | null; stdout: string; stderr: string }> {
8+
const cmd = `${require.resolve('ts-node/dist/bin')} -T -P ${path.resolve('./tsconfig.json')} ${path.resolve(
9+
'./src/bin/cli.ts'
10+
)} ${args.join(' ')}`;
811
return new Promise((resolve) => {
9-
exec(
10-
`ts-node -T -P ${path.resolve('./tsconfig.json')} ${path.resolve('./src/bin/cli.ts')} ${args.join(' ')}`,
11-
{ cwd },
12-
(error, stdout, stderr) => {
13-
resolve({
14-
error,
15-
stdout,
16-
stderr,
17-
});
18-
}
19-
);
12+
exec(cmd, { cwd }, (error, stdout, stderr) => {
13+
resolve({
14+
error,
15+
stdout,
16+
stderr,
17+
});
18+
});
2019
});
2120
}
2221

@@ -32,7 +31,30 @@ afterEach(() => {
3231

3332
describe('CLI options testing', () => {
3433
test('generation with `config.example.js`', async () => {
35-
await cli([`./config.example.js`], __dirname);
34+
const out = await cli([`./config.example.js`], __dirname);
35+
36+
expect(out).toEqual({
37+
stdout: `Generating ./tmp/example.ts
38+
Done
39+
`,
40+
stderr: '',
41+
error: null,
42+
});
43+
44+
expect(fs.readFileSync(path.resolve(tmpDir, 'example.ts'), 'utf-8')).toMatchSnapshot();
45+
});
46+
47+
test('paths are relative to configfile, not to cwd', async () => {
48+
const out = await cli([`../test/config.example.js`], path.resolve(__dirname, '../src'));
49+
50+
expect(out).toEqual({
51+
stdout: `Generating ./tmp/example.ts
52+
Done
53+
`,
54+
stderr: '',
55+
error: null,
56+
});
57+
3658
expect(fs.readFileSync(path.resolve(tmpDir, 'example.ts'), 'utf-8')).toMatchSnapshot();
3759
});
3860

0 commit comments

Comments
 (0)