|
1 | 1 | import { describe, expect, it, vi } from 'vitest' |
2 | | -import { buildListFn, buildRetrieveFn, discoverListEndpoints } from '../listFnResolver' |
| 2 | +import { buildListFn, buildRetrieveFn } from '../listFnResolver' |
| 3 | +import { SpecParser } from '../specParser' |
3 | 4 | import { isDeprecatedOperation } from '../specCleaning' |
4 | 5 | import { minimalStripeOpenApiSpec } from './fixtures/minimalSpec' |
5 | 6 |
|
6 | | -describe('discoverListEndpoints', () => { |
| 7 | +describe('SpecParser.discoverListEndpoints', () => { |
| 8 | + const parser = new SpecParser() |
| 9 | + |
7 | 10 | it('maps table names to their API paths', () => { |
8 | | - const endpoints = discoverListEndpoints(minimalStripeOpenApiSpec) |
| 11 | + const endpoints = parser.discoverListEndpoints(minimalStripeOpenApiSpec) |
9 | 12 |
|
10 | 13 | expect(endpoints.get('customers')).toEqual({ |
11 | 14 | tableName: 'customers', |
@@ -37,7 +40,7 @@ describe('discoverListEndpoints', () => { |
37 | 40 | }) |
38 | 41 |
|
39 | 42 | it('discovers v2 list endpoints using next_page_url format', () => { |
40 | | - const endpoints = discoverListEndpoints(minimalStripeOpenApiSpec) |
| 43 | + const endpoints = parser.discoverListEndpoints(minimalStripeOpenApiSpec) |
41 | 44 |
|
42 | 45 | expect(endpoints.get('v2_core_accounts')).toEqual({ |
43 | 46 | tableName: 'v2_core_accounts', |
@@ -89,35 +92,37 @@ describe('discoverListEndpoints', () => { |
89 | 92 | }, |
90 | 93 | }, |
91 | 94 | } |
92 | | - const endpoints = discoverListEndpoints(spec) |
| 95 | + const endpoints = parser.discoverListEndpoints(spec) |
93 | 96 | const paths = Array.from(endpoints.values()).map((e) => e.apiPath) |
94 | 97 | expect(paths).not.toContain('/v1/customers/{customer}/sources') |
95 | 98 | }) |
96 | 99 |
|
97 | 100 | it('skips endpoints with deprecated: true on the operation', () => { |
98 | | - const endpoints = discoverListEndpoints(minimalStripeOpenApiSpec) |
| 101 | + const endpoints = parser.discoverListEndpoints(minimalStripeOpenApiSpec) |
99 | 102 | const tables = Array.from(endpoints.keys()) |
100 | 103 | expect(tables).not.toContain('deprecated_widgets') |
101 | 104 | }) |
102 | 105 |
|
103 | 106 | it('skips endpoints with [Deprecated] in the description', () => { |
104 | | - const endpoints = discoverListEndpoints(minimalStripeOpenApiSpec) |
| 107 | + const endpoints = parser.discoverListEndpoints(minimalStripeOpenApiSpec) |
105 | 108 | const tables = Array.from(endpoints.keys()) |
106 | 109 | expect(tables).not.toContain('exchange_rates') |
107 | 110 | }) |
108 | 111 |
|
109 | 112 | it('skips endpoints that appear in the generated global deprecated paths set', () => { |
110 | | - const endpoints = discoverListEndpoints(minimalStripeOpenApiSpec) |
| 113 | + const endpoints = parser.discoverListEndpoints(minimalStripeOpenApiSpec) |
111 | 114 | const tables = Array.from(endpoints.keys()) |
112 | 115 | expect(tables).not.toContain('recipients') |
113 | 116 | expect(tables).toContain('customers') |
114 | 117 | }) |
115 | 118 |
|
116 | 119 | it('returns empty map when spec has no paths', () => { |
117 | | - const endpoints = discoverListEndpoints({ openapi: '3.0.0' }) |
| 120 | + const endpoints = parser.discoverListEndpoints({ openapi: '3.0.0' }) |
118 | 121 | expect(endpoints.size).toBe(0) |
119 | 122 | }) |
| 123 | +}) |
120 | 124 |
|
| 125 | +describe('buildListFn / buildRetrieveFn', () => { |
121 | 126 | it('uses the injected fetch for list and retrieve calls', async () => { |
122 | 127 | const fetchMock = vi.fn( |
123 | 128 | async () => new Response(JSON.stringify({ data: [], has_more: false }), { status: 200 }) |
|
0 commit comments