cloudflare/cloudflare-typescript
Publicmirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable
tests/api-resources/api-gateway/configurations.test.ts
74lines · 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 { BaseConfigurations } from 'cloudflare/resources/api-gateway/configurations'; |
| 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: [BaseConfigurations], |
| 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: { configurations: BaseConfigurations } }>) => { |
| 30 | test('update: only required params', async () => { |
| 31 | const responsePromise = client.apiGateway.configurations.update({ |
| 32 | zone_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 33 | auth_id_characteristics: [{ name: 'authorization', type: 'header' }], |
| 34 | }); |
| 35 | const rawResponse = await responsePromise.asResponse(); |
| 36 | expect(rawResponse).toBeInstanceOf(Response); |
| 37 | const response = await responsePromise; |
| 38 | expect(response).not.toBeInstanceOf(Response); |
| 39 | const dataAndResponse = await responsePromise.withResponse(); |
| 40 | expect(dataAndResponse.data).toBe(response); |
| 41 | expect(dataAndResponse.response).toBe(rawResponse); |
| 42 | }); |
| 43 | |
| 44 | test('update: required and optional params', async () => { |
| 45 | const response = await client.apiGateway.configurations.update({ |
| 46 | zone_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 47 | auth_id_characteristics: [{ name: 'authorization', type: 'header' }], |
| 48 | normalize: true, |
| 49 | }); |
| 50 | }); |
| 51 | |
| 52 | test('get: only required params', async () => { |
| 53 | const responsePromise = client.apiGateway.configurations.get({ |
| 54 | zone_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 55 | }); |
| 56 | const rawResponse = await responsePromise.asResponse(); |
| 57 | expect(rawResponse).toBeInstanceOf(Response); |
| 58 | const response = await responsePromise; |
| 59 | expect(response).not.toBeInstanceOf(Response); |
| 60 | const dataAndResponse = await responsePromise.withResponse(); |
| 61 | expect(dataAndResponse.data).toBe(response); |
| 62 | expect(dataAndResponse.response).toBe(rawResponse); |
| 63 | }); |
| 64 | |
| 65 | test('get: required and optional params', async () => { |
| 66 | const response = await client.apiGateway.configurations.get({ |
| 67 | zone_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 68 | normalize: true, |
| 69 | }); |
| 70 | }); |
| 71 | }; |
| 72 | describe('resource configurations', () => runTests(client)); |
| 73 | describe('resource configurations (tree shakable, base)', () => runTests(partialClient)); |
| 74 | describe('resource configurations (tree shakable, subresource)', () => runTests(parentPartialClient)); |
| 75 | |