cloudflare/cloudflare-typescript

Public

mirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v7

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

tests/api-resources/ai-gateway/logs.test.ts

201lines · modecode

1// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3import { AIGateway } from 'cloudflare/resources/ai-gateway/ai-gateway';
4import { BaseLogs } from 'cloudflare/resources/ai-gateway/logs';
5
6import Cloudflare from 'cloudflare';
7import { createClient, type PartialCloudflare } from 'cloudflare/tree-shakable';
8
9const 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
15const 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: [BaseLogs],
20});
21
22const 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
29const runTests = (client: PartialCloudflare<{ aiGateway: { logs: BaseLogs } }>) => {
30 test('list: only required params', async () => {
31 const responsePromise = client.aiGateway.logs.list('my-gateway', {
32 account_id: '0d37909e38d3e99c29fa2cd343ac421a',
33 });
34 const rawResponse = await responsePromise.asResponse();
35 expect(rawResponse).toBeInstanceOf(Response);
36 const response = await responsePromise;
37 expect(response).not.toBeInstanceOf(Response);
38 const dataAndResponse = await responsePromise.withResponse();
39 expect(dataAndResponse.data).toBe(response);
40 expect(dataAndResponse.response).toBe(rawResponse);
41 });
42
43 test('list: required and optional params', async () => {
44 const response = await client.aiGateway.logs.list('my-gateway', {
45 account_id: '0d37909e38d3e99c29fa2cd343ac421a',
46 cached: true,
47 direction: 'asc',
48 end_date: '2019-12-27T18:11:19.117Z',
49 feedback: 0,
50 filters: [
51 {
52 key: 'id',
53 operator: 'eq',
54 value: ['string'],
55 },
56 ],
57 max_cost: 0,
58 max_duration: 0,
59 max_tokens_in: 0,
60 max_tokens_out: 0,
61 max_total_tokens: 0,
62 meta_info: true,
63 min_cost: 0,
64 min_duration: 0,
65 min_tokens_in: 0,
66 min_tokens_out: 0,
67 min_total_tokens: 0,
68 model: 'model',
69 model_type: 'model_type',
70 order_by: 'created_at',
71 order_by_direction: 'asc',
72 page: 1,
73 per_page: 1,
74 provider: 'provider',
75 request_content_type: 'request_content_type',
76 response_content_type: 'response_content_type',
77 search: 'search',
78 start_date: '2019-12-27T18:11:19.117Z',
79 success: true,
80 });
81 });
82
83 test('delete: only required params', async () => {
84 const responsePromise = client.aiGateway.logs.delete('my-gateway', {
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('delete: required and optional params', async () => {
97 const response = await client.aiGateway.logs.delete('my-gateway', {
98 account_id: '0d37909e38d3e99c29fa2cd343ac421a',
99 filters: [
100 {
101 key: 'id',
102 operator: 'eq',
103 value: ['string'],
104 },
105 ],
106 limit: 1,
107 order_by: 'created_at',
108 order_by_direction: 'asc',
109 });
110 });
111
112 test('edit: only required params', async () => {
113 const responsePromise = client.aiGateway.logs.edit('id', {
114 account_id: '0d37909e38d3e99c29fa2cd343ac421a',
115 gateway_id: 'my-gateway',
116 });
117 const rawResponse = await responsePromise.asResponse();
118 expect(rawResponse).toBeInstanceOf(Response);
119 const response = await responsePromise;
120 expect(response).not.toBeInstanceOf(Response);
121 const dataAndResponse = await responsePromise.withResponse();
122 expect(dataAndResponse.data).toBe(response);
123 expect(dataAndResponse.response).toBe(rawResponse);
124 });
125
126 test('edit: required and optional params', async () => {
127 const response = await client.aiGateway.logs.edit('id', {
128 account_id: '0d37909e38d3e99c29fa2cd343ac421a',
129 gateway_id: 'my-gateway',
130 feedback: -1,
131 metadata: { foo: 'string' },
132 score: 0,
133 });
134 });
135
136 test('get: only required params', async () => {
137 const responsePromise = client.aiGateway.logs.get('id', {
138 account_id: '0d37909e38d3e99c29fa2cd343ac421a',
139 gateway_id: 'my-gateway',
140 });
141 const rawResponse = await responsePromise.asResponse();
142 expect(rawResponse).toBeInstanceOf(Response);
143 const response = await responsePromise;
144 expect(response).not.toBeInstanceOf(Response);
145 const dataAndResponse = await responsePromise.withResponse();
146 expect(dataAndResponse.data).toBe(response);
147 expect(dataAndResponse.response).toBe(rawResponse);
148 });
149
150 test('get: required and optional params', async () => {
151 const response = await client.aiGateway.logs.get('id', {
152 account_id: '0d37909e38d3e99c29fa2cd343ac421a',
153 gateway_id: 'my-gateway',
154 });
155 });
156
157 test('request: only required params', async () => {
158 const responsePromise = client.aiGateway.logs.request('id', {
159 account_id: '0d37909e38d3e99c29fa2cd343ac421a',
160 gateway_id: 'my-gateway',
161 });
162 const rawResponse = await responsePromise.asResponse();
163 expect(rawResponse).toBeInstanceOf(Response);
164 const response = await responsePromise;
165 expect(response).not.toBeInstanceOf(Response);
166 const dataAndResponse = await responsePromise.withResponse();
167 expect(dataAndResponse.data).toBe(response);
168 expect(dataAndResponse.response).toBe(rawResponse);
169 });
170
171 test('request: required and optional params', async () => {
172 const response = await client.aiGateway.logs.request('id', {
173 account_id: '0d37909e38d3e99c29fa2cd343ac421a',
174 gateway_id: 'my-gateway',
175 });
176 });
177
178 test('response: only required params', async () => {
179 const responsePromise = client.aiGateway.logs.response('id', {
180 account_id: '0d37909e38d3e99c29fa2cd343ac421a',
181 gateway_id: 'my-gateway',
182 });
183 const rawResponse = await responsePromise.asResponse();
184 expect(rawResponse).toBeInstanceOf(Response);
185 const response = await responsePromise;
186 expect(response).not.toBeInstanceOf(Response);
187 const dataAndResponse = await responsePromise.withResponse();
188 expect(dataAndResponse.data).toBe(response);
189 expect(dataAndResponse.response).toBe(rawResponse);
190 });
191
192 test('response: required and optional params', async () => {
193 const response = await client.aiGateway.logs.response('id', {
194 account_id: '0d37909e38d3e99c29fa2cd343ac421a',
195 gateway_id: 'my-gateway',
196 });
197 });
198};
199describe('resource logs', () => runTests(client));
200describe('resource logs (tree shakable, base)', () => runTests(partialClient));
201describe('resource logs (tree shakable, subresource)', () => runTests(parentPartialClient));
202