cloudflare/cloudflare-typescript
Publicmirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable
tests/api-resources/ai-gateway/evaluations.test.ts
123lines · 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 { BaseEvaluations } from 'cloudflare/resources/ai-gateway/evaluations'; |
| 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: [BaseEvaluations], |
| 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: { evaluations: BaseEvaluations } }>) => { |
| 30 | test('create: only required params', async () => { |
| 31 | const responsePromise = client.aiGateway.evaluations.create('my-gateway', { |
| 32 | account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', |
| 33 | dataset_ids: ['string'], |
| 34 | evaluation_type_ids: ['string'], |
| 35 | name: 'name', |
| 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.evaluations.create('my-gateway', { |
| 48 | account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', |
| 49 | dataset_ids: ['string'], |
| 50 | evaluation_type_ids: ['string'], |
| 51 | name: 'name', |
| 52 | }); |
| 53 | }); |
| 54 | |
| 55 | test('list: only required params', async () => { |
| 56 | const responsePromise = client.aiGateway.evaluations.list('my-gateway', { |
| 57 | account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', |
| 58 | }); |
| 59 | const rawResponse = await responsePromise.asResponse(); |
| 60 | expect(rawResponse).toBeInstanceOf(Response); |
| 61 | const response = await responsePromise; |
| 62 | expect(response).not.toBeInstanceOf(Response); |
| 63 | const dataAndResponse = await responsePromise.withResponse(); |
| 64 | expect(dataAndResponse.data).toBe(response); |
| 65 | expect(dataAndResponse.response).toBe(rawResponse); |
| 66 | }); |
| 67 | |
| 68 | test('list: required and optional params', async () => { |
| 69 | const response = await client.aiGateway.evaluations.list('my-gateway', { |
| 70 | account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', |
| 71 | name: 'name', |
| 72 | page: 1, |
| 73 | per_page: 1, |
| 74 | processed: true, |
| 75 | search: 'search', |
| 76 | }); |
| 77 | }); |
| 78 | |
| 79 | test('delete: only required params', async () => { |
| 80 | const responsePromise = client.aiGateway.evaluations.delete('id', { |
| 81 | account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', |
| 82 | gateway_id: 'my-gateway', |
| 83 | }); |
| 84 | const rawResponse = await responsePromise.asResponse(); |
| 85 | expect(rawResponse).toBeInstanceOf(Response); |
| 86 | const response = await responsePromise; |
| 87 | expect(response).not.toBeInstanceOf(Response); |
| 88 | const dataAndResponse = await responsePromise.withResponse(); |
| 89 | expect(dataAndResponse.data).toBe(response); |
| 90 | expect(dataAndResponse.response).toBe(rawResponse); |
| 91 | }); |
| 92 | |
| 93 | test('delete: required and optional params', async () => { |
| 94 | const response = await client.aiGateway.evaluations.delete('id', { |
| 95 | account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', |
| 96 | gateway_id: 'my-gateway', |
| 97 | }); |
| 98 | }); |
| 99 | |
| 100 | test('get: only required params', async () => { |
| 101 | const responsePromise = client.aiGateway.evaluations.get('id', { |
| 102 | account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', |
| 103 | gateway_id: 'my-gateway', |
| 104 | }); |
| 105 | const rawResponse = await responsePromise.asResponse(); |
| 106 | expect(rawResponse).toBeInstanceOf(Response); |
| 107 | const response = await responsePromise; |
| 108 | expect(response).not.toBeInstanceOf(Response); |
| 109 | const dataAndResponse = await responsePromise.withResponse(); |
| 110 | expect(dataAndResponse.data).toBe(response); |
| 111 | expect(dataAndResponse.response).toBe(rawResponse); |
| 112 | }); |
| 113 | |
| 114 | test('get: required and optional params', async () => { |
| 115 | const response = await client.aiGateway.evaluations.get('id', { |
| 116 | account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', |
| 117 | gateway_id: 'my-gateway', |
| 118 | }); |
| 119 | }); |
| 120 | }; |
| 121 | describe('resource evaluations', () => runTests(client)); |
| 122 | describe('resource evaluations (tree shakable, base)', () => runTests(partialClient)); |
| 123 | describe('resource evaluations (tree shakable, subresource)', () => runTests(parentPartialClient)); |
| 124 | |