cloudflare/cloudflare-typescript

Public

mirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v3.3.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

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

79lines · modecode

1// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3import Cloudflare from 'cloudflare';
4import { Response } from 'node-fetch';
5
6const cloudflare = 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
12describe('resource accounts', () => {
13 test('update: only required params', async () => {
14 const responsePromise = cloudflare.accounts.update({ account_id: {}, name: 'Demo Account' });
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('update: required and optional params', async () => {
25 const response = await cloudflare.accounts.update({
26 account_id: {},
27 name: 'Demo Account',
28 settings: {
29 abuse_contact_email: 'string',
30 default_nameservers: 'cloudflare.standard',
31 enforce_twofactor: true,
32 use_account_custom_ns_by_default: true,
33 },
34 });
35 });
36
37 test('list', async () => {
38 const responsePromise = cloudflare.accounts.list();
39 const rawResponse = await responsePromise.asResponse();
40 expect(rawResponse).toBeInstanceOf(Response);
41 const response = await responsePromise;
42 expect(response).not.toBeInstanceOf(Response);
43 const dataAndResponse = await responsePromise.withResponse();
44 expect(dataAndResponse.data).toBe(response);
45 expect(dataAndResponse.response).toBe(rawResponse);
46 });
47
48 test('list: request options instead of params are passed correctly', async () => {
49 // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
50 await expect(cloudflare.accounts.list({ path: '/_stainless_unknown_path' })).rejects.toThrow(
51 Cloudflare.NotFoundError,
52 );
53 });
54
55 test('list: request options and params are passed correctly', async () => {
56 // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
57 await expect(
58 cloudflare.accounts.list(
59 { direction: 'desc', name: 'example.com', page: 1, per_page: 5 },
60 { path: '/_stainless_unknown_path' },
61 ),
62 ).rejects.toThrow(Cloudflare.NotFoundError);
63 });
64
65 test('get: only required params', async () => {
66 const responsePromise = cloudflare.accounts.get({ account_id: {} });
67 const rawResponse = await responsePromise.asResponse();
68 expect(rawResponse).toBeInstanceOf(Response);
69 const response = await responsePromise;
70 expect(response).not.toBeInstanceOf(Response);
71 const dataAndResponse = await responsePromise.withResponse();
72 expect(dataAndResponse.data).toBe(response);
73 expect(dataAndResponse.response).toBe(rawResponse);
74 });
75
76 test('get: required and optional params', async () => {
77 const response = await cloudflare.accounts.get({ account_id: {} });
78 });
79});
80