cloudflare/cloudflare-typescript
Publicmirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable
tests/api-resources/ai-gateway/ai-gateway.test.ts
228lines · modecode
| 1 | // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | |
| 3 | import { BaseAIGateway } from 'cloudflare/resources/ai-gateway/ai-gateway'; |
| 4 | |
| 5 | import Cloudflare from 'cloudflare'; |
| 6 | import { createClient, type PartialCloudflare } from 'cloudflare/tree-shakable'; |
| 7 | |
| 8 | const client = new Cloudflare({ |
| 9 | apiKey: '144c9defac04969c7bfad8efaa8ea194', |
| 10 | apiEmail: 'user@example.com', |
| 11 | baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', |
| 12 | }); |
| 13 | |
| 14 | const partialClient = createClient({ |
| 15 | apiKey: '144c9defac04969c7bfad8efaa8ea194', |
| 16 | apiEmail: 'user@example.com', |
| 17 | baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', |
| 18 | resources: [BaseAIGateway], |
| 19 | }); |
| 20 | |
| 21 | const runTests = (client: PartialCloudflare<{ aiGateway: BaseAIGateway }>) => { |
| 22 | test('create: only required params', async () => { |
| 23 | const responsePromise = client.aiGateway.create({ |
| 24 | account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', |
| 25 | id: 'my-gateway', |
| 26 | cache_invalidate_on_update: true, |
| 27 | cache_ttl: 0, |
| 28 | collect_logs: true, |
| 29 | rate_limiting_interval: 0, |
| 30 | rate_limiting_limit: 0, |
| 31 | }); |
| 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('create: required and optional params', async () => { |
| 42 | const response = await client.aiGateway.create({ |
| 43 | account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', |
| 44 | id: 'my-gateway', |
| 45 | cache_invalidate_on_update: true, |
| 46 | cache_ttl: 0, |
| 47 | collect_logs: true, |
| 48 | rate_limiting_interval: 0, |
| 49 | rate_limiting_limit: 0, |
| 50 | authentication: true, |
| 51 | log_management: 10000, |
| 52 | log_management_strategy: 'STOP_INSERTING', |
| 53 | logpush: true, |
| 54 | logpush_public_key: 'xxxxxxxxxxxxxxxx', |
| 55 | rate_limiting_technique: 'fixed', |
| 56 | retry_backoff: 'constant', |
| 57 | retry_delay: 0, |
| 58 | retry_max_attempts: 1, |
| 59 | workers_ai_billing_mode: 'postpaid', |
| 60 | zdr: true, |
| 61 | }); |
| 62 | }); |
| 63 | |
| 64 | test('update: only required params', async () => { |
| 65 | const responsePromise = client.aiGateway.update('my-gateway', { |
| 66 | account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', |
| 67 | cache_invalidate_on_update: true, |
| 68 | cache_ttl: 0, |
| 69 | collect_logs: true, |
| 70 | rate_limiting_interval: 0, |
| 71 | rate_limiting_limit: 0, |
| 72 | }); |
| 73 | const rawResponse = await responsePromise.asResponse(); |
| 74 | expect(rawResponse).toBeInstanceOf(Response); |
| 75 | const response = await responsePromise; |
| 76 | expect(response).not.toBeInstanceOf(Response); |
| 77 | const dataAndResponse = await responsePromise.withResponse(); |
| 78 | expect(dataAndResponse.data).toBe(response); |
| 79 | expect(dataAndResponse.response).toBe(rawResponse); |
| 80 | }); |
| 81 | |
| 82 | test('update: required and optional params', async () => { |
| 83 | const response = await client.aiGateway.update('my-gateway', { |
| 84 | account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', |
| 85 | cache_invalidate_on_update: true, |
| 86 | cache_ttl: 0, |
| 87 | collect_logs: true, |
| 88 | rate_limiting_interval: 0, |
| 89 | rate_limiting_limit: 0, |
| 90 | authentication: true, |
| 91 | dlp: { |
| 92 | action: 'BLOCK', |
| 93 | enabled: true, |
| 94 | profiles: ['string'], |
| 95 | }, |
| 96 | guardrails: { |
| 97 | prompt: { |
| 98 | P1: 'FLAG', |
| 99 | S1: 'FLAG', |
| 100 | S10: 'FLAG', |
| 101 | S11: 'FLAG', |
| 102 | S12: 'FLAG', |
| 103 | S13: 'FLAG', |
| 104 | S2: 'FLAG', |
| 105 | S3: 'FLAG', |
| 106 | S4: 'FLAG', |
| 107 | S5: 'FLAG', |
| 108 | S6: 'FLAG', |
| 109 | S7: 'FLAG', |
| 110 | S8: 'FLAG', |
| 111 | S9: 'FLAG', |
| 112 | }, |
| 113 | response: { |
| 114 | P1: 'FLAG', |
| 115 | S1: 'FLAG', |
| 116 | S10: 'FLAG', |
| 117 | S11: 'FLAG', |
| 118 | S12: 'FLAG', |
| 119 | S13: 'FLAG', |
| 120 | S2: 'FLAG', |
| 121 | S3: 'FLAG', |
| 122 | S4: 'FLAG', |
| 123 | S5: 'FLAG', |
| 124 | S6: 'FLAG', |
| 125 | S7: 'FLAG', |
| 126 | S8: 'FLAG', |
| 127 | S9: 'FLAG', |
| 128 | }, |
| 129 | }, |
| 130 | log_management: 10000, |
| 131 | log_management_strategy: 'STOP_INSERTING', |
| 132 | logpush: true, |
| 133 | logpush_public_key: 'xxxxxxxxxxxxxxxx', |
| 134 | otel: [ |
| 135 | { |
| 136 | headers: { foo: 'string' }, |
| 137 | url: 'https://example.com', |
| 138 | authorization: 'authorization', |
| 139 | content_type: 'json', |
| 140 | }, |
| 141 | ], |
| 142 | rate_limiting_technique: 'fixed', |
| 143 | retry_backoff: 'constant', |
| 144 | retry_delay: 0, |
| 145 | retry_max_attempts: 1, |
| 146 | spend_limits: { |
| 147 | enabled: true, |
| 148 | rules: [ |
| 149 | { |
| 150 | limit: 1, |
| 151 | limitType: 'cost', |
| 152 | window: 1, |
| 153 | id: 'x', |
| 154 | enabled: true, |
| 155 | metadata: { foo: { mode: 'partition' } }, |
| 156 | model: { mode: 'filter', values: ['string'] }, |
| 157 | provider: { mode: 'filter', values: ['string'] }, |
| 158 | technique: 'fixed', |
| 159 | }, |
| 160 | ], |
| 161 | }, |
| 162 | store_id: 'store_id', |
| 163 | stripe: { authorization: 'authorization', usage_events: [{ payload: 'payload' }] }, |
| 164 | workers_ai_billing_mode: 'postpaid', |
| 165 | zdr: true, |
| 166 | }); |
| 167 | }); |
| 168 | |
| 169 | test('list: only required params', async () => { |
| 170 | const responsePromise = client.aiGateway.list({ account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0' }); |
| 171 | const rawResponse = await responsePromise.asResponse(); |
| 172 | expect(rawResponse).toBeInstanceOf(Response); |
| 173 | const response = await responsePromise; |
| 174 | expect(response).not.toBeInstanceOf(Response); |
| 175 | const dataAndResponse = await responsePromise.withResponse(); |
| 176 | expect(dataAndResponse.data).toBe(response); |
| 177 | expect(dataAndResponse.response).toBe(rawResponse); |
| 178 | }); |
| 179 | |
| 180 | test('list: required and optional params', async () => { |
| 181 | const response = await client.aiGateway.list({ |
| 182 | account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', |
| 183 | page: 1, |
| 184 | per_page: 1, |
| 185 | search: 'search', |
| 186 | }); |
| 187 | }); |
| 188 | |
| 189 | test('delete: only required params', async () => { |
| 190 | const responsePromise = client.aiGateway.delete('my-gateway', { |
| 191 | account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', |
| 192 | }); |
| 193 | const rawResponse = await responsePromise.asResponse(); |
| 194 | expect(rawResponse).toBeInstanceOf(Response); |
| 195 | const response = await responsePromise; |
| 196 | expect(response).not.toBeInstanceOf(Response); |
| 197 | const dataAndResponse = await responsePromise.withResponse(); |
| 198 | expect(dataAndResponse.data).toBe(response); |
| 199 | expect(dataAndResponse.response).toBe(rawResponse); |
| 200 | }); |
| 201 | |
| 202 | test('delete: required and optional params', async () => { |
| 203 | const response = await client.aiGateway.delete('my-gateway', { |
| 204 | account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', |
| 205 | }); |
| 206 | }); |
| 207 | |
| 208 | test('get: only required params', async () => { |
| 209 | const responsePromise = client.aiGateway.get('my-gateway', { |
| 210 | account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', |
| 211 | }); |
| 212 | const rawResponse = await responsePromise.asResponse(); |
| 213 | expect(rawResponse).toBeInstanceOf(Response); |
| 214 | const response = await responsePromise; |
| 215 | expect(response).not.toBeInstanceOf(Response); |
| 216 | const dataAndResponse = await responsePromise.withResponse(); |
| 217 | expect(dataAndResponse.data).toBe(response); |
| 218 | expect(dataAndResponse.response).toBe(rawResponse); |
| 219 | }); |
| 220 | |
| 221 | test('get: required and optional params', async () => { |
| 222 | const response = await client.aiGateway.get('my-gateway', { |
| 223 | account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', |
| 224 | }); |
| 225 | }); |
| 226 | }; |
| 227 | describe('resource aiGateway', () => runTests(client)); |
| 228 | describe('resource aiGateway (tree shakable, base)', () => runTests(partialClient)); |
| 229 | |