cloudflare/cloudflare-typescript

Public

mirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
6cd645879ba28ec5e88cbb9be29b7bd86350e1ee

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api-resources/cache/variants.test.ts

80lines · modecode

1// File generated from our OpenAPI spec by Stainless.
2
3import Cloudflare from 'cloudflare';
4import { Response } from 'node-fetch';
5
6const cloudflare = new Cloudflare({
7 apiKey: '144c9defac04969c7bfad8efaa8ea194',
8 apiEmail: 'user@example.com',
9 apiToken: 'Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY',
10 userServiceKey:
11 'v1.0-144c9defac04969c7bfad8ef-631a41d003a32d25fe878081ef365c49503f7fada600da935e2851a1c7326084b85cbf6429c4b859de8475731dc92a9c329631e6d59e6c73da7b198497172b4cefe071d90d0f5d2719',
12 baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
13});
14
15describe('resource variants', () => {
16 // skipped: tests are disabled for the time being
17 test.skip('list', async () => {
18 const responsePromise = cloudflare.cache.variants.list('023e105f4ecef8ad9ca31a8372d0c353');
19 const rawResponse = await responsePromise.asResponse();
20 expect(rawResponse).toBeInstanceOf(Response);
21 const response = await responsePromise;
22 expect(response).not.toBeInstanceOf(Response);
23 const dataAndResponse = await responsePromise.withResponse();
24 expect(dataAndResponse.data).toBe(response);
25 expect(dataAndResponse.response).toBe(rawResponse);
26 });
27
28 // skipped: tests are disabled for the time being
29 test.skip('list: request options instead of params are passed correctly', async () => {
30 // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
31 await expect(
32 cloudflare.cache.variants.list('023e105f4ecef8ad9ca31a8372d0c353', {
33 path: '/_stainless_unknown_path',
34 }),
35 ).rejects.toThrow(Cloudflare.NotFoundError);
36 });
37
38 // skipped: tests are disabled for the time being
39 test.skip('delete', async () => {
40 const responsePromise = cloudflare.cache.variants.delete('023e105f4ecef8ad9ca31a8372d0c353');
41 const rawResponse = await responsePromise.asResponse();
42 expect(rawResponse).toBeInstanceOf(Response);
43 const response = await responsePromise;
44 expect(response).not.toBeInstanceOf(Response);
45 const dataAndResponse = await responsePromise.withResponse();
46 expect(dataAndResponse.data).toBe(response);
47 expect(dataAndResponse.response).toBe(rawResponse);
48 });
49
50 // skipped: tests are disabled for the time being
51 test.skip('edit: only required params', async () => {
52 const responsePromise = cloudflare.cache.variants.edit('023e105f4ecef8ad9ca31a8372d0c353', { value: {} });
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 // skipped: tests are disabled for the time being
63 test.skip('edit: required and optional params', async () => {
64 const response = await cloudflare.cache.variants.edit('023e105f4ecef8ad9ca31a8372d0c353', {
65 value: {
66 avif: ['image/webp', 'image/jpeg'],
67 bmp: ['image/webp', 'image/jpeg'],
68 gif: ['image/webp', 'image/jpeg'],
69 jp2: ['image/webp', 'image/avif'],
70 jpeg: ['image/webp', 'image/avif'],
71 jpg: ['image/webp', 'image/avif'],
72 jpg2: ['image/webp', 'image/avif'],
73 png: ['image/webp', 'image/avif'],
74 tif: ['image/webp', 'image/avif'],
75 tiff: ['image/webp', 'image/avif'],
76 webp: ['image/jpeg', 'image/avif'],
77 },
78 });
79 });
80});
81