cloudflare/cloudflare-typescript
Publicmirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable
tests/api-resources/ai-gateway/logs.test.ts
161lines · 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 client = 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 logs', () => { |
| 13 | test('list: only required params', async () => { |
| 14 | const responsePromise = client.aiGateway.logs.list('my-gateway', { |
| 15 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 16 | }); |
| 17 | const rawResponse = await responsePromise.asResponse(); |
| 18 | expect(rawResponse).toBeInstanceOf(Response); |
| 19 | const response = await responsePromise; |
| 20 | expect(response).not.toBeInstanceOf(Response); |
| 21 | const dataAndResponse = await responsePromise.withResponse(); |
| 22 | expect(dataAndResponse.data).toBe(response); |
| 23 | expect(dataAndResponse.response).toBe(rawResponse); |
| 24 | }); |
| 25 | |
| 26 | test('list: required and optional params', async () => { |
| 27 | const response = await client.aiGateway.logs.list('my-gateway', { |
| 28 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 29 | cached: true, |
| 30 | direction: 'asc', |
| 31 | end_date: '2019-12-27T18:11:19.117Z', |
| 32 | feedback: 0, |
| 33 | filters: [{ key: 'id', operator: 'eq', value: ['string'] }], |
| 34 | max_cost: 0, |
| 35 | max_duration: 0, |
| 36 | max_tokens_in: 0, |
| 37 | max_tokens_out: 0, |
| 38 | max_total_tokens: 0, |
| 39 | meta_info: true, |
| 40 | min_cost: 0, |
| 41 | min_duration: 0, |
| 42 | min_tokens_in: 0, |
| 43 | min_tokens_out: 0, |
| 44 | min_total_tokens: 0, |
| 45 | model: 'model', |
| 46 | model_type: 'model_type', |
| 47 | order_by: 'created_at', |
| 48 | order_by_direction: 'asc', |
| 49 | page: 1, |
| 50 | per_page: 1, |
| 51 | provider: 'provider', |
| 52 | request_content_type: 'request_content_type', |
| 53 | response_content_type: 'response_content_type', |
| 54 | search: 'search', |
| 55 | start_date: '2019-12-27T18:11:19.117Z', |
| 56 | success: true, |
| 57 | }); |
| 58 | }); |
| 59 | |
| 60 | test('delete: only required params', async () => { |
| 61 | const responsePromise = client.aiGateway.logs.delete('my-gateway', { |
| 62 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 63 | }); |
| 64 | const rawResponse = await responsePromise.asResponse(); |
| 65 | expect(rawResponse).toBeInstanceOf(Response); |
| 66 | const response = await responsePromise; |
| 67 | expect(response).not.toBeInstanceOf(Response); |
| 68 | const dataAndResponse = await responsePromise.withResponse(); |
| 69 | expect(dataAndResponse.data).toBe(response); |
| 70 | expect(dataAndResponse.response).toBe(rawResponse); |
| 71 | }); |
| 72 | |
| 73 | test('delete: required and optional params', async () => { |
| 74 | const response = await client.aiGateway.logs.delete('my-gateway', { |
| 75 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 76 | filters: [{ key: 'id', operator: 'eq', value: ['string'] }], |
| 77 | limit: 1, |
| 78 | order_by: 'created_at', |
| 79 | order_by_direction: 'asc', |
| 80 | }); |
| 81 | }); |
| 82 | |
| 83 | test('edit: only required params', async () => { |
| 84 | const responsePromise = client.aiGateway.logs.edit('my-gateway', 'id', { |
| 85 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 86 | }); |
| 87 | const rawResponse = await responsePromise.asResponse(); |
| 88 | expect(rawResponse).toBeInstanceOf(Response); |
| 89 | const response = await responsePromise; |
| 90 | expect(response).not.toBeInstanceOf(Response); |
| 91 | const dataAndResponse = await responsePromise.withResponse(); |
| 92 | expect(dataAndResponse.data).toBe(response); |
| 93 | expect(dataAndResponse.response).toBe(rawResponse); |
| 94 | }); |
| 95 | |
| 96 | test('edit: required and optional params', async () => { |
| 97 | const response = await client.aiGateway.logs.edit('my-gateway', 'id', { |
| 98 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 99 | feedback: -1, |
| 100 | metadata: { foo: 'string' }, |
| 101 | score: 0, |
| 102 | }); |
| 103 | }); |
| 104 | |
| 105 | test('get: only required params', async () => { |
| 106 | const responsePromise = client.aiGateway.logs.get('my-gateway', 'id', { |
| 107 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 108 | }); |
| 109 | const rawResponse = await responsePromise.asResponse(); |
| 110 | expect(rawResponse).toBeInstanceOf(Response); |
| 111 | const response = await responsePromise; |
| 112 | expect(response).not.toBeInstanceOf(Response); |
| 113 | const dataAndResponse = await responsePromise.withResponse(); |
| 114 | expect(dataAndResponse.data).toBe(response); |
| 115 | expect(dataAndResponse.response).toBe(rawResponse); |
| 116 | }); |
| 117 | |
| 118 | test('get: required and optional params', async () => { |
| 119 | const response = await client.aiGateway.logs.get('my-gateway', 'id', { |
| 120 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 121 | }); |
| 122 | }); |
| 123 | |
| 124 | test('request: only required params', async () => { |
| 125 | const responsePromise = client.aiGateway.logs.request('my-gateway', 'id', { |
| 126 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 127 | }); |
| 128 | const rawResponse = await responsePromise.asResponse(); |
| 129 | expect(rawResponse).toBeInstanceOf(Response); |
| 130 | const response = await responsePromise; |
| 131 | expect(response).not.toBeInstanceOf(Response); |
| 132 | const dataAndResponse = await responsePromise.withResponse(); |
| 133 | expect(dataAndResponse.data).toBe(response); |
| 134 | expect(dataAndResponse.response).toBe(rawResponse); |
| 135 | }); |
| 136 | |
| 137 | test('request: required and optional params', async () => { |
| 138 | const response = await client.aiGateway.logs.request('my-gateway', 'id', { |
| 139 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 140 | }); |
| 141 | }); |
| 142 | |
| 143 | test('response: only required params', async () => { |
| 144 | const responsePromise = client.aiGateway.logs.response('my-gateway', 'id', { |
| 145 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 146 | }); |
| 147 | const rawResponse = await responsePromise.asResponse(); |
| 148 | expect(rawResponse).toBeInstanceOf(Response); |
| 149 | const response = await responsePromise; |
| 150 | expect(response).not.toBeInstanceOf(Response); |
| 151 | const dataAndResponse = await responsePromise.withResponse(); |
| 152 | expect(dataAndResponse.data).toBe(response); |
| 153 | expect(dataAndResponse.response).toBe(rawResponse); |
| 154 | }); |
| 155 | |
| 156 | test('response: required and optional params', async () => { |
| 157 | const response = await client.aiGateway.logs.response('my-gateway', 'id', { |
| 158 | account_id: '0d37909e38d3e99c29fa2cd343ac421a', |
| 159 | }); |
| 160 | }); |
| 161 | }); |
| 162 | |