cloudflare/cloudflare-typescript
Publicmirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable
tests/api-resources/ai-gateway/provider-configs.test.ts
82lines · modecode
| 1 | // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | |
| 3 | import { AIGateway } from 'cloudflare/resources/ai-gateway/ai-gateway'; |
| 4 | import { BaseProviderConfigs } from 'cloudflare/resources/ai-gateway/provider-configs'; |
| 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: [BaseProviderConfigs], |
| 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: [AIGateway], |
| 27 | }); |
| 28 | |
| 29 | const runTests = (client: PartialCloudflare<{ aiGateway: { providerConfigs: BaseProviderConfigs } }>) => { |
| 30 | test('create: only required params', async () => { |
| 31 | const responsePromise = client.aiGateway.providerConfigs.create('my-gateway', { |
| 32 | account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', |
| 33 | alias: 'alias', |
| 34 | default_config: true, |
| 35 | provider_slug: 'provider_slug', |
| 36 | }); |
| 37 | const rawResponse = await responsePromise.asResponse(); |
| 38 | expect(rawResponse).toBeInstanceOf(Response); |
| 39 | const response = await responsePromise; |
| 40 | expect(response).not.toBeInstanceOf(Response); |
| 41 | const dataAndResponse = await responsePromise.withResponse(); |
| 42 | expect(dataAndResponse.data).toBe(response); |
| 43 | expect(dataAndResponse.response).toBe(rawResponse); |
| 44 | }); |
| 45 | |
| 46 | test('create: required and optional params', async () => { |
| 47 | const response = await client.aiGateway.providerConfigs.create('my-gateway', { |
| 48 | account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', |
| 49 | alias: 'alias', |
| 50 | default_config: true, |
| 51 | provider_slug: 'provider_slug', |
| 52 | rate_limit: 0, |
| 53 | rate_limit_period: 0, |
| 54 | secret: 'secret', |
| 55 | secret_id: 'secret_id', |
| 56 | }); |
| 57 | }); |
| 58 | |
| 59 | test('list: only required params', async () => { |
| 60 | const responsePromise = client.aiGateway.providerConfigs.list('my-gateway', { |
| 61 | account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', |
| 62 | }); |
| 63 | const rawResponse = await responsePromise.asResponse(); |
| 64 | expect(rawResponse).toBeInstanceOf(Response); |
| 65 | const response = await responsePromise; |
| 66 | expect(response).not.toBeInstanceOf(Response); |
| 67 | const dataAndResponse = await responsePromise.withResponse(); |
| 68 | expect(dataAndResponse.data).toBe(response); |
| 69 | expect(dataAndResponse.response).toBe(rawResponse); |
| 70 | }); |
| 71 | |
| 72 | test('list: required and optional params', async () => { |
| 73 | const response = await client.aiGateway.providerConfigs.list('my-gateway', { |
| 74 | account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', |
| 75 | page: 1, |
| 76 | per_page: 1, |
| 77 | }); |
| 78 | }); |
| 79 | }; |
| 80 | describe('resource providerConfigs', () => runTests(client)); |
| 81 | describe('resource providerConfigs (tree shakable, base)', () => runTests(partialClient)); |
| 82 | describe('resource providerConfigs (tree shakable, subresource)', () => runTests(parentPartialClient)); |
| 83 | |