cloudflare/cloudflare-typescript
Publicmirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable
tests/api-resources/calls/calls.test.ts
103lines · 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 calls', () => { |
| 13 | test('create: only required params', async () => { |
| 14 | const responsePromise = cloudflare.calls.create({ account_id: '023e105f4ecef8ad9ca31a8372d0c353' }); |
| 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 cloudflare.calls.create({ |
| 26 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 27 | name: 'production-realtime-app', |
| 28 | }); |
| 29 | }); |
| 30 | |
| 31 | test('update: only required params', async () => { |
| 32 | const responsePromise = cloudflare.calls.update('2a95132c15732412d22c1476fa83f27a', { |
| 33 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 34 | }); |
| 35 | const rawResponse = await responsePromise.asResponse(); |
| 36 | expect(rawResponse).toBeInstanceOf(Response); |
| 37 | const response = await responsePromise; |
| 38 | expect(response).not.toBeInstanceOf(Response); |
| 39 | const dataAndResponse = await responsePromise.withResponse(); |
| 40 | expect(dataAndResponse.data).toBe(response); |
| 41 | expect(dataAndResponse.response).toBe(rawResponse); |
| 42 | }); |
| 43 | |
| 44 | test('update: required and optional params', async () => { |
| 45 | const response = await cloudflare.calls.update('2a95132c15732412d22c1476fa83f27a', { |
| 46 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 47 | name: 'production-realtime-app', |
| 48 | }); |
| 49 | }); |
| 50 | |
| 51 | test('list: only required params', async () => { |
| 52 | const responsePromise = cloudflare.calls.list({ account_id: '023e105f4ecef8ad9ca31a8372d0c353' }); |
| 53 | const rawResponse = await responsePromise.asResponse(); |
| 54 | expect(rawResponse).toBeInstanceOf(Response); |
| 55 | const response = await responsePromise; |
| 56 | expect(response).not.toBeInstanceOf(Response); |
| 57 | const dataAndResponse = await responsePromise.withResponse(); |
| 58 | expect(dataAndResponse.data).toBe(response); |
| 59 | expect(dataAndResponse.response).toBe(rawResponse); |
| 60 | }); |
| 61 | |
| 62 | test('list: required and optional params', async () => { |
| 63 | const response = await cloudflare.calls.list({ account_id: '023e105f4ecef8ad9ca31a8372d0c353' }); |
| 64 | }); |
| 65 | |
| 66 | test('delete: only required params', async () => { |
| 67 | const responsePromise = cloudflare.calls.delete('2a95132c15732412d22c1476fa83f27a', { |
| 68 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 69 | }); |
| 70 | const rawResponse = await responsePromise.asResponse(); |
| 71 | expect(rawResponse).toBeInstanceOf(Response); |
| 72 | const response = await responsePromise; |
| 73 | expect(response).not.toBeInstanceOf(Response); |
| 74 | const dataAndResponse = await responsePromise.withResponse(); |
| 75 | expect(dataAndResponse.data).toBe(response); |
| 76 | expect(dataAndResponse.response).toBe(rawResponse); |
| 77 | }); |
| 78 | |
| 79 | test('delete: required and optional params', async () => { |
| 80 | const response = await cloudflare.calls.delete('2a95132c15732412d22c1476fa83f27a', { |
| 81 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 82 | }); |
| 83 | }); |
| 84 | |
| 85 | test('get: only required params', async () => { |
| 86 | const responsePromise = cloudflare.calls.get('2a95132c15732412d22c1476fa83f27a', { |
| 87 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 88 | }); |
| 89 | const rawResponse = await responsePromise.asResponse(); |
| 90 | expect(rawResponse).toBeInstanceOf(Response); |
| 91 | const response = await responsePromise; |
| 92 | expect(response).not.toBeInstanceOf(Response); |
| 93 | const dataAndResponse = await responsePromise.withResponse(); |
| 94 | expect(dataAndResponse.data).toBe(response); |
| 95 | expect(dataAndResponse.response).toBe(rawResponse); |
| 96 | }); |
| 97 | |
| 98 | test('get: required and optional params', async () => { |
| 99 | const response = await cloudflare.calls.get('2a95132c15732412d22c1476fa83f27a', { |
| 100 | account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 101 | }); |
| 102 | }); |
| 103 | }); |
| 104 | |