cloudflare/cloudflare-typescript

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v6.3.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api-resources/aisearch/tokens.test.ts

122lines · 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 tokens', () => {
13 test('create: only required params', async () => {
14 const responsePromise = client.aiSearch.tokens.create({
15 account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22',
16 cf_api_id: 'a1b2c3d4e5f6',
17 cf_api_key: 'abc123',
18 name: 'my-token',
19 });
20 const rawResponse = await responsePromise.asResponse();
21 expect(rawResponse).toBeInstanceOf(Response);
22 const response = await responsePromise;
23 expect(response).not.toBeInstanceOf(Response);
24 const dataAndResponse = await responsePromise.withResponse();
25 expect(dataAndResponse.data).toBe(response);
26 expect(dataAndResponse.response).toBe(rawResponse);
27 });
28
29 test('create: required and optional params', async () => {
30 const response = await client.aiSearch.tokens.create({
31 account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22',
32 cf_api_id: 'a1b2c3d4e5f6',
33 cf_api_key: 'abc123',
34 name: 'my-token',
35 legacy: true,
36 });
37 });
38
39 test('update: only required params', async () => {
40 const responsePromise = client.aiSearch.tokens.update('62af0db3-c410-40b2-9ee3-0e93f6dd1de0', {
41 account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22',
42 cf_api_id: 'a1b2c3d4e5f6',
43 cf_api_key: 'abc123',
44 name: 'my-token',
45 });
46 const rawResponse = await responsePromise.asResponse();
47 expect(rawResponse).toBeInstanceOf(Response);
48 const response = await responsePromise;
49 expect(response).not.toBeInstanceOf(Response);
50 const dataAndResponse = await responsePromise.withResponse();
51 expect(dataAndResponse.data).toBe(response);
52 expect(dataAndResponse.response).toBe(rawResponse);
53 });
54
55 test('update: required and optional params', async () => {
56 const response = await client.aiSearch.tokens.update('62af0db3-c410-40b2-9ee3-0e93f6dd1de0', {
57 account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22',
58 cf_api_id: 'a1b2c3d4e5f6',
59 cf_api_key: 'abc123',
60 name: 'my-token',
61 legacy: true,
62 });
63 });
64
65 test('list: only required params', async () => {
66 const responsePromise = client.aiSearch.tokens.list({ account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22' });
67 const rawResponse = await responsePromise.asResponse();
68 expect(rawResponse).toBeInstanceOf(Response);
69 const response = await responsePromise;
70 expect(response).not.toBeInstanceOf(Response);
71 const dataAndResponse = await responsePromise.withResponse();
72 expect(dataAndResponse.data).toBe(response);
73 expect(dataAndResponse.response).toBe(rawResponse);
74 });
75
76 test('list: required and optional params', async () => {
77 const response = await client.aiSearch.tokens.list({
78 account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22',
79 page: 1,
80 per_page: 20,
81 search: 'my-token',
82 });
83 });
84
85 test('delete: only required params', async () => {
86 const responsePromise = client.aiSearch.tokens.delete('62af0db3-c410-40b2-9ee3-0e93f6dd1de0', {
87 account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22',
88 });
89 const rawResponse = await responsePromise.asResponse();
90 expect(rawResponse).toBeInstanceOf(Response);
91 const response = await responsePromise;
92 expect(response).not.toBeInstanceOf(Response);
93 const dataAndResponse = await responsePromise.withResponse();
94 expect(dataAndResponse.data).toBe(response);
95 expect(dataAndResponse.response).toBe(rawResponse);
96 });
97
98 test('delete: required and optional params', async () => {
99 const response = await client.aiSearch.tokens.delete('62af0db3-c410-40b2-9ee3-0e93f6dd1de0', {
100 account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22',
101 });
102 });
103
104 test('read: only required params', async () => {
105 const responsePromise = client.aiSearch.tokens.read('62af0db3-c410-40b2-9ee3-0e93f6dd1de0', {
106 account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22',
107 });
108 const rawResponse = await responsePromise.asResponse();
109 expect(rawResponse).toBeInstanceOf(Response);
110 const response = await responsePromise;
111 expect(response).not.toBeInstanceOf(Response);
112 const dataAndResponse = await responsePromise.withResponse();
113 expect(dataAndResponse.data).toBe(response);
114 expect(dataAndResponse.response).toBe(rawResponse);
115 });
116
117 test('read: required and optional params', async () => {
118 const response = await client.aiSearch.tokens.read('62af0db3-c410-40b2-9ee3-0e93f6dd1de0', {
119 account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22',
120 });
121 });
122});
123