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