cloudflare/cloudflare-typescript
Publicmirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable
tests/api-resources/api-gateway/schemas.test.ts
51lines · modecode
| 1 | // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | |
| 3 | import { APIGateway } from 'cloudflare/resources/api-gateway/api-gateway'; |
| 4 | import { BaseSchemas } from 'cloudflare/resources/api-gateway/schemas'; |
| 5 | |
| 6 | import Cloudflare from 'cloudflare'; |
| 7 | import { createClient, type PartialCloudflare } from 'cloudflare/tree-shakable'; |
| 8 | |
| 9 | const client = new Cloudflare({ |
| 10 | apiKey: '144c9defac04969c7bfad8efaa8ea194', |
| 11 | apiEmail: 'user@example.com', |
| 12 | baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', |
| 13 | }); |
| 14 | |
| 15 | const partialClient = createClient({ |
| 16 | apiKey: '144c9defac04969c7bfad8efaa8ea194', |
| 17 | apiEmail: 'user@example.com', |
| 18 | baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', |
| 19 | resources: [BaseSchemas], |
| 20 | }); |
| 21 | |
| 22 | const parentPartialClient = createClient({ |
| 23 | apiKey: '144c9defac04969c7bfad8efaa8ea194', |
| 24 | apiEmail: 'user@example.com', |
| 25 | baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', |
| 26 | resources: [APIGateway], |
| 27 | }); |
| 28 | |
| 29 | const runTests = (client: PartialCloudflare<{ apiGateway: { schemas: BaseSchemas } }>) => { |
| 30 | test('list: only required params', async () => { |
| 31 | const responsePromise = client.apiGateway.schemas.list({ zone_id: '023e105f4ecef8ad9ca31a8372d0c353' }); |
| 32 | const rawResponse = await responsePromise.asResponse(); |
| 33 | expect(rawResponse).toBeInstanceOf(Response); |
| 34 | const response = await responsePromise; |
| 35 | expect(response).not.toBeInstanceOf(Response); |
| 36 | const dataAndResponse = await responsePromise.withResponse(); |
| 37 | expect(dataAndResponse.data).toBe(response); |
| 38 | expect(dataAndResponse.response).toBe(rawResponse); |
| 39 | }); |
| 40 | |
| 41 | test('list: required and optional params', async () => { |
| 42 | const response = await client.apiGateway.schemas.list({ |
| 43 | zone_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 44 | feature: ['thresholds'], |
| 45 | host: ['www.example.com'], |
| 46 | }); |
| 47 | }); |
| 48 | }; |
| 49 | describe('resource schemas', () => runTests(client)); |
| 50 | describe('resource schemas (tree shakable, base)', () => runTests(partialClient)); |
| 51 | describe('resource schemas (tree shakable, subresource)', () => runTests(parentPartialClient)); |
| 52 | |