cloudflare/cloudflare-typescript
Publicmirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable
tests/api-resources/accounts/roles.test.ts
50lines · 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 roles', () => { |
| 13 | test('list: only required params', async () => { |
| 14 | const responsePromise = client.accounts.roles.list({ account_id: 'eb78d65290b24279ba6f44721b3ea3c4' }); |
| 15 | const rawResponse = await responsePromise.asResponse(); |
| 16 | expect(rawResponse).toBeInstanceOf(Response); |
| 17 | const response = await responsePromise; |
| 18 | expect(response).not.toBeInstanceOf(Response); |
| 19 | const dataAndResponse = await responsePromise.withResponse(); |
| 20 | expect(dataAndResponse.data).toBe(response); |
| 21 | expect(dataAndResponse.response).toBe(rawResponse); |
| 22 | }); |
| 23 | |
| 24 | test('list: required and optional params', async () => { |
| 25 | const response = await client.accounts.roles.list({ |
| 26 | account_id: 'eb78d65290b24279ba6f44721b3ea3c4', |
| 27 | page: 1, |
| 28 | per_page: 5, |
| 29 | }); |
| 30 | }); |
| 31 | |
| 32 | test('get: only required params', async () => { |
| 33 | const responsePromise = client.accounts.roles.get('3536bcfad5faccb999b47003c79917fb', { |
| 34 | account_id: 'eb78d65290b24279ba6f44721b3ea3c4', |
| 35 | }); |
| 36 | const rawResponse = await responsePromise.asResponse(); |
| 37 | expect(rawResponse).toBeInstanceOf(Response); |
| 38 | const response = await responsePromise; |
| 39 | expect(response).not.toBeInstanceOf(Response); |
| 40 | const dataAndResponse = await responsePromise.withResponse(); |
| 41 | expect(dataAndResponse.data).toBe(response); |
| 42 | expect(dataAndResponse.response).toBe(rawResponse); |
| 43 | }); |
| 44 | |
| 45 | test('get: required and optional params', async () => { |
| 46 | const response = await client.accounts.roles.get('3536bcfad5faccb999b47003c79917fb', { |
| 47 | account_id: 'eb78d65290b24279ba6f44721b3ea3c4', |
| 48 | }); |
| 49 | }); |
| 50 | }); |
| 51 | |