cloudflare/cloudflare-typescript

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v6.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

121lines · 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' });
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: '023e105f4ecef8ad9ca31a8372d0c353',
35 id: '023e105f4ecef8ad9ca31a8372d0c353',
36 name: 'Demo Account',
37 type: 'standard',
38 });
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('update: required and optional params', async () => {
49 const response = await client.accounts.update({
50 account_id: '023e105f4ecef8ad9ca31a8372d0c353',
51 id: '023e105f4ecef8ad9ca31a8372d0c353',
52 name: 'Demo Account',
53 type: 'standard',
54 managed_by: {},
55 settings: { abuse_contact_email: 'abuse_contact_email', enforce_twofactor: true },
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 {
82 direction: 'desc',
83 name: 'example.com',
84 page: 1,
85 per_page: 5,
86 },
87 { path: '/_stainless_unknown_path' },
88 ),
89 ).rejects.toThrow(Cloudflare.NotFoundError);
90 });
91
92 test('delete: only required params', async () => {
93 const responsePromise = client.accounts.delete({ account_id: 'account_id' });
94 const rawResponse = await responsePromise.asResponse();
95 expect(rawResponse).toBeInstanceOf(Response);
96 const response = await responsePromise;
97 expect(response).not.toBeInstanceOf(Response);
98 const dataAndResponse = await responsePromise.withResponse();
99 expect(dataAndResponse.data).toBe(response);
100 expect(dataAndResponse.response).toBe(rawResponse);
101 });
102
103 test('delete: required and optional params', async () => {
104 const response = await client.accounts.delete({ account_id: 'account_id' });
105 });
106
107 test('get: only required params', async () => {
108 const responsePromise = client.accounts.get({ account_id: '023e105f4ecef8ad9ca31a8372d0c353' });
109 const rawResponse = await responsePromise.asResponse();
110 expect(rawResponse).toBeInstanceOf(Response);
111 const response = await responsePromise;
112 expect(response).not.toBeInstanceOf(Response);
113 const dataAndResponse = await responsePromise.withResponse();
114 expect(dataAndResponse.data).toBe(response);
115 expect(dataAndResponse.response).toBe(rawResponse);
116 });
117
118 test('get: required and optional params', async () => {
119 const response = await client.accounts.get({ account_id: '023e105f4ecef8ad9ca31a8372d0c353' });
120 });
121});
122