cloudflare/cloudflare-typescript
Publicmirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable
tests/api-resources/ai-gateway/dynamic-routing.test.ts
276lines · 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 { BaseDynamicRouting } from 'cloudflare/resources/ai-gateway/dynamic-routing'; |
| 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: [BaseDynamicRouting], |
| 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: { dynamicRouting: BaseDynamicRouting } }>) => { |
| 30 | test('create: only required params', async () => { |
| 31 | const responsePromise = client.aiGateway.dynamicRouting.create('54442216', { |
| 32 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 33 | elements: [ |
| 34 | { |
| 35 | id: 'id', |
| 36 | outputs: { next: { elementId: 'elementId' } }, |
| 37 | type: 'start', |
| 38 | }, |
| 39 | ], |
| 40 | name: 'name', |
| 41 | }); |
| 42 | const rawResponse = await responsePromise.asResponse(); |
| 43 | expect(rawResponse).toBeInstanceOf(Response); |
| 44 | const response = await responsePromise; |
| 45 | expect(response).not.toBeInstanceOf(Response); |
| 46 | const dataAndResponse = await responsePromise.withResponse(); |
| 47 | expect(dataAndResponse.data).toBe(response); |
| 48 | expect(dataAndResponse.response).toBe(rawResponse); |
| 49 | }); |
| 50 | |
| 51 | test('create: required and optional params', async () => { |
| 52 | const response = await client.aiGateway.dynamicRouting.create('54442216', { |
| 53 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 54 | elements: [ |
| 55 | { |
| 56 | id: 'id', |
| 57 | outputs: { next: { elementId: 'elementId' } }, |
| 58 | type: 'start', |
| 59 | }, |
| 60 | ], |
| 61 | name: 'name', |
| 62 | }); |
| 63 | }); |
| 64 | |
| 65 | test('update: only required params', async () => { |
| 66 | const responsePromise = client.aiGateway.dynamicRouting.update('54442216', { |
| 67 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 68 | gateway_id: '54442216', |
| 69 | name: 'Route Name', |
| 70 | }); |
| 71 | const rawResponse = await responsePromise.asResponse(); |
| 72 | expect(rawResponse).toBeInstanceOf(Response); |
| 73 | const response = await responsePromise; |
| 74 | expect(response).not.toBeInstanceOf(Response); |
| 75 | const dataAndResponse = await responsePromise.withResponse(); |
| 76 | expect(dataAndResponse.data).toBe(response); |
| 77 | expect(dataAndResponse.response).toBe(rawResponse); |
| 78 | }); |
| 79 | |
| 80 | test('update: required and optional params', async () => { |
| 81 | const response = await client.aiGateway.dynamicRouting.update('54442216', { |
| 82 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 83 | gateway_id: '54442216', |
| 84 | name: 'Route Name', |
| 85 | }); |
| 86 | }); |
| 87 | |
| 88 | test('list: only required params', async () => { |
| 89 | const responsePromise = client.aiGateway.dynamicRouting.list('54442216', { |
| 90 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 91 | }); |
| 92 | const rawResponse = await responsePromise.asResponse(); |
| 93 | expect(rawResponse).toBeInstanceOf(Response); |
| 94 | const response = await responsePromise; |
| 95 | expect(response).not.toBeInstanceOf(Response); |
| 96 | const dataAndResponse = await responsePromise.withResponse(); |
| 97 | expect(dataAndResponse.data).toBe(response); |
| 98 | expect(dataAndResponse.response).toBe(rawResponse); |
| 99 | }); |
| 100 | |
| 101 | test('list: required and optional params', async () => { |
| 102 | const response = await client.aiGateway.dynamicRouting.list('54442216', { |
| 103 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 104 | page: 1, |
| 105 | per_page: 20, |
| 106 | }); |
| 107 | }); |
| 108 | |
| 109 | test('delete: only required params', async () => { |
| 110 | const responsePromise = client.aiGateway.dynamicRouting.delete('54442216', { |
| 111 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 112 | gateway_id: '54442216', |
| 113 | }); |
| 114 | const rawResponse = await responsePromise.asResponse(); |
| 115 | expect(rawResponse).toBeInstanceOf(Response); |
| 116 | const response = await responsePromise; |
| 117 | expect(response).not.toBeInstanceOf(Response); |
| 118 | const dataAndResponse = await responsePromise.withResponse(); |
| 119 | expect(dataAndResponse.data).toBe(response); |
| 120 | expect(dataAndResponse.response).toBe(rawResponse); |
| 121 | }); |
| 122 | |
| 123 | test('delete: required and optional params', async () => { |
| 124 | const response = await client.aiGateway.dynamicRouting.delete('54442216', { |
| 125 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 126 | gateway_id: '54442216', |
| 127 | }); |
| 128 | }); |
| 129 | |
| 130 | test('createDeployment: only required params', async () => { |
| 131 | const responsePromise = client.aiGateway.dynamicRouting.createDeployment('54442216', { |
| 132 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 133 | gateway_id: '54442216', |
| 134 | version_id: '54442216', |
| 135 | }); |
| 136 | const rawResponse = await responsePromise.asResponse(); |
| 137 | expect(rawResponse).toBeInstanceOf(Response); |
| 138 | const response = await responsePromise; |
| 139 | expect(response).not.toBeInstanceOf(Response); |
| 140 | const dataAndResponse = await responsePromise.withResponse(); |
| 141 | expect(dataAndResponse.data).toBe(response); |
| 142 | expect(dataAndResponse.response).toBe(rawResponse); |
| 143 | }); |
| 144 | |
| 145 | test('createDeployment: required and optional params', async () => { |
| 146 | const response = await client.aiGateway.dynamicRouting.createDeployment('54442216', { |
| 147 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 148 | gateway_id: '54442216', |
| 149 | version_id: '54442216', |
| 150 | }); |
| 151 | }); |
| 152 | |
| 153 | test('createVersion: only required params', async () => { |
| 154 | const responsePromise = client.aiGateway.dynamicRouting.createVersion('54442216', { |
| 155 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 156 | gateway_id: '54442216', |
| 157 | elements: [ |
| 158 | { |
| 159 | id: 'id', |
| 160 | outputs: { next: { elementId: 'elementId' } }, |
| 161 | type: 'start', |
| 162 | }, |
| 163 | ], |
| 164 | }); |
| 165 | const rawResponse = await responsePromise.asResponse(); |
| 166 | expect(rawResponse).toBeInstanceOf(Response); |
| 167 | const response = await responsePromise; |
| 168 | expect(response).not.toBeInstanceOf(Response); |
| 169 | const dataAndResponse = await responsePromise.withResponse(); |
| 170 | expect(dataAndResponse.data).toBe(response); |
| 171 | expect(dataAndResponse.response).toBe(rawResponse); |
| 172 | }); |
| 173 | |
| 174 | test('createVersion: required and optional params', async () => { |
| 175 | const response = await client.aiGateway.dynamicRouting.createVersion('54442216', { |
| 176 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 177 | gateway_id: '54442216', |
| 178 | elements: [ |
| 179 | { |
| 180 | id: 'id', |
| 181 | outputs: { next: { elementId: 'elementId' } }, |
| 182 | type: 'start', |
| 183 | }, |
| 184 | ], |
| 185 | }); |
| 186 | }); |
| 187 | |
| 188 | test('get: only required params', async () => { |
| 189 | const responsePromise = client.aiGateway.dynamicRouting.get('54442216', { |
| 190 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 191 | gateway_id: '54442216', |
| 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('get: required and optional params', async () => { |
| 203 | const response = await client.aiGateway.dynamicRouting.get('54442216', { |
| 204 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 205 | gateway_id: '54442216', |
| 206 | }); |
| 207 | }); |
| 208 | |
| 209 | test('getVersion: only required params', async () => { |
| 210 | const responsePromise = client.aiGateway.dynamicRouting.getVersion('54442216', { |
| 211 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 212 | gateway_id: '54442216', |
| 213 | id: '54442216', |
| 214 | }); |
| 215 | const rawResponse = await responsePromise.asResponse(); |
| 216 | expect(rawResponse).toBeInstanceOf(Response); |
| 217 | const response = await responsePromise; |
| 218 | expect(response).not.toBeInstanceOf(Response); |
| 219 | const dataAndResponse = await responsePromise.withResponse(); |
| 220 | expect(dataAndResponse.data).toBe(response); |
| 221 | expect(dataAndResponse.response).toBe(rawResponse); |
| 222 | }); |
| 223 | |
| 224 | test('getVersion: required and optional params', async () => { |
| 225 | const response = await client.aiGateway.dynamicRouting.getVersion('54442216', { |
| 226 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 227 | gateway_id: '54442216', |
| 228 | id: '54442216', |
| 229 | }); |
| 230 | }); |
| 231 | |
| 232 | test('listDeployments: only required params', async () => { |
| 233 | const responsePromise = client.aiGateway.dynamicRouting.listDeployments('54442216', { |
| 234 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 235 | gateway_id: '54442216', |
| 236 | }); |
| 237 | const rawResponse = await responsePromise.asResponse(); |
| 238 | expect(rawResponse).toBeInstanceOf(Response); |
| 239 | const response = await responsePromise; |
| 240 | expect(response).not.toBeInstanceOf(Response); |
| 241 | const dataAndResponse = await responsePromise.withResponse(); |
| 242 | expect(dataAndResponse.data).toBe(response); |
| 243 | expect(dataAndResponse.response).toBe(rawResponse); |
| 244 | }); |
| 245 | |
| 246 | test('listDeployments: required and optional params', async () => { |
| 247 | const response = await client.aiGateway.dynamicRouting.listDeployments('54442216', { |
| 248 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 249 | gateway_id: '54442216', |
| 250 | }); |
| 251 | }); |
| 252 | |
| 253 | test('listVersions: only required params', async () => { |
| 254 | const responsePromise = client.aiGateway.dynamicRouting.listVersions('54442216', { |
| 255 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 256 | gateway_id: '54442216', |
| 257 | }); |
| 258 | const rawResponse = await responsePromise.asResponse(); |
| 259 | expect(rawResponse).toBeInstanceOf(Response); |
| 260 | const response = await responsePromise; |
| 261 | expect(response).not.toBeInstanceOf(Response); |
| 262 | const dataAndResponse = await responsePromise.withResponse(); |
| 263 | expect(dataAndResponse.data).toBe(response); |
| 264 | expect(dataAndResponse.response).toBe(rawResponse); |
| 265 | }); |
| 266 | |
| 267 | test('listVersions: required and optional params', async () => { |
| 268 | const response = await client.aiGateway.dynamicRouting.listVersions('54442216', { |
| 269 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 270 | gateway_id: '54442216', |
| 271 | }); |
| 272 | }); |
| 273 | }; |
| 274 | describe('resource dynamicRouting', () => runTests(client)); |
| 275 | describe('resource dynamicRouting (tree shakable, base)', () => runTests(partialClient)); |
| 276 | describe('resource dynamicRouting (tree shakable, subresource)', () => runTests(parentPartialClient)); |
| 277 | |