Skip to content

Commit 671a6f5

Browse files
authored
test(pagination): fix new tests in CI
1 parent 1f4fa7a commit 671a6f5

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

packages/openapi-ts/src/ir/__tests__/pagination.test.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,14 @@ describe('operationPagination', () => {
7878
const queryParam = (
7979
name: string,
8080
type: IR.SchemaObject['type'] = 'string',
81+
pagination = false,
8182
): IR.ParameterObject => ({
82-
explode: true,
83-
location: 'query',
8483
name,
84+
location: 'query',
8585
schema: { type },
8686
style: 'form',
87+
explode: true,
88+
...(pagination ? { pagination: true } : {}),
8789
});
8890

8991
const emptyContext = {} as IR.Context;
@@ -105,8 +107,7 @@ describe('operationPagination', () => {
105107
method: 'get',
106108
parameters: {
107109
query: {
108-
page: queryParam('page', 'integer'),
109-
perPage: queryParam('perPage', 'integer'),
110+
page: queryParam('page', 'integer', true),
110111
},
111112
},
112113
},
@@ -128,7 +129,7 @@ describe('operationPagination', () => {
128129

129130
it.each(queryScenarios)(
130131
'query params for $operation.id → $hasPagination',
131-
({ hasPagination, operation }) => {
132+
({ hasPagination, operation }: { hasPagination: boolean; operation: IR.OperationObject }) => {
132133
const result = operationPagination({ context: emptyContext, operation });
133134
expect(Boolean(result)).toEqual(hasPagination);
134135
},
@@ -137,17 +138,17 @@ describe('operationPagination', () => {
137138
it('body.pagination === true returns entire body', () => {
138139
const operation: IR.OperationObject = {
139140
...baseOperationMeta,
141+
id: 'bodyTrue',
140142
body: {
141143
mediaType: 'application/json',
142144
pagination: true,
143145
schema: {
146+
type: 'object',
144147
properties: {
145148
page: { type: 'integer' },
146149
},
147-
type: 'object',
148150
},
149151
},
150-
id: 'bodyTrue',
151152
};
152153

153154
const result = operationPagination({ context: emptyContext, operation });
@@ -160,22 +161,22 @@ describe('operationPagination', () => {
160161
it('body.pagination = "pagination" returns the matching property', () => {
161162
const operation: IR.OperationObject = {
162163
...baseOperationMeta,
164+
id: 'bodyField',
163165
body: {
164166
mediaType: 'application/json',
165167
pagination: 'pagination',
166168
schema: {
169+
type: 'object',
167170
properties: {
168171
pagination: {
172+
type: 'object',
169173
properties: {
170174
page: { type: 'integer' },
171175
},
172-
type: 'object',
173176
},
174177
},
175-
type: 'object',
176178
},
177179
},
178-
id: 'bodyField',
179180
};
180181

181182
const result = operationPagination({ context: emptyContext, operation });
@@ -188,26 +189,26 @@ describe('operationPagination', () => {
188189
it('resolves $ref and uses the resolved pagination property', () => {
189190
const context: IR.Context = {
190191
resolveIrRef: vi.fn().mockReturnValue({
192+
type: 'object',
191193
properties: {
192194
pagination: {
195+
type: 'object',
193196
properties: {
194197
page: { type: 'integer' },
195198
},
196-
type: 'object',
197199
},
198200
},
199-
type: 'object',
200201
}),
201202
} as unknown as IR.Context;
202203

203204
const operation: IR.OperationObject = {
204205
...baseOperationMeta,
206+
id: 'refPagination',
205207
body: {
206208
mediaType: 'application/json',
207209
pagination: 'pagination',
208210
schema: { $ref: '#/components/schemas/PaginationBody' },
209211
},
210-
id: 'refPagination',
211212
};
212213

213214
const result = operationPagination({ context, operation });
@@ -223,27 +224,28 @@ describe('operationPagination', () => {
223224
it('falls back to query when pagination key not found in body', () => {
224225
const operation: IR.OperationObject = {
225226
...baseOperationMeta,
227+
id: 'fallback',
228+
parameters: {
229+
query: {
230+
cursor: queryParam('cursor', 'string', true),
231+
},
232+
},
226233
body: {
227234
mediaType: 'application/json',
228235
pagination: 'pagination',
229236
schema: {
237+
type: 'object',
230238
properties: {
231239
notPagination: { type: 'string' },
232240
},
233-
type: 'object',
234-
},
235-
},
236-
id: 'fallback',
237-
parameters: {
238-
query: {
239-
cursor: queryParam('cursor', 'string'),
240241
},
241242
},
242243
};
243244

244245
const result = operationPagination({ context: emptyContext, operation });
245246

246247
expect(result?.in).toEqual('query');
247-
expect(result?.schema?.properties?.cursor).toBeDefined();
248+
expect(result?.name).toEqual('cursor');
249+
expect(result?.schema?.type).toEqual('string');
248250
});
249-
});
251+
});

0 commit comments

Comments
 (0)