cloudflare/cloudflare-typescript
Publicmirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable
tests/api-resources/accounts/subscriptions.test.ts
128lines · 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 { BaseSubscriptions } from 'cloudflare/resources/accounts/subscriptions'; |
| 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: [BaseSubscriptions], |
| 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: { subscriptions: BaseSubscriptions } }>) => { |
| 30 | test('create: only required params', async () => { |
| 31 | const responsePromise = client.accounts.subscriptions.create({ |
| 32 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 33 | }); |
| 34 | const rawResponse = await responsePromise.asResponse(); |
| 35 | expect(rawResponse).toBeInstanceOf(Response); |
| 36 | const response = await responsePromise; |
| 37 | expect(response).not.toBeInstanceOf(Response); |
| 38 | const dataAndResponse = await responsePromise.withResponse(); |
| 39 | expect(dataAndResponse.data).toBe(response); |
| 40 | expect(dataAndResponse.response).toBe(rawResponse); |
| 41 | }); |
| 42 | |
| 43 | test('create: required and optional params', async () => { |
| 44 | const response = await client.accounts.subscriptions.create({ |
| 45 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 46 | frequency: 'monthly', |
| 47 | rate_plan: { |
| 48 | id: 'free', |
| 49 | currency: 'USD', |
| 50 | externally_managed: false, |
| 51 | is_contract: false, |
| 52 | public_name: 'Business Plan', |
| 53 | scope: 'zone', |
| 54 | sets: ['string'], |
| 55 | }, |
| 56 | }); |
| 57 | }); |
| 58 | |
| 59 | test('update: only required params', async () => { |
| 60 | const responsePromise = client.accounts.subscriptions.update('506e3185e9c882d175a2d0cb0093d9f2', { |
| 61 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 62 | }); |
| 63 | const rawResponse = await responsePromise.asResponse(); |
| 64 | expect(rawResponse).toBeInstanceOf(Response); |
| 65 | const response = await responsePromise; |
| 66 | expect(response).not.toBeInstanceOf(Response); |
| 67 | const dataAndResponse = await responsePromise.withResponse(); |
| 68 | expect(dataAndResponse.data).toBe(response); |
| 69 | expect(dataAndResponse.response).toBe(rawResponse); |
| 70 | }); |
| 71 | |
| 72 | test('update: required and optional params', async () => { |
| 73 | const response = await client.accounts.subscriptions.update('506e3185e9c882d175a2d0cb0093d9f2', { |
| 74 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 75 | frequency: 'monthly', |
| 76 | rate_plan: { |
| 77 | id: 'free', |
| 78 | currency: 'USD', |
| 79 | externally_managed: false, |
| 80 | is_contract: false, |
| 81 | public_name: 'Business Plan', |
| 82 | scope: 'zone', |
| 83 | sets: ['string'], |
| 84 | }, |
| 85 | }); |
| 86 | }); |
| 87 | |
| 88 | test('delete: only required params', async () => { |
| 89 | const responsePromise = client.accounts.subscriptions.delete('506e3185e9c882d175a2d0cb0093d9f2', { |
| 90 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 91 | }); |
| 92 | const rawResponse = await responsePromise.asResponse(); |
| 93 | expect(rawResponse).toBeInstanceOf(Response); |
| 94 | const response = await responsePromise; |
| 95 | expect(response).not.toBeInstanceOf(Response); |
| 96 | const dataAndResponse = await responsePromise.withResponse(); |
| 97 | expect(dataAndResponse.data).toBe(response); |
| 98 | expect(dataAndResponse.response).toBe(rawResponse); |
| 99 | }); |
| 100 | |
| 101 | test('delete: required and optional params', async () => { |
| 102 | const response = await client.accounts.subscriptions.delete('506e3185e9c882d175a2d0cb0093d9f2', { |
| 103 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 104 | }); |
| 105 | }); |
| 106 | |
| 107 | test('get: only required params', async () => { |
| 108 | const responsePromise = client.accounts.subscriptions.get({ |
| 109 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 110 | }); |
| 111 | const rawResponse = await responsePromise.asResponse(); |
| 112 | expect(rawResponse).toBeInstanceOf(Response); |
| 113 | const response = await responsePromise; |
| 114 | expect(response).not.toBeInstanceOf(Response); |
| 115 | const dataAndResponse = await responsePromise.withResponse(); |
| 116 | expect(dataAndResponse.data).toBe(response); |
| 117 | expect(dataAndResponse.response).toBe(rawResponse); |
| 118 | }); |
| 119 | |
| 120 | test('get: required and optional params', async () => { |
| 121 | const response = await client.accounts.subscriptions.get({ |
| 122 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 123 | }); |
| 124 | }); |
| 125 | }; |
| 126 | describe('resource subscriptions', () => runTests(client)); |
| 127 | describe('resource subscriptions (tree shakable, base)', () => runTests(partialClient)); |
| 128 | describe('resource subscriptions (tree shakable, subresource)', () => runTests(parentPartialClient)); |
| 129 | |