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/alerting/policies.test.ts

243lines · modecode

1// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3import { Alerting } from 'cloudflare/resources/alerting/alerting';
4import { BasePolicies } from 'cloudflare/resources/alerting/policies';
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: [BasePolicies],
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: [Alerting],
27});
28
29const runTests = (client: PartialCloudflare<{ alerting: { policies: BasePolicies } }>) => {
30 // prism errors - https://github.com/cloudflare/cloudflare-python/actions/runs/9327225061/job/25676826349?pr=482#step:5:4274
31 test.skip('create: only required params', async () => {
32 const responsePromise = client.alerting.policies.create({
33 account_id: '023e105f4ecef8ad9ca31a8372d0c353',
34 alert_type: 'universal_ssl_event_type',
35 enabled: true,
36 mechanisms: {},
37 name: 'SSL Notification Event Policy',
38 });
39 const rawResponse = await responsePromise.asResponse();
40 expect(rawResponse).toBeInstanceOf(Response);
41 const response = await responsePromise;
42 expect(response).not.toBeInstanceOf(Response);
43 const dataAndResponse = await responsePromise.withResponse();
44 expect(dataAndResponse.data).toBe(response);
45 expect(dataAndResponse.response).toBe(rawResponse);
46 });
47
48 // prism errors - https://github.com/cloudflare/cloudflare-python/actions/runs/9327225061/job/25676826349?pr=482#step:5:4274
49 test.skip('create: required and optional params', async () => {
50 const response = await client.alerting.policies.create({
51 account_id: '023e105f4ecef8ad9ca31a8372d0c353',
52 alert_type: 'universal_ssl_event_type',
53 enabled: true,
54 mechanisms: {
55 email: [{ id: 'id' }],
56 pagerduty: [{ id: 'f174e90afafe4643bbbc4a0ed4fc8415' }],
57 webhooks: [{ id: 'f174e90afafe4643bbbc4a0ed4fc8415' }],
58 },
59 name: 'SSL Notification Event Policy',
60 alert_interval: '30m',
61 description: 'Something describing the policy.',
62 filters: {
63 actions: ['string'],
64 affected_asns: ['string'],
65 affected_components: ['string'],
66 affected_locations: ['string'],
67 airport_code: ['string'],
68 alert_trigger_preferences: ['string'],
69 alert_trigger_preferences_value: ['string'],
70 enabled: ['string'],
71 environment: ['string'],
72 event: ['string'],
73 event_source: ['string'],
74 event_type: ['string'],
75 group_by: ['string'],
76 health_check_id: ['string'],
77 incident_impact: ['INCIDENT_IMPACT_NONE'],
78 input_id: ['string'],
79 insight_class: ['string'],
80 limit: ['string'],
81 logo_tag: ['string'],
82 megabits_per_second: ['string'],
83 new_health: ['string'],
84 new_status: ['string'],
85 packets_per_second: ['string'],
86 pool_id: ['string'],
87 pop_names: ['string'],
88 product: ['string'],
89 project_id: ['string'],
90 protocol: ['string'],
91 query_tag: ['string'],
92 requests_per_second: ['string'],
93 selectors: ['string'],
94 services: ['string'],
95 slo: ['99.9'],
96 status: ['string'],
97 target_hostname: ['string'],
98 target_ip: ['string'],
99 target_zone_name: ['string'],
100 traffic_exclusions: ['security_events'],
101 tunnel_id: ['string'],
102 tunnel_name: ['string'],
103 type: ['string'],
104 where: ['string'],
105 zones: ['string'],
106 },
107 });
108 });
109
110 // prism errors - https://github.com/cloudflare/cloudflare-python/actions/runs/9327225061/job/25676826349?pr=482#step:5:4274
111 test.skip('update: only required params', async () => {
112 const responsePromise = client.alerting.policies.update('0da2b59ef118439d8097bdfb215203c9', {
113 account_id: '023e105f4ecef8ad9ca31a8372d0c353',
114 });
115 const rawResponse = await responsePromise.asResponse();
116 expect(rawResponse).toBeInstanceOf(Response);
117 const response = await responsePromise;
118 expect(response).not.toBeInstanceOf(Response);
119 const dataAndResponse = await responsePromise.withResponse();
120 expect(dataAndResponse.data).toBe(response);
121 expect(dataAndResponse.response).toBe(rawResponse);
122 });
123
124 // prism errors - https://github.com/cloudflare/cloudflare-python/actions/runs/9327225061/job/25676826349?pr=482#step:5:4274
125 test.skip('update: required and optional params', async () => {
126 const response = await client.alerting.policies.update('0da2b59ef118439d8097bdfb215203c9', {
127 account_id: '023e105f4ecef8ad9ca31a8372d0c353',
128 alert_interval: '30m',
129 alert_type: 'universal_ssl_event_type',
130 description: 'Something describing the policy.',
131 enabled: true,
132 filters: {
133 actions: ['string'],
134 affected_asns: ['string'],
135 affected_components: ['string'],
136 affected_locations: ['string'],
137 airport_code: ['string'],
138 alert_trigger_preferences: ['string'],
139 alert_trigger_preferences_value: ['string'],
140 enabled: ['string'],
141 environment: ['string'],
142 event: ['string'],
143 event_source: ['string'],
144 event_type: ['string'],
145 group_by: ['string'],
146 health_check_id: ['string'],
147 incident_impact: ['INCIDENT_IMPACT_NONE'],
148 input_id: ['string'],
149 insight_class: ['string'],
150 limit: ['string'],
151 logo_tag: ['string'],
152 megabits_per_second: ['string'],
153 new_health: ['string'],
154 new_status: ['string'],
155 packets_per_second: ['string'],
156 pool_id: ['string'],
157 pop_names: ['string'],
158 product: ['string'],
159 project_id: ['string'],
160 protocol: ['string'],
161 query_tag: ['string'],
162 requests_per_second: ['string'],
163 selectors: ['string'],
164 services: ['string'],
165 slo: ['99.9'],
166 status: ['string'],
167 target_hostname: ['string'],
168 target_ip: ['string'],
169 target_zone_name: ['string'],
170 traffic_exclusions: ['security_events'],
171 tunnel_id: ['string'],
172 tunnel_name: ['string'],
173 type: ['string'],
174 where: ['string'],
175 zones: ['string'],
176 },
177 mechanisms: {
178 email: [{ id: 'id' }],
179 pagerduty: [{ id: 'f174e90afafe4643bbbc4a0ed4fc8415' }],
180 webhooks: [{ id: 'f174e90afafe4643bbbc4a0ed4fc8415' }],
181 },
182 name: 'SSL Notification Event Policy',
183 });
184 });
185
186 test('list: only required params', async () => {
187 const responsePromise = client.alerting.policies.list({ account_id: '023e105f4ecef8ad9ca31a8372d0c353' });
188 const rawResponse = await responsePromise.asResponse();
189 expect(rawResponse).toBeInstanceOf(Response);
190 const response = await responsePromise;
191 expect(response).not.toBeInstanceOf(Response);
192 const dataAndResponse = await responsePromise.withResponse();
193 expect(dataAndResponse.data).toBe(response);
194 expect(dataAndResponse.response).toBe(rawResponse);
195 });
196
197 test('list: required and optional params', async () => {
198 const response = await client.alerting.policies.list({ account_id: '023e105f4ecef8ad9ca31a8372d0c353' });
199 });
200
201 test('delete: only required params', async () => {
202 const responsePromise = client.alerting.policies.delete('0da2b59ef118439d8097bdfb215203c9', {
203 account_id: '023e105f4ecef8ad9ca31a8372d0c353',
204 });
205 const rawResponse = await responsePromise.asResponse();
206 expect(rawResponse).toBeInstanceOf(Response);
207 const response = await responsePromise;
208 expect(response).not.toBeInstanceOf(Response);
209 const dataAndResponse = await responsePromise.withResponse();
210 expect(dataAndResponse.data).toBe(response);
211 expect(dataAndResponse.response).toBe(rawResponse);
212 });
213
214 test('delete: required and optional params', async () => {
215 const response = await client.alerting.policies.delete('0da2b59ef118439d8097bdfb215203c9', {
216 account_id: '023e105f4ecef8ad9ca31a8372d0c353',
217 });
218 });
219
220 // prism errors - https://github.com/cloudflare/cloudflare-python/actions/runs/9327225061/job/25676826349?pr=482#step:5:4274
221 test.skip('get: only required params', async () => {
222 const responsePromise = client.alerting.policies.get('0da2b59ef118439d8097bdfb215203c9', {
223 account_id: '023e105f4ecef8ad9ca31a8372d0c353',
224 });
225 const rawResponse = await responsePromise.asResponse();
226 expect(rawResponse).toBeInstanceOf(Response);
227 const response = await responsePromise;
228 expect(response).not.toBeInstanceOf(Response);
229 const dataAndResponse = await responsePromise.withResponse();
230 expect(dataAndResponse.data).toBe(response);
231 expect(dataAndResponse.response).toBe(rawResponse);
232 });
233
234 // prism errors - https://github.com/cloudflare/cloudflare-python/actions/runs/9327225061/job/25676826349?pr=482#step:5:4274
235 test.skip('get: required and optional params', async () => {
236 const response = await client.alerting.policies.get('0da2b59ef118439d8097bdfb215203c9', {
237 account_id: '023e105f4ecef8ad9ca31a8372d0c353',
238 });
239 });
240};
241describe('resource policies', () => runTests(client));
242describe('resource policies (tree shakable, base)', () => runTests(partialClient));
243describe('resource policies (tree shakable, subresource)', () => runTests(parentPartialClient));
244