cloudflare/cloudflare-typescript

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v4.0.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

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

116lines · 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 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
12describe('resource accounts', () => {
13 test('create: only required params', async () => {
14 const responsePromise = client.accounts.create({ name: 'name', type: 'standard' });
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('create: required and optional params', async () => {
25 const response = await client.accounts.create({
26 name: 'name',
27 type: 'standard',
28 unit: { id: 'f267e341f3dd4697bd3b9f71dd96247f' },
29 });
30 });
31
32 test('update: only required params', async () => {
33 const responsePromise = client.accounts.update({
34 account_id: 'eb78d65290b24279ba6f44721b3ea3c4',
35 name: 'Demo Account',
36 });
37 const rawResponse = await responsePromise.asResponse();
38 expect(rawResponse).toBeInstanceOf(Response);
39 const response = await responsePromise;
40 expect(response).not.toBeInstanceOf(Response);
41 const dataAndResponse = await responsePromise.withResponse();
42 expect(dataAndResponse.data).toBe(response);
43 expect(dataAndResponse.response).toBe(rawResponse);
44 });
45
46 test('update: required and optional params', async () => {
47 const response = await client.accounts.update({
48 account_id: 'eb78d65290b24279ba6f44721b3ea3c4',
49 name: 'Demo Account',
50 settings: {
51 abuse_contact_email: 'abuse_contact_email',
52 default_nameservers: 'cloudflare.standard',
53 enforce_twofactor: true,
54 use_account_custom_ns_by_default: true,
55 },
56 });
57 });
58
59 test('list', async () => {
60 const responsePromise = client.accounts.list();
61 const rawResponse = await responsePromise.asResponse();
62 expect(rawResponse).toBeInstanceOf(Response);
63 const response = await responsePromise;
64 expect(response).not.toBeInstanceOf(Response);
65 const dataAndResponse = await responsePromise.withResponse();
66 expect(dataAndResponse.data).toBe(response);
67 expect(dataAndResponse.response).toBe(rawResponse);
68 });
69
70 test('list: request options instead of params are passed correctly', async () => {
71 // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
72 await expect(client.accounts.list({ path: '/_stainless_unknown_path' })).rejects.toThrow(
73 Cloudflare.NotFoundError,
74 );
75 });
76
77 test('list: request options and params are passed correctly', async () => {
78 // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
79 await expect(
80 client.accounts.list(
81 { direction: 'asc', name: 'example.com', page: 1, per_page: 5 },
82 { path: '/_stainless_unknown_path' },
83 ),
84 ).rejects.toThrow(Cloudflare.NotFoundError);
85 });
86
87 test('delete: only required params', async () => {
88 const responsePromise = client.accounts.delete({ account_id: 'account_id' });
89 const rawResponse = await responsePromise.asResponse();
90 expect(rawResponse).toBeInstanceOf(Response);
91 const response = await responsePromise;
92 expect(response).not.toBeInstanceOf(Response);
93 const dataAndResponse = await responsePromise.withResponse();
94 expect(dataAndResponse.data).toBe(response);
95 expect(dataAndResponse.response).toBe(rawResponse);
96 });
97
98 test('delete: required and optional params', async () => {
99 const response = await client.accounts.delete({ account_id: 'account_id' });
100 });
101
102 test('get: only required params', async () => {
103 const responsePromise = client.accounts.get({ account_id: 'eb78d65290b24279ba6f44721b3ea3c4' });
104 const rawResponse = await responsePromise.asResponse();
105 expect(rawResponse).toBeInstanceOf(Response);
106 const response = await responsePromise;
107 expect(response).not.toBeInstanceOf(Response);
108 const dataAndResponse = await responsePromise.withResponse();
109 expect(dataAndResponse.data).toBe(response);
110 expect(dataAndResponse.response).toBe(rawResponse);
111 });
112
113 test('get: required and optional params', async () => {
114 const response = await client.accounts.get({ account_id: 'eb78d65290b24279ba6f44721b3ea3c4' });
115 });
116});
117