cloudflare/cloudflare-typescript
Publicmirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable
tests/api-resources/accounts/subscriptions.test.ts
108lines · 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 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 | |
| 12 | describe('resource subscriptions', () => { |
| 13 | test('create: only required params', async () => { |
| 14 | const responsePromise = client.accounts.subscriptions.create({ |
| 15 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 16 | }); |
| 17 | const rawResponse = await responsePromise.asResponse(); |
| 18 | expect(rawResponse).toBeInstanceOf(Response); |
| 19 | const response = await responsePromise; |
| 20 | expect(response).not.toBeInstanceOf(Response); |
| 21 | const dataAndResponse = await responsePromise.withResponse(); |
| 22 | expect(dataAndResponse.data).toBe(response); |
| 23 | expect(dataAndResponse.response).toBe(rawResponse); |
| 24 | }); |
| 25 | |
| 26 | test('create: required and optional params', async () => { |
| 27 | const response = await client.accounts.subscriptions.create({ |
| 28 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 29 | frequency: 'weekly', |
| 30 | rate_plan: { |
| 31 | id: 'free', |
| 32 | currency: 'USD', |
| 33 | externally_managed: false, |
| 34 | is_contract: false, |
| 35 | public_name: 'Business Plan', |
| 36 | scope: 'zone', |
| 37 | sets: ['string'], |
| 38 | }, |
| 39 | }); |
| 40 | }); |
| 41 | |
| 42 | test('update: only required params', async () => { |
| 43 | const responsePromise = client.accounts.subscriptions.update('506e3185e9c882d175a2d0cb0093d9f2', { |
| 44 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 45 | }); |
| 46 | const rawResponse = await responsePromise.asResponse(); |
| 47 | expect(rawResponse).toBeInstanceOf(Response); |
| 48 | const response = await responsePromise; |
| 49 | expect(response).not.toBeInstanceOf(Response); |
| 50 | const dataAndResponse = await responsePromise.withResponse(); |
| 51 | expect(dataAndResponse.data).toBe(response); |
| 52 | expect(dataAndResponse.response).toBe(rawResponse); |
| 53 | }); |
| 54 | |
| 55 | test('update: required and optional params', async () => { |
| 56 | const response = await client.accounts.subscriptions.update('506e3185e9c882d175a2d0cb0093d9f2', { |
| 57 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 58 | frequency: 'weekly', |
| 59 | rate_plan: { |
| 60 | id: 'free', |
| 61 | currency: 'USD', |
| 62 | externally_managed: false, |
| 63 | is_contract: false, |
| 64 | public_name: 'Business Plan', |
| 65 | scope: 'zone', |
| 66 | sets: ['string'], |
| 67 | }, |
| 68 | }); |
| 69 | }); |
| 70 | |
| 71 | test('delete: only required params', async () => { |
| 72 | const responsePromise = client.accounts.subscriptions.delete('506e3185e9c882d175a2d0cb0093d9f2', { |
| 73 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 74 | }); |
| 75 | const rawResponse = await responsePromise.asResponse(); |
| 76 | expect(rawResponse).toBeInstanceOf(Response); |
| 77 | const response = await responsePromise; |
| 78 | expect(response).not.toBeInstanceOf(Response); |
| 79 | const dataAndResponse = await responsePromise.withResponse(); |
| 80 | expect(dataAndResponse.data).toBe(response); |
| 81 | expect(dataAndResponse.response).toBe(rawResponse); |
| 82 | }); |
| 83 | |
| 84 | test('delete: required and optional params', async () => { |
| 85 | const response = await client.accounts.subscriptions.delete('506e3185e9c882d175a2d0cb0093d9f2', { |
| 86 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 87 | }); |
| 88 | }); |
| 89 | |
| 90 | test('get: only required params', async () => { |
| 91 | const responsePromise = client.accounts.subscriptions.get({ |
| 92 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 93 | }); |
| 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('get: required and optional params', async () => { |
| 104 | const response = await client.accounts.subscriptions.get({ |
| 105 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 106 | }); |
| 107 | }); |
| 108 | }); |
| 109 | |