Skip to content

Commit facfe16

Browse files
committed
- Added testcases for query parsing
1 parent 4c21c51 commit facfe16

File tree

8 files changed

+123
-2
lines changed

8 files changed

+123
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
66
- Updated dependencies
77
### Added
88
- Added test cases for CLI commands
9+
- Added test cases for query parsing
910

1011
## [0.18.1] - 2022-01-31
1112
### Fixed

test/__snapshots__/index.spec.ts.snap

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3541,6 +3541,7 @@ export type { ModelWithPattern } from './models/ModelWithPattern';
35413541
export type { ModelWithProperties } from './models/ModelWithProperties';
35423542
export type { ModelWithReference } from './models/ModelWithReference';
35433543
export type { ModelWithString } from './models/ModelWithString';
3544+
export type { Pageable } from './models/Pageable';
35443545
export type { SimpleBoolean } from './models/SimpleBoolean';
35453546
export type { SimpleFile } from './models/SimpleFile';
35463547
export type { SimpleInteger } from './models/SimpleInteger';
@@ -3601,6 +3602,7 @@ export { $ModelWithPattern } from './schemas/$ModelWithPattern';
36013602
export { $ModelWithProperties } from './schemas/$ModelWithProperties';
36023603
export { $ModelWithReference } from './schemas/$ModelWithReference';
36033604
export { $ModelWithString } from './schemas/$ModelWithString';
3605+
export { $Pageable } from './schemas/$Pageable';
36043606
export { $SimpleBoolean } from './schemas/$SimpleBoolean';
36053607
export { $SimpleFile } from './schemas/$SimpleFile';
36063608
export { $SimpleInteger } from './schemas/$SimpleInteger';
@@ -4525,6 +4527,19 @@ export type ModelWithString = {
45254527
"
45264528
`;
45274529

4530+
exports[`v3 should generate: ./test/generated/v3/models/Pageable.ts 1`] = `
4531+
"/* istanbul ignore file */
4532+
/* tslint:disable */
4533+
/* eslint-disable */
4534+
4535+
export type Pageable = {
4536+
page?: number;
4537+
size?: number;
4538+
sort?: Array<string>;
4539+
};
4540+
"
4541+
`;
4542+
45284543
exports[`v3 should generate: ./test/generated/v3/models/SimpleBoolean.ts 1`] = `
45294544
"/* istanbul ignore file */
45304545
/* tslint:disable */
@@ -5612,6 +5627,31 @@ export const $ModelWithString = {
56125627
} as const;"
56135628
`;
56145629

5630+
exports[`v3 should generate: ./test/generated/v3/schemas/$Pageable.ts 1`] = `
5631+
"/* istanbul ignore file */
5632+
/* tslint:disable */
5633+
/* eslint-disable */
5634+
export const $Pageable = {
5635+
properties: {
5636+
page: {
5637+
type: 'number',
5638+
format: 'int32',
5639+
},
5640+
size: {
5641+
type: 'number',
5642+
format: 'int32',
5643+
minimum: 1,
5644+
},
5645+
sort: {
5646+
type: 'array',
5647+
contains: {
5648+
type: 'string',
5649+
},
5650+
},
5651+
},
5652+
} as const;"
5653+
`;
5654+
56155655
exports[`v3 should generate: ./test/generated/v3/schemas/$SimpleBoolean.ts 1`] = `
56165656
"/* istanbul ignore file */
56175657
/* tslint:disable */
@@ -6305,6 +6345,7 @@ exports[`v3 should generate: ./test/generated/v3/services/ParametersService.ts 1
63056345
/* tslint:disable */
63066346
/* eslint-disable */
63076347
import type { ModelWithString } from '../models/ModelWithString';
6348+
import type { Pageable } from '../models/Pageable';
63086349

63096350
import type { CancelablePromise } from '../core/CancelablePromise';
63106351
import { OpenAPI } from '../core/OpenAPI';
@@ -6427,7 +6468,7 @@ export class ParametersService {
64276468
* @throws ApiError
64286469
*/
64296470
public static postCallWithOptionalParam(
6430-
parameter: string,
6471+
parameter: Pageable,
64316472
requestBody?: ModelWithString,
64326473
): CancelablePromise<void> {
64336474
return __request(OpenAPI, {

test/e2e/v3.axios.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,14 @@ describe('v3.axios', () => {
138138
})
139139
);
140140
});
141+
142+
it('it should parse query params', async () => {
143+
const { ParametersService } = require('./generated/v3/axios/index.js');
144+
const result = (await ParametersService.postCallWithOptionalParam({
145+
page: 0,
146+
size: 1,
147+
sort: ['___location'],
148+
})) as Promise<any>;
149+
expect((result as any).query).toStrictEqual({ parameter: { page: '0', size: '1', sort: '___location' } });
150+
});
141151
});

test/e2e/v3.babel.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,18 @@ describe('v3.babel', () => {
164164
})
165165
);
166166
});
167+
168+
it('it should parse query params', async () => {
169+
const result = await browser.evaluate(async () => {
170+
const { ParametersService } = (window as any).api;
171+
return (await ParametersService.postCallWithOptionalParam({
172+
parameter: {
173+
page: 0,
174+
size: 1,
175+
sort: ['___location'],
176+
},
177+
})) as Promise<any>;
178+
});
179+
expect(result.query).toStrictEqual({ parameter: { page: '0', size: '1', sort: '___location' } });
180+
});
167181
});

test/e2e/v3.fetch.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,16 @@ describe('v3.fetch', () => {
158158
})
159159
);
160160
});
161+
162+
it('it should parse query params', async () => {
163+
const result = await browser.evaluate(async () => {
164+
const { ParametersService } = (window as any).api;
165+
return (await ParametersService.postCallWithOptionalParam({
166+
page: 0,
167+
size: 1,
168+
sort: ['___location'],
169+
})) as Promise<any>;
170+
});
171+
expect(result.query).toStrictEqual({ parameter: { page: '0', size: '1', sort: '___location' } });
172+
});
161173
});

test/e2e/v3.node.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,14 @@ describe('v3.node', () => {
138138
})
139139
);
140140
});
141+
142+
it('it should parse query params', async () => {
143+
const { ParametersService } = require('./generated/v3/node/index.js');
144+
const result = (await ParametersService.postCallWithOptionalParam({
145+
page: 0,
146+
size: 1,
147+
sort: ['___location'],
148+
})) as Promise<any>;
149+
expect((result as any).query).toStrictEqual({ parameter: { page: '0', size: '1', sort: '___location' } });
150+
});
141151
});

test/e2e/v3.xhr.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,16 @@ describe('v3.xhr', () => {
157157
})
158158
);
159159
});
160+
161+
it('it should parse query params', async () => {
162+
const result = await browser.evaluate(async () => {
163+
const { ParametersService } = (window as any).api;
164+
return (await ParametersService.postCallWithOptionalParam({
165+
page: 0,
166+
size: 1,
167+
sort: ['___location'],
168+
})) as Promise<any>;
169+
});
170+
expect(result.query).toStrictEqual({ parameter: { page: '0', size: '1', sort: '___location' } });
171+
});
160172
});

test/spec/v3.json

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@
339339
"in": "query",
340340
"required": true,
341341
"schema": {
342-
"type": "string"
342+
"$ref": "#/components/schemas/Pageable"
343343
}
344344
}
345345
],
@@ -2400,6 +2400,27 @@
24002400
"format": "uri"
24012401
}
24022402
}
2403+
},
2404+
"Pageable": {
2405+
"type": "object",
2406+
"properties": {
2407+
"page": {
2408+
"minimum": 0,
2409+
"type": "integer",
2410+
"format": "int32"
2411+
},
2412+
"size": {
2413+
"minimum": 1,
2414+
"type": "integer",
2415+
"format": "int32"
2416+
},
2417+
"sort": {
2418+
"type": "array",
2419+
"items": {
2420+
"type": "string"
2421+
}
2422+
}
2423+
}
24032424
}
24042425
}
24052426
}

0 commit comments

Comments
 (0)