cloudflare/cloudflare-typescript
Publicmirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable
tests/api-resources/alerting/policies.test.ts
213lines · modecode
| 1 | // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | |
| 3 | import Cloudflare from 'cloudflare'; |
| 4 | import { Response } from 'node-fetch'; |
| 5 | |
| 6 | const cloudflare = 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 | |
| 12 | describe('resource policies', () => { |
| 13 | test('create: only required params', async () => { |
| 14 | const responsePromise = cloudflare.alerting.policies.create({ |
| 15 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 16 | alert_type: 'universal_ssl_event_type', |
| 17 | enabled: true, |
| 18 | mechanisms: { email: [{}], pagerduty: [{}], webhooks: [{}] }, |
| 19 | name: 'SSL Notification Event Policy', |
| 20 | }); |
| 21 | const rawResponse = await responsePromise.asResponse(); |
| 22 | expect(rawResponse).toBeInstanceOf(Response); |
| 23 | const response = await responsePromise; |
| 24 | expect(response).not.toBeInstanceOf(Response); |
| 25 | const dataAndResponse = await responsePromise.withResponse(); |
| 26 | expect(dataAndResponse.data).toBe(response); |
| 27 | expect(dataAndResponse.response).toBe(rawResponse); |
| 28 | }); |
| 29 | |
| 30 | test('create: required and optional params', async () => { |
| 31 | const response = await cloudflare.alerting.policies.create({ |
| 32 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 33 | alert_type: 'universal_ssl_event_type', |
| 34 | enabled: true, |
| 35 | mechanisms: { |
| 36 | email: [{ id: 'test@example.com' }], |
| 37 | pagerduty: [{ id: 'e8133a15-00a4-4d69-aec1-32f70c51f6e5' }], |
| 38 | webhooks: [{ id: '14cc1190-5d2b-4b98-a696-c424cb2ad05f' }], |
| 39 | }, |
| 40 | name: 'SSL Notification Event Policy', |
| 41 | description: 'Something describing the policy.', |
| 42 | filters: { |
| 43 | actions: ['string', 'string', 'string'], |
| 44 | affected_asns: ['string', 'string', 'string'], |
| 45 | affected_components: ['string', 'string', 'string'], |
| 46 | affected_locations: ['string', 'string', 'string'], |
| 47 | airport_code: ['string', 'string', 'string'], |
| 48 | alert_trigger_preferences: ['string', 'string', 'string'], |
| 49 | alert_trigger_preferences_value: ['99.0', '98.0', '97.0'], |
| 50 | enabled: ['string', 'string', 'string'], |
| 51 | environment: ['string', 'string', 'string'], |
| 52 | event: ['string', 'string', 'string'], |
| 53 | event_source: ['string', 'string', 'string'], |
| 54 | event_type: ['string', 'string', 'string'], |
| 55 | group_by: ['string', 'string', 'string'], |
| 56 | health_check_id: ['string', 'string', 'string'], |
| 57 | incident_impact: ['INCIDENT_IMPACT_NONE', 'INCIDENT_IMPACT_MINOR', 'INCIDENT_IMPACT_MAJOR'], |
| 58 | input_id: ['string', 'string', 'string'], |
| 59 | limit: ['string', 'string', 'string'], |
| 60 | logo_tag: ['string', 'string', 'string'], |
| 61 | megabits_per_second: ['string', 'string', 'string'], |
| 62 | new_health: ['string', 'string', 'string'], |
| 63 | new_status: ['string', 'string', 'string'], |
| 64 | packets_per_second: ['string', 'string', 'string'], |
| 65 | pool_id: ['string', 'string', 'string'], |
| 66 | product: ['string', 'string', 'string'], |
| 67 | project_id: ['string', 'string', 'string'], |
| 68 | protocol: ['string', 'string', 'string'], |
| 69 | query_tag: ['string', 'string', 'string'], |
| 70 | requests_per_second: ['string', 'string', 'string'], |
| 71 | selectors: ['string', 'string', 'string'], |
| 72 | services: ['string', 'string', 'string'], |
| 73 | slo: ['99.9'], |
| 74 | status: ['string', 'string', 'string'], |
| 75 | target_hostname: ['string', 'string', 'string'], |
| 76 | target_ip: ['string', 'string', 'string'], |
| 77 | target_zone_name: ['string', 'string', 'string'], |
| 78 | traffic_exclusions: ['security_events'], |
| 79 | tunnel_id: ['string', 'string', 'string'], |
| 80 | tunnel_name: ['string', 'string', 'string'], |
| 81 | where: ['string', 'string', 'string'], |
| 82 | zones: ['string', 'string', 'string'], |
| 83 | }, |
| 84 | }); |
| 85 | }); |
| 86 | |
| 87 | test('update: only required params', async () => { |
| 88 | const responsePromise = cloudflare.alerting.policies.update('0da2b59e-f118-439d-8097-bdfb215203c9', { |
| 89 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 90 | }); |
| 91 | const rawResponse = await responsePromise.asResponse(); |
| 92 | expect(rawResponse).toBeInstanceOf(Response); |
| 93 | const response = await responsePromise; |
| 94 | expect(response).not.toBeInstanceOf(Response); |
| 95 | const dataAndResponse = await responsePromise.withResponse(); |
| 96 | expect(dataAndResponse.data).toBe(response); |
| 97 | expect(dataAndResponse.response).toBe(rawResponse); |
| 98 | }); |
| 99 | |
| 100 | test('update: required and optional params', async () => { |
| 101 | const response = await cloudflare.alerting.policies.update('0da2b59e-f118-439d-8097-bdfb215203c9', { |
| 102 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 103 | alert_type: 'universal_ssl_event_type', |
| 104 | description: 'Something describing the policy.', |
| 105 | enabled: true, |
| 106 | filters: { |
| 107 | actions: ['string', 'string', 'string'], |
| 108 | affected_asns: ['string', 'string', 'string'], |
| 109 | affected_components: ['string', 'string', 'string'], |
| 110 | affected_locations: ['string', 'string', 'string'], |
| 111 | airport_code: ['string', 'string', 'string'], |
| 112 | alert_trigger_preferences: ['string', 'string', 'string'], |
| 113 | alert_trigger_preferences_value: ['99.0', '98.0', '97.0'], |
| 114 | enabled: ['string', 'string', 'string'], |
| 115 | environment: ['string', 'string', 'string'], |
| 116 | event: ['string', 'string', 'string'], |
| 117 | event_source: ['string', 'string', 'string'], |
| 118 | event_type: ['string', 'string', 'string'], |
| 119 | group_by: ['string', 'string', 'string'], |
| 120 | health_check_id: ['string', 'string', 'string'], |
| 121 | incident_impact: ['INCIDENT_IMPACT_NONE', 'INCIDENT_IMPACT_MINOR', 'INCIDENT_IMPACT_MAJOR'], |
| 122 | input_id: ['string', 'string', 'string'], |
| 123 | limit: ['string', 'string', 'string'], |
| 124 | logo_tag: ['string', 'string', 'string'], |
| 125 | megabits_per_second: ['string', 'string', 'string'], |
| 126 | new_health: ['string', 'string', 'string'], |
| 127 | new_status: ['string', 'string', 'string'], |
| 128 | packets_per_second: ['string', 'string', 'string'], |
| 129 | pool_id: ['string', 'string', 'string'], |
| 130 | product: ['string', 'string', 'string'], |
| 131 | project_id: ['string', 'string', 'string'], |
| 132 | protocol: ['string', 'string', 'string'], |
| 133 | query_tag: ['string', 'string', 'string'], |
| 134 | requests_per_second: ['string', 'string', 'string'], |
| 135 | selectors: ['string', 'string', 'string'], |
| 136 | services: ['string', 'string', 'string'], |
| 137 | slo: ['99.9'], |
| 138 | status: ['string', 'string', 'string'], |
| 139 | target_hostname: ['string', 'string', 'string'], |
| 140 | target_ip: ['string', 'string', 'string'], |
| 141 | target_zone_name: ['string', 'string', 'string'], |
| 142 | traffic_exclusions: ['security_events'], |
| 143 | tunnel_id: ['string', 'string', 'string'], |
| 144 | tunnel_name: ['string', 'string', 'string'], |
| 145 | where: ['string', 'string', 'string'], |
| 146 | zones: ['string', 'string', 'string'], |
| 147 | }, |
| 148 | mechanisms: { |
| 149 | email: [{ id: 'test@example.com' }], |
| 150 | pagerduty: [{ id: 'e8133a15-00a4-4d69-aec1-32f70c51f6e5' }], |
| 151 | webhooks: [{ id: '14cc1190-5d2b-4b98-a696-c424cb2ad05f' }], |
| 152 | }, |
| 153 | name: 'SSL Notification Event Policy', |
| 154 | }); |
| 155 | }); |
| 156 | |
| 157 | test('list: only required params', async () => { |
| 158 | const responsePromise = cloudflare.alerting.policies.list({ |
| 159 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 160 | }); |
| 161 | const rawResponse = await responsePromise.asResponse(); |
| 162 | expect(rawResponse).toBeInstanceOf(Response); |
| 163 | const response = await responsePromise; |
| 164 | expect(response).not.toBeInstanceOf(Response); |
| 165 | const dataAndResponse = await responsePromise.withResponse(); |
| 166 | expect(dataAndResponse.data).toBe(response); |
| 167 | expect(dataAndResponse.response).toBe(rawResponse); |
| 168 | }); |
| 169 | |
| 170 | test('list: required and optional params', async () => { |
| 171 | const response = await cloudflare.alerting.policies.list({ |
| 172 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 173 | }); |
| 174 | }); |
| 175 | |
| 176 | test('delete: only required params', async () => { |
| 177 | const responsePromise = cloudflare.alerting.policies.delete('0da2b59e-f118-439d-8097-bdfb215203c9', { |
| 178 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 179 | }); |
| 180 | const rawResponse = await responsePromise.asResponse(); |
| 181 | expect(rawResponse).toBeInstanceOf(Response); |
| 182 | const response = await responsePromise; |
| 183 | expect(response).not.toBeInstanceOf(Response); |
| 184 | const dataAndResponse = await responsePromise.withResponse(); |
| 185 | expect(dataAndResponse.data).toBe(response); |
| 186 | expect(dataAndResponse.response).toBe(rawResponse); |
| 187 | }); |
| 188 | |
| 189 | test('delete: required and optional params', async () => { |
| 190 | const response = await cloudflare.alerting.policies.delete('0da2b59e-f118-439d-8097-bdfb215203c9', { |
| 191 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 192 | }); |
| 193 | }); |
| 194 | |
| 195 | test('get: only required params', async () => { |
| 196 | const responsePromise = cloudflare.alerting.policies.get('0da2b59e-f118-439d-8097-bdfb215203c9', { |
| 197 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 198 | }); |
| 199 | const rawResponse = await responsePromise.asResponse(); |
| 200 | expect(rawResponse).toBeInstanceOf(Response); |
| 201 | const response = await responsePromise; |
| 202 | expect(response).not.toBeInstanceOf(Response); |
| 203 | const dataAndResponse = await responsePromise.withResponse(); |
| 204 | expect(dataAndResponse.data).toBe(response); |
| 205 | expect(dataAndResponse.response).toBe(rawResponse); |
| 206 | }); |
| 207 | |
| 208 | test('get: required and optional params', async () => { |
| 209 | const response = await cloudflare.alerting.policies.get('0da2b59e-f118-439d-8097-bdfb215203c9', { |
| 210 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 211 | }); |
| 212 | }); |
| 213 | }); |
| 214 | |