cloudflare/cloudflare-typescript
Publicmirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable
tests/api-resources/accounts/accounts.test.ts
85lines · 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 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 | |
| 12 | describe('resource accounts', () => { |
| 13 | // skipped: tests are disabled for the time being |
| 14 | test.skip('update: only required params', async () => { |
| 15 | const responsePromise = cloudflare.accounts.update({ account_id: {}, name: 'Demo Account' }); |
| 16 | const rawResponse = await responsePromise.asResponse(); |
| 17 | expect(rawResponse).toBeInstanceOf(Response); |
| 18 | const response = await responsePromise; |
| 19 | expect(response).not.toBeInstanceOf(Response); |
| 20 | const dataAndResponse = await responsePromise.withResponse(); |
| 21 | expect(dataAndResponse.data).toBe(response); |
| 22 | expect(dataAndResponse.response).toBe(rawResponse); |
| 23 | }); |
| 24 | |
| 25 | // skipped: tests are disabled for the time being |
| 26 | test.skip('update: required and optional params', async () => { |
| 27 | const response = await cloudflare.accounts.update({ |
| 28 | account_id: {}, |
| 29 | name: 'Demo Account', |
| 30 | settings: { |
| 31 | default_nameservers: 'cloudflare.standard', |
| 32 | enforce_twofactor: true, |
| 33 | use_account_custom_ns_by_default: true, |
| 34 | }, |
| 35 | }); |
| 36 | }); |
| 37 | |
| 38 | // skipped: tests are disabled for the time being |
| 39 | test.skip('list', async () => { |
| 40 | const responsePromise = cloudflare.accounts.list(); |
| 41 | const rawResponse = await responsePromise.asResponse(); |
| 42 | expect(rawResponse).toBeInstanceOf(Response); |
| 43 | const response = await responsePromise; |
| 44 | expect(response).not.toBeInstanceOf(Response); |
| 45 | const dataAndResponse = await responsePromise.withResponse(); |
| 46 | expect(dataAndResponse.data).toBe(response); |
| 47 | expect(dataAndResponse.response).toBe(rawResponse); |
| 48 | }); |
| 49 | |
| 50 | // skipped: tests are disabled for the time being |
| 51 | test.skip('list: request options instead of params are passed correctly', async () => { |
| 52 | // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error |
| 53 | await expect(cloudflare.accounts.list({ path: '/_stainless_unknown_path' })).rejects.toThrow( |
| 54 | Cloudflare.NotFoundError, |
| 55 | ); |
| 56 | }); |
| 57 | |
| 58 | // skipped: tests are disabled for the time being |
| 59 | test.skip('list: request options and params are passed correctly', async () => { |
| 60 | // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error |
| 61 | await expect( |
| 62 | cloudflare.accounts.list( |
| 63 | { direction: 'desc', page: 1, per_page: 5 }, |
| 64 | { path: '/_stainless_unknown_path' }, |
| 65 | ), |
| 66 | ).rejects.toThrow(Cloudflare.NotFoundError); |
| 67 | }); |
| 68 | |
| 69 | // skipped: tests are disabled for the time being |
| 70 | test.skip('get: only required params', async () => { |
| 71 | const responsePromise = cloudflare.accounts.get({ account_id: {} }); |
| 72 | const rawResponse = await responsePromise.asResponse(); |
| 73 | expect(rawResponse).toBeInstanceOf(Response); |
| 74 | const response = await responsePromise; |
| 75 | expect(response).not.toBeInstanceOf(Response); |
| 76 | const dataAndResponse = await responsePromise.withResponse(); |
| 77 | expect(dataAndResponse.data).toBe(response); |
| 78 | expect(dataAndResponse.response).toBe(rawResponse); |
| 79 | }); |
| 80 | |
| 81 | // skipped: tests are disabled for the time being |
| 82 | test.skip('get: required and optional params', async () => { |
| 83 | const response = await cloudflare.accounts.get({ account_id: {} }); |
| 84 | }); |
| 85 | }); |
| 86 | |