cloudflare/cloudflare-typescript
Publicmirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable
tests/api-resources/accounts/members.test.ts
144lines · modecode
| 1 | // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | |
| 3 | import { Accounts } from 'cloudflare/resources/accounts/accounts'; |
| 4 | import { BaseMembers } from 'cloudflare/resources/accounts/members'; |
| 5 | |
| 6 | import Cloudflare from 'cloudflare'; |
| 7 | import { createClient, type PartialCloudflare } from 'cloudflare/tree-shakable'; |
| 8 | |
| 9 | const 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 | |
| 15 | const 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: [BaseMembers], |
| 20 | }); |
| 21 | |
| 22 | const 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 | |
| 29 | const runTests = (client: PartialCloudflare<{ accounts: { members: BaseMembers } }>) => { |
| 30 | // HTTP 422 error from prism |
| 31 | test.skip('create: only required params', async () => { |
| 32 | const responsePromise = client.accounts.members.create({ |
| 33 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 34 | email: 'user@example.com', |
| 35 | roles: ['3536bcfad5faccb999b47003c79917fb'], |
| 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 | // HTTP 422 error from prism |
| 47 | test.skip('create: required and optional params', async () => { |
| 48 | const response = await client.accounts.members.create({ |
| 49 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 50 | email: 'user@example.com', |
| 51 | roles: ['3536bcfad5faccb999b47003c79917fb'], |
| 52 | status: 'accepted', |
| 53 | }); |
| 54 | }); |
| 55 | |
| 56 | // TODO: investigate broken test |
| 57 | test.skip('update: only required params', async () => { |
| 58 | const responsePromise = client.accounts.members.update('4536bcfad5faccb111b47003c79917fa', { |
| 59 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 60 | }); |
| 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 | // TODO: investigate broken test |
| 71 | test.skip('update: required and optional params', async () => { |
| 72 | const response = await client.accounts.members.update('4536bcfad5faccb111b47003c79917fa', { |
| 73 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 74 | roles: [{ id: '3536bcfad5faccb999b47003c79917fb' }], |
| 75 | }); |
| 76 | }); |
| 77 | |
| 78 | test('list: only required params', async () => { |
| 79 | const responsePromise = client.accounts.members.list({ account_id: '023e105f4ecef8ad9ca31a8372d0c353' }); |
| 80 | const rawResponse = await responsePromise.asResponse(); |
| 81 | expect(rawResponse).toBeInstanceOf(Response); |
| 82 | const response = await responsePromise; |
| 83 | expect(response).not.toBeInstanceOf(Response); |
| 84 | const dataAndResponse = await responsePromise.withResponse(); |
| 85 | expect(dataAndResponse.data).toBe(response); |
| 86 | expect(dataAndResponse.response).toBe(rawResponse); |
| 87 | }); |
| 88 | |
| 89 | test('list: required and optional params', async () => { |
| 90 | const response = await client.accounts.members.list({ |
| 91 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 92 | direction: 'desc', |
| 93 | order: 'status', |
| 94 | page: 1, |
| 95 | per_page: 5, |
| 96 | status: 'accepted', |
| 97 | }); |
| 98 | }); |
| 99 | |
| 100 | // HTTP 422 error from prism |
| 101 | test.skip('delete: only required params', async () => { |
| 102 | const responsePromise = client.accounts.members.delete('4536bcfad5faccb111b47003c79917fa', { |
| 103 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 104 | }); |
| 105 | const rawResponse = await responsePromise.asResponse(); |
| 106 | expect(rawResponse).toBeInstanceOf(Response); |
| 107 | const response = await responsePromise; |
| 108 | expect(response).not.toBeInstanceOf(Response); |
| 109 | const dataAndResponse = await responsePromise.withResponse(); |
| 110 | expect(dataAndResponse.data).toBe(response); |
| 111 | expect(dataAndResponse.response).toBe(rawResponse); |
| 112 | }); |
| 113 | |
| 114 | // HTTP 422 error from prism |
| 115 | test.skip('delete: required and optional params', async () => { |
| 116 | const response = await client.accounts.members.delete('4536bcfad5faccb111b47003c79917fa', { |
| 117 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 118 | }); |
| 119 | }); |
| 120 | |
| 121 | // HTTP 422 error from prism |
| 122 | test.skip('get: only required params', async () => { |
| 123 | const responsePromise = client.accounts.members.get('4536bcfad5faccb111b47003c79917fa', { |
| 124 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 125 | }); |
| 126 | const rawResponse = await responsePromise.asResponse(); |
| 127 | expect(rawResponse).toBeInstanceOf(Response); |
| 128 | const response = await responsePromise; |
| 129 | expect(response).not.toBeInstanceOf(Response); |
| 130 | const dataAndResponse = await responsePromise.withResponse(); |
| 131 | expect(dataAndResponse.data).toBe(response); |
| 132 | expect(dataAndResponse.response).toBe(rawResponse); |
| 133 | }); |
| 134 | |
| 135 | // HTTP 422 error from prism |
| 136 | test.skip('get: required and optional params', async () => { |
| 137 | const response = await client.accounts.members.get('4536bcfad5faccb111b47003c79917fa', { |
| 138 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 139 | }); |
| 140 | }); |
| 141 | }; |
| 142 | describe('resource members', () => runTests(client)); |
| 143 | describe('resource members (tree shakable, base)', () => runTests(partialClient)); |
| 144 | describe('resource members (tree shakable, subresource)', () => runTests(parentPartialClient)); |
| 145 | |