cloudflare/cloudflare-typescript

Public

mirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v6.4.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

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

173lines · modecode

1// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3import Cloudflare from 'cloudflare';
4import { Response } from 'node-fetch';
5
6const 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
12describe('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: [
34 {
35 key: 'id',
36 operator: 'eq',
37 value: ['string'],
38 },
39 ],
40 max_cost: 0,
41 max_duration: 0,
42 max_tokens_in: 0,
43 max_tokens_out: 0,
44 max_total_tokens: 0,
45 meta_info: true,
46 min_cost: 0,
47 min_duration: 0,
48 min_tokens_in: 0,
49 min_tokens_out: 0,
50 min_total_tokens: 0,
51 model: 'model',
52 model_type: 'model_type',
53 order_by: 'created_at',
54 order_by_direction: 'asc',
55 page: 1,
56 per_page: 1,
57 provider: 'provider',
58 request_content_type: 'request_content_type',
59 response_content_type: 'response_content_type',
60 search: 'search',
61 start_date: '2019-12-27T18:11:19.117Z',
62 success: true,
63 });
64 });
65
66 test('delete: only required params', async () => {
67 const responsePromise = client.aiGateway.logs.delete('my-gateway', {
68 account_id: '0d37909e38d3e99c29fa2cd343ac421a',
69 });
70 const rawResponse = await responsePromise.asResponse();
71 expect(rawResponse).toBeInstanceOf(Response);
72 const response = await responsePromise;
73 expect(response).not.toBeInstanceOf(Response);
74 const dataAndResponse = await responsePromise.withResponse();
75 expect(dataAndResponse.data).toBe(response);
76 expect(dataAndResponse.response).toBe(rawResponse);
77 });
78
79 test('delete: required and optional params', async () => {
80 const response = await client.aiGateway.logs.delete('my-gateway', {
81 account_id: '0d37909e38d3e99c29fa2cd343ac421a',
82 filters: [
83 {
84 key: 'id',
85 operator: 'eq',
86 value: ['string'],
87 },
88 ],
89 limit: 1,
90 order_by: 'created_at',
91 order_by_direction: 'asc',
92 });
93 });
94
95 test('edit: only required params', async () => {
96 const responsePromise = client.aiGateway.logs.edit('my-gateway', 'id', {
97 account_id: '0d37909e38d3e99c29fa2cd343ac421a',
98 });
99 const rawResponse = await responsePromise.asResponse();
100 expect(rawResponse).toBeInstanceOf(Response);
101 const response = await responsePromise;
102 expect(response).not.toBeInstanceOf(Response);
103 const dataAndResponse = await responsePromise.withResponse();
104 expect(dataAndResponse.data).toBe(response);
105 expect(dataAndResponse.response).toBe(rawResponse);
106 });
107
108 test('edit: required and optional params', async () => {
109 const response = await client.aiGateway.logs.edit('my-gateway', 'id', {
110 account_id: '0d37909e38d3e99c29fa2cd343ac421a',
111 feedback: -1,
112 metadata: { foo: 'string' },
113 score: 0,
114 });
115 });
116
117 test('get: only required params', async () => {
118 const responsePromise = client.aiGateway.logs.get('my-gateway', 'id', {
119 account_id: '0d37909e38d3e99c29fa2cd343ac421a',
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 client.aiGateway.logs.get('my-gateway', 'id', {
132 account_id: '0d37909e38d3e99c29fa2cd343ac421a',
133 });
134 });
135
136 test('request: only required params', async () => {
137 const responsePromise = client.aiGateway.logs.request('my-gateway', 'id', {
138 account_id: '0d37909e38d3e99c29fa2cd343ac421a',
139 });
140 const rawResponse = await responsePromise.asResponse();
141 expect(rawResponse).toBeInstanceOf(Response);
142 const response = await responsePromise;
143 expect(response).not.toBeInstanceOf(Response);
144 const dataAndResponse = await responsePromise.withResponse();
145 expect(dataAndResponse.data).toBe(response);
146 expect(dataAndResponse.response).toBe(rawResponse);
147 });
148
149 test('request: required and optional params', async () => {
150 const response = await client.aiGateway.logs.request('my-gateway', 'id', {
151 account_id: '0d37909e38d3e99c29fa2cd343ac421a',
152 });
153 });
154
155 test('response: only required params', async () => {
156 const responsePromise = client.aiGateway.logs.response('my-gateway', 'id', {
157 account_id: '0d37909e38d3e99c29fa2cd343ac421a',
158 });
159 const rawResponse = await responsePromise.asResponse();
160 expect(rawResponse).toBeInstanceOf(Response);
161 const response = await responsePromise;
162 expect(response).not.toBeInstanceOf(Response);
163 const dataAndResponse = await responsePromise.withResponse();
164 expect(dataAndResponse.data).toBe(response);
165 expect(dataAndResponse.response).toBe(rawResponse);
166 });
167
168 test('response: required and optional params', async () => {
169 const response = await client.aiGateway.logs.response('my-gateway', 'id', {
170 account_id: '0d37909e38d3e99c29fa2cd343ac421a',
171 });
172 });
173});
174