cloudflare/cloudflare-typescript

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
06559e345dee6f4ace074eaacd2b66089e08b9b4

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api-resources/challenges/widgets.test.ts

184lines · modecode

1// File generated from our OpenAPI spec by Stainless.
2
3import Cloudflare from 'cloudflare';
4import { Response } from 'node-fetch';
5
6const cloudflare = new Cloudflare({
7 apiKey: '144c9defac04969c7bfad8efaa8ea194',
8 apiEmail: 'user@example.com',
9 apiToken: 'Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY',
10 userServiceKey:
11 'v1.0-144c9defac04969c7bfad8ef-631a41d003a32d25fe878081ef365c49503f7fada600da935e2851a1c7326084b85cbf6429c4b859de8475731dc92a9c329631e6d59e6c73da7b198497172b4cefe071d90d0f5d2719',
12 baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
13});
14
15describe('resource widgets', () => {
16 // skipped: tests are disabled for the time being
17 test.skip('create: only required params', async () => {
18 const responsePromise = cloudflare.challenges.widgets.create('023e105f4ecef8ad9ca31a8372d0c353', {
19 domains: ['203.0.113.1', 'cloudflare.com', 'blog.example.com'],
20 mode: 'invisible',
21 name: 'blog.cloudflare.com login form',
22 });
23 const rawResponse = await responsePromise.asResponse();
24 expect(rawResponse).toBeInstanceOf(Response);
25 const response = await responsePromise;
26 expect(response).not.toBeInstanceOf(Response);
27 const dataAndResponse = await responsePromise.withResponse();
28 expect(dataAndResponse.data).toBe(response);
29 expect(dataAndResponse.response).toBe(rawResponse);
30 });
31
32 // skipped: tests are disabled for the time being
33 test.skip('create: required and optional params', async () => {
34 const response = await cloudflare.challenges.widgets.create('023e105f4ecef8ad9ca31a8372d0c353', {
35 domains: ['203.0.113.1', 'cloudflare.com', 'blog.example.com'],
36 mode: 'invisible',
37 name: 'blog.cloudflare.com login form',
38 direction: 'asc',
39 order: 'id',
40 page: 1,
41 per_page: 5,
42 bot_fight_mode: true,
43 clearance_level: 'interactive',
44 offlabel: true,
45 region: 'world',
46 });
47 });
48
49 // skipped: tests are disabled for the time being
50 test.skip('update: only required params', async () => {
51 const responsePromise = cloudflare.challenges.widgets.update(
52 '023e105f4ecef8ad9ca31a8372d0c353',
53 '0x4AAF00AAAABn0R22HWm-YUc',
54 {
55 domains: ['203.0.113.1', 'cloudflare.com', 'blog.example.com'],
56 mode: 'invisible',
57 name: 'blog.cloudflare.com login form',
58 },
59 );
60 const rawResponse = await responsePromise.asResponse();
61 expect(rawResponse).toBeInstanceOf(Response);
62 const response = await responsePromise;
63 expect(response).not.toBeInstanceOf(Response);
64 const dataAndResponse = await responsePromise.withResponse();
65 expect(dataAndResponse.data).toBe(response);
66 expect(dataAndResponse.response).toBe(rawResponse);
67 });
68
69 // skipped: tests are disabled for the time being
70 test.skip('update: required and optional params', async () => {
71 const response = await cloudflare.challenges.widgets.update(
72 '023e105f4ecef8ad9ca31a8372d0c353',
73 '0x4AAF00AAAABn0R22HWm-YUc',
74 {
75 domains: ['203.0.113.1', 'cloudflare.com', 'blog.example.com'],
76 mode: 'invisible',
77 name: 'blog.cloudflare.com login form',
78 bot_fight_mode: true,
79 clearance_level: 'interactive',
80 offlabel: true,
81 },
82 );
83 });
84
85 // skipped: tests are disabled for the time being
86 test.skip('list', async () => {
87 const responsePromise = cloudflare.challenges.widgets.list('023e105f4ecef8ad9ca31a8372d0c353');
88 const rawResponse = await responsePromise.asResponse();
89 expect(rawResponse).toBeInstanceOf(Response);
90 const response = await responsePromise;
91 expect(response).not.toBeInstanceOf(Response);
92 const dataAndResponse = await responsePromise.withResponse();
93 expect(dataAndResponse.data).toBe(response);
94 expect(dataAndResponse.response).toBe(rawResponse);
95 });
96
97 // skipped: tests are disabled for the time being
98 test.skip('list: request options instead of params are passed correctly', async () => {
99 // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
100 await expect(
101 cloudflare.challenges.widgets.list('023e105f4ecef8ad9ca31a8372d0c353', {
102 path: '/_stainless_unknown_path',
103 }),
104 ).rejects.toThrow(Cloudflare.NotFoundError);
105 });
106
107 // skipped: tests are disabled for the time being
108 test.skip('list: request options and params are passed correctly', async () => {
109 // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
110 await expect(
111 cloudflare.challenges.widgets.list(
112 '023e105f4ecef8ad9ca31a8372d0c353',
113 { direction: 'asc', order: 'id', page: 1, per_page: 5 },
114 { path: '/_stainless_unknown_path' },
115 ),
116 ).rejects.toThrow(Cloudflare.NotFoundError);
117 });
118
119 // skipped: tests are disabled for the time being
120 test.skip('delete', async () => {
121 const responsePromise = cloudflare.challenges.widgets.delete(
122 '023e105f4ecef8ad9ca31a8372d0c353',
123 '0x4AAF00AAAABn0R22HWm-YUc',
124 );
125 const rawResponse = await responsePromise.asResponse();
126 expect(rawResponse).toBeInstanceOf(Response);
127 const response = await responsePromise;
128 expect(response).not.toBeInstanceOf(Response);
129 const dataAndResponse = await responsePromise.withResponse();
130 expect(dataAndResponse.data).toBe(response);
131 expect(dataAndResponse.response).toBe(rawResponse);
132 });
133
134 // skipped: tests are disabled for the time being
135 test.skip('delete: request options instead of params are passed correctly', async () => {
136 // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
137 await expect(
138 cloudflare.challenges.widgets.delete('023e105f4ecef8ad9ca31a8372d0c353', '0x4AAF00AAAABn0R22HWm-YUc', {
139 path: '/_stainless_unknown_path',
140 }),
141 ).rejects.toThrow(Cloudflare.NotFoundError);
142 });
143
144 // skipped: tests are disabled for the time being
145 test.skip('get', async () => {
146 const responsePromise = cloudflare.challenges.widgets.get(
147 '023e105f4ecef8ad9ca31a8372d0c353',
148 '0x4AAF00AAAABn0R22HWm-YUc',
149 );
150 const rawResponse = await responsePromise.asResponse();
151 expect(rawResponse).toBeInstanceOf(Response);
152 const response = await responsePromise;
153 expect(response).not.toBeInstanceOf(Response);
154 const dataAndResponse = await responsePromise.withResponse();
155 expect(dataAndResponse.data).toBe(response);
156 expect(dataAndResponse.response).toBe(rawResponse);
157 });
158
159 // skipped: tests are disabled for the time being
160 test.skip('get: request options instead of params are passed correctly', async () => {
161 // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
162 await expect(
163 cloudflare.challenges.widgets.get('023e105f4ecef8ad9ca31a8372d0c353', '0x4AAF00AAAABn0R22HWm-YUc', {
164 path: '/_stainless_unknown_path',
165 }),
166 ).rejects.toThrow(Cloudflare.NotFoundError);
167 });
168
169 // skipped: tests are disabled for the time being
170 test.skip('rotateSecret', async () => {
171 const responsePromise = cloudflare.challenges.widgets.rotateSecret(
172 '023e105f4ecef8ad9ca31a8372d0c353',
173 '0x4AAF00AAAABn0R22HWm-YUc',
174 {},
175 );
176 const rawResponse = await responsePromise.asResponse();
177 expect(rawResponse).toBeInstanceOf(Response);
178 const response = await responsePromise;
179 expect(response).not.toBeInstanceOf(Response);
180 const dataAndResponse = await responsePromise.withResponse();
181 expect(dataAndResponse.data).toBe(response);
182 expect(dataAndResponse.response).toBe(rawResponse);
183 });
184});