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