cloudflare/cloudflare-typescript
Publicmirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable
tests/api-resources/aisearch/tokens.test.ts
114lines · 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 tokens', () => { |
| 13 | test('create: only required params', async () => { |
| 14 | const responsePromise = client.aiSearch.tokens.create({ |
| 15 | account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', |
| 16 | cf_api_id: 'cf_api_id', |
| 17 | cf_api_key: 'cf_api_key', |
| 18 | name: 'name', |
| 19 | }); |
| 20 | const rawResponse = await responsePromise.asResponse(); |
| 21 | expect(rawResponse).toBeInstanceOf(Response); |
| 22 | const response = await responsePromise; |
| 23 | expect(response).not.toBeInstanceOf(Response); |
| 24 | const dataAndResponse = await responsePromise.withResponse(); |
| 25 | expect(dataAndResponse.data).toBe(response); |
| 26 | expect(dataAndResponse.response).toBe(rawResponse); |
| 27 | }); |
| 28 | |
| 29 | test('create: required and optional params', async () => { |
| 30 | const response = await client.aiSearch.tokens.create({ |
| 31 | account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', |
| 32 | cf_api_id: 'cf_api_id', |
| 33 | cf_api_key: 'cf_api_key', |
| 34 | name: 'name', |
| 35 | legacy: true, |
| 36 | }); |
| 37 | }); |
| 38 | |
| 39 | test('update: only required params', async () => { |
| 40 | const responsePromise = client.aiSearch.tokens.update('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { |
| 41 | account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', |
| 42 | }); |
| 43 | const rawResponse = await responsePromise.asResponse(); |
| 44 | expect(rawResponse).toBeInstanceOf(Response); |
| 45 | const response = await responsePromise; |
| 46 | expect(response).not.toBeInstanceOf(Response); |
| 47 | const dataAndResponse = await responsePromise.withResponse(); |
| 48 | expect(dataAndResponse.data).toBe(response); |
| 49 | expect(dataAndResponse.response).toBe(rawResponse); |
| 50 | }); |
| 51 | |
| 52 | test('update: required and optional params', async () => { |
| 53 | const response = await client.aiSearch.tokens.update('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { |
| 54 | account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', |
| 55 | }); |
| 56 | }); |
| 57 | |
| 58 | test('list: only required params', async () => { |
| 59 | const responsePromise = client.aiSearch.tokens.list({ account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22' }); |
| 60 | const rawResponse = await responsePromise.asResponse(); |
| 61 | expect(rawResponse).toBeInstanceOf(Response); |
| 62 | const response = await responsePromise; |
| 63 | expect(response).not.toBeInstanceOf(Response); |
| 64 | const dataAndResponse = await responsePromise.withResponse(); |
| 65 | expect(dataAndResponse.data).toBe(response); |
| 66 | expect(dataAndResponse.response).toBe(rawResponse); |
| 67 | }); |
| 68 | |
| 69 | test('list: required and optional params', async () => { |
| 70 | const response = await client.aiSearch.tokens.list({ |
| 71 | account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', |
| 72 | page: 1, |
| 73 | per_page: 1, |
| 74 | }); |
| 75 | }); |
| 76 | |
| 77 | test('delete: only required params', async () => { |
| 78 | const responsePromise = client.aiSearch.tokens.delete('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { |
| 79 | account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', |
| 80 | }); |
| 81 | const rawResponse = await responsePromise.asResponse(); |
| 82 | expect(rawResponse).toBeInstanceOf(Response); |
| 83 | const response = await responsePromise; |
| 84 | expect(response).not.toBeInstanceOf(Response); |
| 85 | const dataAndResponse = await responsePromise.withResponse(); |
| 86 | expect(dataAndResponse.data).toBe(response); |
| 87 | expect(dataAndResponse.response).toBe(rawResponse); |
| 88 | }); |
| 89 | |
| 90 | test('delete: required and optional params', async () => { |
| 91 | const response = await client.aiSearch.tokens.delete('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { |
| 92 | account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', |
| 93 | }); |
| 94 | }); |
| 95 | |
| 96 | test('read: only required params', async () => { |
| 97 | const responsePromise = client.aiSearch.tokens.read('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { |
| 98 | account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', |
| 99 | }); |
| 100 | const rawResponse = await responsePromise.asResponse(); |
| 101 | expect(rawResponse).toBeInstanceOf(Response); |
| 102 | const response = await responsePromise; |
| 103 | expect(response).not.toBeInstanceOf(Response); |
| 104 | const dataAndResponse = await responsePromise.withResponse(); |
| 105 | expect(dataAndResponse.data).toBe(response); |
| 106 | expect(dataAndResponse.response).toBe(rawResponse); |
| 107 | }); |
| 108 | |
| 109 | test('read: required and optional params', async () => { |
| 110 | const response = await client.aiSearch.tokens.read('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { |
| 111 | account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', |
| 112 | }); |
| 113 | }); |
| 114 | }); |
| 115 | |