cloudflare/cloudflare-typescript
Publicmirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable
tests/api-resources/alerting/silences.test.ts
119lines · 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 silences', () => { |
| 13 | test('create: only required params', async () => { |
| 14 | const responsePromise = client.alerting.silences.create({ |
| 15 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 16 | body: [{}], |
| 17 | }); |
| 18 | const rawResponse = await responsePromise.asResponse(); |
| 19 | expect(rawResponse).toBeInstanceOf(Response); |
| 20 | const response = await responsePromise; |
| 21 | expect(response).not.toBeInstanceOf(Response); |
| 22 | const dataAndResponse = await responsePromise.withResponse(); |
| 23 | expect(dataAndResponse.data).toBe(response); |
| 24 | expect(dataAndResponse.response).toBe(rawResponse); |
| 25 | }); |
| 26 | |
| 27 | test('create: required and optional params', async () => { |
| 28 | const response = await client.alerting.silences.create({ |
| 29 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 30 | body: [ |
| 31 | { |
| 32 | end_time: '2022-01-01T00:00:00Z', |
| 33 | policy_id: '0da2b59ef118439d8097bdfb215203c9', |
| 34 | start_time: '2022-01-01T00:00:00Z', |
| 35 | }, |
| 36 | ], |
| 37 | }); |
| 38 | }); |
| 39 | |
| 40 | test('update: only required params', async () => { |
| 41 | const responsePromise = client.alerting.silences.update({ |
| 42 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 43 | body: [{}], |
| 44 | }); |
| 45 | const rawResponse = await responsePromise.asResponse(); |
| 46 | expect(rawResponse).toBeInstanceOf(Response); |
| 47 | const response = await responsePromise; |
| 48 | expect(response).not.toBeInstanceOf(Response); |
| 49 | const dataAndResponse = await responsePromise.withResponse(); |
| 50 | expect(dataAndResponse.data).toBe(response); |
| 51 | expect(dataAndResponse.response).toBe(rawResponse); |
| 52 | }); |
| 53 | |
| 54 | test('update: required and optional params', async () => { |
| 55 | const response = await client.alerting.silences.update({ |
| 56 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 57 | body: [ |
| 58 | { |
| 59 | id: 'f878e90c23f44126ae3cfc399f646977', |
| 60 | end_time: '2022-01-01T00:00:00Z', |
| 61 | start_time: '2022-01-01T00:00:00Z', |
| 62 | }, |
| 63 | ], |
| 64 | }); |
| 65 | }); |
| 66 | |
| 67 | test('list: only required params', async () => { |
| 68 | const responsePromise = client.alerting.silences.list({ account_id: '023e105f4ecef8ad9ca31a8372d0c353' }); |
| 69 | const rawResponse = await responsePromise.asResponse(); |
| 70 | expect(rawResponse).toBeInstanceOf(Response); |
| 71 | const response = await responsePromise; |
| 72 | expect(response).not.toBeInstanceOf(Response); |
| 73 | const dataAndResponse = await responsePromise.withResponse(); |
| 74 | expect(dataAndResponse.data).toBe(response); |
| 75 | expect(dataAndResponse.response).toBe(rawResponse); |
| 76 | }); |
| 77 | |
| 78 | test('list: required and optional params', async () => { |
| 79 | const response = await client.alerting.silences.list({ account_id: '023e105f4ecef8ad9ca31a8372d0c353' }); |
| 80 | }); |
| 81 | |
| 82 | test('delete: only required params', async () => { |
| 83 | const responsePromise = client.alerting.silences.delete('f878e90c23f44126ae3cfc399f646977', { |
| 84 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 85 | }); |
| 86 | const rawResponse = await responsePromise.asResponse(); |
| 87 | expect(rawResponse).toBeInstanceOf(Response); |
| 88 | const response = await responsePromise; |
| 89 | expect(response).not.toBeInstanceOf(Response); |
| 90 | const dataAndResponse = await responsePromise.withResponse(); |
| 91 | expect(dataAndResponse.data).toBe(response); |
| 92 | expect(dataAndResponse.response).toBe(rawResponse); |
| 93 | }); |
| 94 | |
| 95 | test('delete: required and optional params', async () => { |
| 96 | const response = await client.alerting.silences.delete('f878e90c23f44126ae3cfc399f646977', { |
| 97 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 98 | }); |
| 99 | }); |
| 100 | |
| 101 | test('get: only required params', async () => { |
| 102 | const responsePromise = client.alerting.silences.get('f878e90c23f44126ae3cfc399f646977', { |
| 103 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 104 | }); |
| 105 | const rawResponse = await responsePromise.asResponse(); |
| 106 | expect(rawResponse).toBeInstanceOf(Response); |
| 107 | const response = await responsePromise; |
| 108 | expect(response).not.toBeInstanceOf(Response); |
| 109 | const dataAndResponse = await responsePromise.withResponse(); |
| 110 | expect(dataAndResponse.data).toBe(response); |
| 111 | expect(dataAndResponse.response).toBe(rawResponse); |
| 112 | }); |
| 113 | |
| 114 | test('get: required and optional params', async () => { |
| 115 | const response = await client.alerting.silences.get('f878e90c23f44126ae3cfc399f646977', { |
| 116 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 117 | }); |
| 118 | }); |
| 119 | }); |
| 120 | |