|
1 | 1 | import { expect, test } from 'bun:test' |
| 2 | +import type { UrlMapValue } from '@devup-api/core' |
2 | 3 | import type { OpenAPIV3_1 } from 'openapi-types' |
3 | 4 | import { createUrlMap } from '../create-url-map' |
4 | 5 |
|
@@ -55,7 +56,7 @@ test.each([ |
55 | 56 |
|
56 | 57 | const result = createUrlMap(schema, options) |
57 | 58 |
|
58 | | - expect(result).toEqual(expected) |
| 59 | + expect(result).toEqual(expected as Record<string, UrlMapValue>) |
59 | 60 | }) |
60 | 61 |
|
61 | 62 | test('converts path parameters based on convertCase', () => { |
@@ -109,9 +110,13 @@ test.each([ |
109 | 110 | const result = createUrlMap(schema) |
110 | 111 |
|
111 | 112 | expect(result).toHaveProperty(expectedKey) |
112 | | - expect(result[expectedKey].method).toBe(expectedMethod) |
| 113 | + expect(result[expectedKey]?.method).toBe( |
| 114 | + expectedMethod as 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH', |
| 115 | + ) |
113 | 116 | expect(result).toHaveProperty('/users') |
114 | | - expect(result['/users'].method).toBe(expectedMethod) |
| 117 | + expect(result['/users']?.method).toBe( |
| 118 | + expectedMethod as 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH', |
| 119 | + ) |
115 | 120 | }) |
116 | 121 |
|
117 | 122 | test('handles operation without operationId', () => { |
@@ -182,19 +187,21 @@ test('handles undefined paths', () => { |
182 | 187 | const schema: OpenAPIV3_1.Document = { |
183 | 188 | openapi: '3.1.0', |
184 | 189 | info: { title: 'Test API', version: '1.0.0' }, |
| 190 | + components: {}, |
| 191 | + paths: {}, |
185 | 192 | } |
186 | 193 |
|
187 | 194 | const result = createUrlMap(schema) |
188 | 195 |
|
189 | 196 | expect(result).toEqual({}) |
190 | 197 | }) |
191 | 198 |
|
192 | | -test('handles null pathItem', () => { |
| 199 | +test('handles undefined pathItem', () => { |
193 | 200 | const schema: OpenAPIV3_1.Document = { |
194 | 201 | openapi: '3.1.0', |
195 | 202 | info: { title: 'Test API', version: '1.0.0' }, |
196 | 203 | paths: { |
197 | | - '/users': null, |
| 204 | + '/users': undefined, |
198 | 205 | }, |
199 | 206 | } |
200 | 207 |
|
@@ -282,7 +289,7 @@ test.each([ |
282 | 289 | convertCase: caseType as 'camel' | 'snake' | 'pascal', |
283 | 290 | }) |
284 | 291 |
|
285 | | - expect(result[expectedPath].url).toBe(expectedUrl) |
| 292 | + expect(result[expectedPath]?.url).toBe(expectedUrl) |
286 | 293 | }) |
287 | 294 |
|
288 | 295 | test.each([ |
|
0 commit comments