|
| 1 | +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | + |
| 3 | +import Julep from '@julep/sdk'; |
| 4 | +import { Response } from 'node-fetch'; |
| 5 | + |
| 6 | +const client = new Julep({ |
| 7 | + apiKey: 'My API Key', |
| 8 | + baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', |
| 9 | +}); |
| 10 | + |
| 11 | +describe('resource files', () => { |
| 12 | + test('create: only required params', async () => { |
| 13 | + const responsePromise = client.files.create({ content: 'content', name: 'name' }); |
| 14 | + const rawResponse = await responsePromise.asResponse(); |
| 15 | + expect(rawResponse).toBeInstanceOf(Response); |
| 16 | + const response = await responsePromise; |
| 17 | + expect(response).not.toBeInstanceOf(Response); |
| 18 | + const dataAndResponse = await responsePromise.withResponse(); |
| 19 | + expect(dataAndResponse.data).toBe(response); |
| 20 | + expect(dataAndResponse.response).toBe(rawResponse); |
| 21 | + }); |
| 22 | + |
| 23 | + test('create: required and optional params', async () => { |
| 24 | + const response = await client.files.create({ |
| 25 | + content: 'content', |
| 26 | + name: 'name', |
| 27 | + description: 'description', |
| 28 | + mime_type: 'mime_type', |
| 29 | + }); |
| 30 | + }); |
| 31 | + |
| 32 | + test('delete', async () => { |
| 33 | + const responsePromise = client.files.delete('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e'); |
| 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('delete: request options instead of params are passed correctly', async () => { |
| 44 | + // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error |
| 45 | + await expect( |
| 46 | + client.files.delete('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { path: '/_stainless_unknown_path' }), |
| 47 | + ).rejects.toThrow(Julep.NotFoundError); |
| 48 | + }); |
| 49 | + |
| 50 | + test('get', async () => { |
| 51 | + const responsePromise = client.files.get('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e'); |
| 52 | + const rawResponse = await responsePromise.asResponse(); |
| 53 | + expect(rawResponse).toBeInstanceOf(Response); |
| 54 | + const response = await responsePromise; |
| 55 | + expect(response).not.toBeInstanceOf(Response); |
| 56 | + const dataAndResponse = await responsePromise.withResponse(); |
| 57 | + expect(dataAndResponse.data).toBe(response); |
| 58 | + expect(dataAndResponse.response).toBe(rawResponse); |
| 59 | + }); |
| 60 | + |
| 61 | + test('get: request options instead of params are passed correctly', async () => { |
| 62 | + // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error |
| 63 | + await expect( |
| 64 | + client.files.get('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { path: '/_stainless_unknown_path' }), |
| 65 | + ).rejects.toThrow(Julep.NotFoundError); |
| 66 | + }); |
| 67 | +}); |
0 commit comments