cloudflare/cloudflare-typescript

Public

mirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v7

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

tests/api-resources/ai/to-markdown.test.ts

72lines · modecode

1// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3import { AI } from 'cloudflare/resources/ai/ai';
4import { BaseToMarkdown } from 'cloudflare/resources/ai/to-markdown';
5
6import Cloudflare, { toFile } from 'cloudflare';
7import { createClient, type PartialCloudflare } from 'cloudflare/tree-shakable';
8
9const 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
15const 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: [BaseToMarkdown],
20});
21
22const 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: [AI],
27});
28
29const runTests = (client: PartialCloudflare<{ ai: { toMarkdown: BaseToMarkdown } }>) => {
30 test('supported: only required params', async () => {
31 const responsePromise = client.ai.toMarkdown.supported({
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('supported: required and optional params', async () => {
44 const response = await client.ai.toMarkdown.supported({ account_id: '023e105f4ecef8ad9ca31a8372d0c353' });
45 });
46
47 // TODO: investigate prism error for invalid security scheme used
48 test.skip('transform: only required params', async () => {
49 const responsePromise = client.ai.toMarkdown.transform({
50 account_id: '023e105f4ecef8ad9ca31a8372d0c353',
51 file: { files: [await toFile(Buffer.from('Example data'), 'README.md')] },
52 });
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 // TODO: investigate prism error for invalid security scheme used
63 test.skip('transform: required and optional params', async () => {
64 const response = await client.ai.toMarkdown.transform({
65 account_id: '023e105f4ecef8ad9ca31a8372d0c353',
66 file: { files: [await toFile(Buffer.from('Example data'), 'README.md')] },
67 });
68 });
69};
70describe('resource toMarkdown', () => runTests(client));
71describe('resource toMarkdown (tree shakable, base)', () => runTests(partialClient));
72describe('resource toMarkdown (tree shakable, subresource)', () => runTests(parentPartialClient));