From facfe1666bd243b25b016574a6a93d92ef4444b5 Mon Sep 17 00:00:00 2001 From: Ferdi Koomen Date: Wed, 2 Feb 2022 21:20:12 +0100 Subject: [PATCH] - Added testcases for query parsing --- CHANGELOG.md | 1 + test/__snapshots__/index.spec.ts.snap | 43 ++++++++++++++++++++++++++- test/e2e/v3.axios.spec.ts | 10 +++++++ test/e2e/v3.babel.spec.ts | 14 +++++++++ test/e2e/v3.fetch.spec.ts | 12 ++++++++ test/e2e/v3.node.spec.ts | 10 +++++++ test/e2e/v3.xhr.spec.ts | 12 ++++++++ test/spec/v3.json | 23 +++++++++++++- 8 files changed, 123 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 237f80c7..aa46be02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. - Updated dependencies ### Added - Added test cases for CLI commands +- Added test cases for query parsing ## [0.18.1] - 2022-01-31 ### Fixed diff --git a/test/__snapshots__/index.spec.ts.snap b/test/__snapshots__/index.spec.ts.snap index 287afae5..f294281b 100644 --- a/test/__snapshots__/index.spec.ts.snap +++ b/test/__snapshots__/index.spec.ts.snap @@ -3541,6 +3541,7 @@ export type { ModelWithPattern } from './models/ModelWithPattern'; export type { ModelWithProperties } from './models/ModelWithProperties'; export type { ModelWithReference } from './models/ModelWithReference'; export type { ModelWithString } from './models/ModelWithString'; +export type { Pageable } from './models/Pageable'; export type { SimpleBoolean } from './models/SimpleBoolean'; export type { SimpleFile } from './models/SimpleFile'; export type { SimpleInteger } from './models/SimpleInteger'; @@ -3601,6 +3602,7 @@ export { $ModelWithPattern } from './schemas/$ModelWithPattern'; export { $ModelWithProperties } from './schemas/$ModelWithProperties'; export { $ModelWithReference } from './schemas/$ModelWithReference'; export { $ModelWithString } from './schemas/$ModelWithString'; +export { $Pageable } from './schemas/$Pageable'; export { $SimpleBoolean } from './schemas/$SimpleBoolean'; export { $SimpleFile } from './schemas/$SimpleFile'; export { $SimpleInteger } from './schemas/$SimpleInteger'; @@ -4525,6 +4527,19 @@ export type ModelWithString = { " `; +exports[`v3 should generate: ./test/generated/v3/models/Pageable.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export type Pageable = { + page?: number; + size?: number; + sort?: Array; +}; +" +`; + exports[`v3 should generate: ./test/generated/v3/models/SimpleBoolean.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ @@ -5612,6 +5627,31 @@ export const $ModelWithString = { } as const;" `; +exports[`v3 should generate: ./test/generated/v3/schemas/$Pageable.ts 1`] = ` +"/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $Pageable = { + properties: { + page: { + type: 'number', + format: 'int32', + }, + size: { + type: 'number', + format: 'int32', + minimum: 1, + }, + sort: { + type: 'array', + contains: { + type: 'string', + }, + }, + }, +} as const;" +`; + exports[`v3 should generate: ./test/generated/v3/schemas/$SimpleBoolean.ts 1`] = ` "/* istanbul ignore file */ /* tslint:disable */ @@ -6305,6 +6345,7 @@ exports[`v3 should generate: ./test/generated/v3/services/ParametersService.ts 1 /* tslint:disable */ /* eslint-disable */ import type { ModelWithString } from '../models/ModelWithString'; +import type { Pageable } from '../models/Pageable'; import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; @@ -6427,7 +6468,7 @@ export class ParametersService { * @throws ApiError */ public static postCallWithOptionalParam( - parameter: string, + parameter: Pageable, requestBody?: ModelWithString, ): CancelablePromise { return __request(OpenAPI, { diff --git a/test/e2e/v3.axios.spec.ts b/test/e2e/v3.axios.spec.ts index 3c809b89..b43b0a54 100644 --- a/test/e2e/v3.axios.spec.ts +++ b/test/e2e/v3.axios.spec.ts @@ -138,4 +138,14 @@ describe('v3.axios', () => { }) ); }); + + it('it should parse query params', async () => { + const { ParametersService } = require('./generated/v3/axios/index.js'); + const result = (await ParametersService.postCallWithOptionalParam({ + page: 0, + size: 1, + sort: ['location'], + })) as Promise; + expect((result as any).query).toStrictEqual({ parameter: { page: '0', size: '1', sort: 'location' } }); + }); }); diff --git a/test/e2e/v3.babel.spec.ts b/test/e2e/v3.babel.spec.ts index 7ad9a0f4..42463b4b 100644 --- a/test/e2e/v3.babel.spec.ts +++ b/test/e2e/v3.babel.spec.ts @@ -164,4 +164,18 @@ describe('v3.babel', () => { }) ); }); + + it('it should parse query params', async () => { + const result = await browser.evaluate(async () => { + const { ParametersService } = (window as any).api; + return (await ParametersService.postCallWithOptionalParam({ + parameter: { + page: 0, + size: 1, + sort: ['location'], + }, + })) as Promise; + }); + expect(result.query).toStrictEqual({ parameter: { page: '0', size: '1', sort: 'location' } }); + }); }); diff --git a/test/e2e/v3.fetch.spec.ts b/test/e2e/v3.fetch.spec.ts index c055a9d0..2fb58d1e 100644 --- a/test/e2e/v3.fetch.spec.ts +++ b/test/e2e/v3.fetch.spec.ts @@ -158,4 +158,16 @@ describe('v3.fetch', () => { }) ); }); + + it('it should parse query params', async () => { + const result = await browser.evaluate(async () => { + const { ParametersService } = (window as any).api; + return (await ParametersService.postCallWithOptionalParam({ + page: 0, + size: 1, + sort: ['location'], + })) as Promise; + }); + expect(result.query).toStrictEqual({ parameter: { page: '0', size: '1', sort: 'location' } }); + }); }); diff --git a/test/e2e/v3.node.spec.ts b/test/e2e/v3.node.spec.ts index 153d23db..5dd4ec34 100644 --- a/test/e2e/v3.node.spec.ts +++ b/test/e2e/v3.node.spec.ts @@ -138,4 +138,14 @@ describe('v3.node', () => { }) ); }); + + it('it should parse query params', async () => { + const { ParametersService } = require('./generated/v3/node/index.js'); + const result = (await ParametersService.postCallWithOptionalParam({ + page: 0, + size: 1, + sort: ['location'], + })) as Promise; + expect((result as any).query).toStrictEqual({ parameter: { page: '0', size: '1', sort: 'location' } }); + }); }); diff --git a/test/e2e/v3.xhr.spec.ts b/test/e2e/v3.xhr.spec.ts index b677be5b..a117027a 100644 --- a/test/e2e/v3.xhr.spec.ts +++ b/test/e2e/v3.xhr.spec.ts @@ -157,4 +157,16 @@ describe('v3.xhr', () => { }) ); }); + + it('it should parse query params', async () => { + const result = await browser.evaluate(async () => { + const { ParametersService } = (window as any).api; + return (await ParametersService.postCallWithOptionalParam({ + page: 0, + size: 1, + sort: ['location'], + })) as Promise; + }); + expect(result.query).toStrictEqual({ parameter: { page: '0', size: '1', sort: 'location' } }); + }); }); diff --git a/test/spec/v3.json b/test/spec/v3.json index fae6f5b9..c336bda8 100644 --- a/test/spec/v3.json +++ b/test/spec/v3.json @@ -339,7 +339,7 @@ "in": "query", "required": true, "schema": { - "type": "string" + "$ref": "#/components/schemas/Pageable" } } ], @@ -2400,6 +2400,27 @@ "format": "uri" } } + }, + "Pageable": { + "type": "object", + "properties": { + "page": { + "minimum": 0, + "type": "integer", + "format": "int32" + }, + "size": { + "minimum": 1, + "type": "integer", + "format": "int32" + }, + "sort": { + "type": "array", + "items": { + "type": "string" + } + } + } } } }