cloudflare/cloudflare-typescript
Publicmirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable
tests/api-resources/access/keys.test.ts
75lines · 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 keys', () => { |
| 15 | // skipped: tests are disabled for the time being |
| 16 | test.skip('list', async () => { |
| 17 | const responsePromise = cloudflare.access.keys.list('023e105f4ecef8ad9ca31a8372d0c353'); |
| 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 | // skipped: tests are disabled for the time being |
| 28 | test.skip('list: request options instead of params are passed correctly', async () => { |
| 29 | // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error |
| 30 | await expect( |
| 31 | cloudflare.access.keys.list('023e105f4ecef8ad9ca31a8372d0c353', { path: '/_stainless_unknown_path' }), |
| 32 | ).rejects.toThrow(Cloudflare.NotFoundError); |
| 33 | }); |
| 34 | |
| 35 | // skipped: tests are disabled for the time being |
| 36 | test.skip('replace: only required params', async () => { |
| 37 | const responsePromise = cloudflare.access.keys.replace('023e105f4ecef8ad9ca31a8372d0c353', { |
| 38 | key_rotation_interval_days: 30, |
| 39 | }); |
| 40 | const rawResponse = await responsePromise.asResponse(); |
| 41 | expect(rawResponse).toBeInstanceOf(Response); |
| 42 | const response = await responsePromise; |
| 43 | expect(response).not.toBeInstanceOf(Response); |
| 44 | const dataAndResponse = await responsePromise.withResponse(); |
| 45 | expect(dataAndResponse.data).toBe(response); |
| 46 | expect(dataAndResponse.response).toBe(rawResponse); |
| 47 | }); |
| 48 | |
| 49 | // skipped: tests are disabled for the time being |
| 50 | test.skip('replace: required and optional params', async () => { |
| 51 | const response = await cloudflare.access.keys.replace('023e105f4ecef8ad9ca31a8372d0c353', { |
| 52 | key_rotation_interval_days: 30, |
| 53 | }); |
| 54 | }); |
| 55 | |
| 56 | // skipped: tests are disabled for the time being |
| 57 | test.skip('rotate', async () => { |
| 58 | const responsePromise = cloudflare.access.keys.rotate('023e105f4ecef8ad9ca31a8372d0c353'); |
| 59 | const rawResponse = await responsePromise.asResponse(); |
| 60 | expect(rawResponse).toBeInstanceOf(Response); |
| 61 | const response = await responsePromise; |
| 62 | expect(response).not.toBeInstanceOf(Response); |
| 63 | const dataAndResponse = await responsePromise.withResponse(); |
| 64 | expect(dataAndResponse.data).toBe(response); |
| 65 | expect(dataAndResponse.response).toBe(rawResponse); |
| 66 | }); |
| 67 | |
| 68 | // skipped: tests are disabled for the time being |
| 69 | test.skip('rotate: request options instead of params are passed correctly', async () => { |
| 70 | // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error |
| 71 | await expect( |
| 72 | cloudflare.access.keys.rotate('023e105f4ecef8ad9ca31a8372d0c353', { path: '/_stainless_unknown_path' }), |
| 73 | ).rejects.toThrow(Cloudflare.NotFoundError); |
| 74 | }); |
| 75 | }); |
| 76 | |