cloudflare/cloudflare-typescript

Public

mirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v7

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

tests/api-resources/accounts/roles.test.ts

70lines · modecode

1// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3import { Accounts } from 'cloudflare/resources/accounts/accounts';
4import { BaseRoles } from 'cloudflare/resources/accounts/roles';
5
6import Cloudflare from 'cloudflare';
7import { createClient, type PartialCloudflare } from 'cloudflare/tree-shakable';
8
9const client = new Cloudflare({
10 apiKey: '144c9defac04969c7bfad8efaa8ea194',
11 apiEmail: 'user@example.com',
12 baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
13});
14
15const partialClient = createClient({
16 apiKey: '144c9defac04969c7bfad8efaa8ea194',
17 apiEmail: 'user@example.com',
18 baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
19 resources: [BaseRoles],
20});
21
22const parentPartialClient = createClient({
23 apiKey: '144c9defac04969c7bfad8efaa8ea194',
24 apiEmail: 'user@example.com',
25 baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
26 resources: [Accounts],
27});
28
29const runTests = (client: PartialCloudflare<{ accounts: { roles: BaseRoles } }>) => {
30 test('list: only required params', async () => {
31 const responsePromise = client.accounts.roles.list({ account_id: '023e105f4ecef8ad9ca31a8372d0c353' });
32 const rawResponse = await responsePromise.asResponse();
33 expect(rawResponse).toBeInstanceOf(Response);
34 const response = await responsePromise;
35 expect(response).not.toBeInstanceOf(Response);
36 const dataAndResponse = await responsePromise.withResponse();
37 expect(dataAndResponse.data).toBe(response);
38 expect(dataAndResponse.response).toBe(rawResponse);
39 });
40
41 test('list: required and optional params', async () => {
42 const response = await client.accounts.roles.list({
43 account_id: '023e105f4ecef8ad9ca31a8372d0c353',
44 page: 1,
45 per_page: 5,
46 });
47 });
48
49 test('get: only required params', async () => {
50 const responsePromise = client.accounts.roles.get('3536bcfad5faccb999b47003c79917fb', {
51 account_id: '023e105f4ecef8ad9ca31a8372d0c353',
52 });
53 const rawResponse = await responsePromise.asResponse();
54 expect(rawResponse).toBeInstanceOf(Response);
55 const response = await responsePromise;
56 expect(response).not.toBeInstanceOf(Response);
57 const dataAndResponse = await responsePromise.withResponse();
58 expect(dataAndResponse.data).toBe(response);
59 expect(dataAndResponse.response).toBe(rawResponse);
60 });
61
62 test('get: required and optional params', async () => {
63 const response = await client.accounts.roles.get('3536bcfad5faccb999b47003c79917fb', {
64 account_id: '023e105f4ecef8ad9ca31a8372d0c353',
65 });
66 });
67};
68describe('resource roles', () => runTests(client));
69describe('resource roles (tree shakable, base)', () => runTests(partialClient));
70describe('resource roles (tree shakable, subresource)', () => runTests(parentPartialClient));
71