cloudflare/cloudflare-typescript
Publicmirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable
tests/api-resources/ai-gateway/ai-gateway.test.ts
135lines · modecode
| 1 | // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | |
| 3 | import Cloudflare from 'cloudflare'; |
| 4 | import { Response } from 'node-fetch'; |
| 5 | |
| 6 | const cloudflare = new Cloudflare({ |
| 7 | apiKey: '144c9defac04969c7bfad8efaa8ea194', |
| 8 | apiEmail: 'user@example.com', |
| 9 | baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', |
| 10 | }); |
| 11 | |
| 12 | describe('resource aiGateway', () => { |
| 13 | test('create: only required params', async () => { |
| 14 | const responsePromise = cloudflare.aiGateway.create({ |
| 15 | account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', |
| 16 | id: 'my-gateway', |
| 17 | cache_invalidate_on_update: true, |
| 18 | cache_ttl: 0, |
| 19 | collect_logs: true, |
| 20 | rate_limiting_interval: 0, |
| 21 | rate_limiting_limit: 0, |
| 22 | rate_limiting_technique: 'fixed', |
| 23 | }); |
| 24 | const rawResponse = await responsePromise.asResponse(); |
| 25 | expect(rawResponse).toBeInstanceOf(Response); |
| 26 | const response = await responsePromise; |
| 27 | expect(response).not.toBeInstanceOf(Response); |
| 28 | const dataAndResponse = await responsePromise.withResponse(); |
| 29 | expect(dataAndResponse.data).toBe(response); |
| 30 | expect(dataAndResponse.response).toBe(rawResponse); |
| 31 | }); |
| 32 | |
| 33 | test('create: required and optional params', async () => { |
| 34 | const response = await cloudflare.aiGateway.create({ |
| 35 | account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', |
| 36 | id: 'my-gateway', |
| 37 | cache_invalidate_on_update: true, |
| 38 | cache_ttl: 0, |
| 39 | collect_logs: true, |
| 40 | rate_limiting_interval: 0, |
| 41 | rate_limiting_limit: 0, |
| 42 | rate_limiting_technique: 'fixed', |
| 43 | }); |
| 44 | }); |
| 45 | |
| 46 | test('update: only required params', async () => { |
| 47 | const responsePromise = cloudflare.aiGateway.update('my-gateway', { |
| 48 | account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', |
| 49 | cache_invalidate_on_update: true, |
| 50 | cache_ttl: 0, |
| 51 | collect_logs: true, |
| 52 | rate_limiting_interval: 0, |
| 53 | rate_limiting_limit: 0, |
| 54 | rate_limiting_technique: 'fixed', |
| 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('update: required and optional params', async () => { |
| 66 | const response = await cloudflare.aiGateway.update('my-gateway', { |
| 67 | account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', |
| 68 | cache_invalidate_on_update: true, |
| 69 | cache_ttl: 0, |
| 70 | collect_logs: true, |
| 71 | rate_limiting_interval: 0, |
| 72 | rate_limiting_limit: 0, |
| 73 | rate_limiting_technique: 'fixed', |
| 74 | }); |
| 75 | }); |
| 76 | |
| 77 | test('list: only required params', async () => { |
| 78 | const responsePromise = cloudflare.aiGateway.list({ account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0' }); |
| 79 | const rawResponse = await responsePromise.asResponse(); |
| 80 | expect(rawResponse).toBeInstanceOf(Response); |
| 81 | const response = await responsePromise; |
| 82 | expect(response).not.toBeInstanceOf(Response); |
| 83 | const dataAndResponse = await responsePromise.withResponse(); |
| 84 | expect(dataAndResponse.data).toBe(response); |
| 85 | expect(dataAndResponse.response).toBe(rawResponse); |
| 86 | }); |
| 87 | |
| 88 | test('list: required and optional params', async () => { |
| 89 | const response = await cloudflare.aiGateway.list({ |
| 90 | account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', |
| 91 | id: 'my-gateway', |
| 92 | order_by: 'order_by', |
| 93 | page: 1, |
| 94 | per_page: 5, |
| 95 | }); |
| 96 | }); |
| 97 | |
| 98 | test('delete: only required params', async () => { |
| 99 | const responsePromise = cloudflare.aiGateway.delete('id', { |
| 100 | account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', |
| 101 | }); |
| 102 | const rawResponse = await responsePromise.asResponse(); |
| 103 | expect(rawResponse).toBeInstanceOf(Response); |
| 104 | const response = await responsePromise; |
| 105 | expect(response).not.toBeInstanceOf(Response); |
| 106 | const dataAndResponse = await responsePromise.withResponse(); |
| 107 | expect(dataAndResponse.data).toBe(response); |
| 108 | expect(dataAndResponse.response).toBe(rawResponse); |
| 109 | }); |
| 110 | |
| 111 | test('delete: required and optional params', async () => { |
| 112 | const response = await cloudflare.aiGateway.delete('id', { |
| 113 | account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', |
| 114 | }); |
| 115 | }); |
| 116 | |
| 117 | test('get: only required params', async () => { |
| 118 | const responsePromise = cloudflare.aiGateway.get('my-gateway', { |
| 119 | account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', |
| 120 | }); |
| 121 | const rawResponse = await responsePromise.asResponse(); |
| 122 | expect(rawResponse).toBeInstanceOf(Response); |
| 123 | const response = await responsePromise; |
| 124 | expect(response).not.toBeInstanceOf(Response); |
| 125 | const dataAndResponse = await responsePromise.withResponse(); |
| 126 | expect(dataAndResponse.data).toBe(response); |
| 127 | expect(dataAndResponse.response).toBe(rawResponse); |
| 128 | }); |
| 129 | |
| 130 | test('get: required and optional params', async () => { |
| 131 | const response = await cloudflare.aiGateway.get('my-gateway', { |
| 132 | account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', |
| 133 | }); |
| 134 | }); |
| 135 | }); |
| 136 | |