|
1 | 1 | // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
2 | 2 |
|
3 | 3 | import Anthropic, { toFile } from '@anthropic-ai/sdk'; |
| 4 | +import { mockFetch } from '../../../lib/mock-fetch'; |
4 | 5 |
|
5 | 6 | const client = new Anthropic({ |
6 | 7 | apiKey: 'my-anthropic-api-key', |
@@ -33,6 +34,39 @@ describe('resource versions', () => { |
33 | 34 | ).rejects.toThrow(Anthropic.NotFoundError); |
34 | 35 | }); |
35 | 36 |
|
| 37 | + test('create: preserves nested skill filenames in multipart uploads', async () => { |
| 38 | + const { fetch: mock, handleRequest } = mockFetch(); |
| 39 | + const fetch: typeof globalThis.fetch = (req, init) => { |
| 40 | + if (typeof req === 'string' && req.startsWith('data:,')) { |
| 41 | + return globalThis.fetch(req, init); |
| 42 | + } |
| 43 | + |
| 44 | + return mock(req, init); |
| 45 | + }; |
| 46 | + const skillsClient = new Anthropic({ apiKey: 'my-anthropic-api-key', fetch, maxRetries: 0 }); |
| 47 | + |
| 48 | + handleRequest(async (_req, init) => { |
| 49 | + expect(init?.body).toBeInstanceOf(FormData); |
| 50 | + |
| 51 | + const form = init?.body as FormData; |
| 52 | + const file = form.get('files[]'); |
| 53 | + expect(file).toBeInstanceOf(File); |
| 54 | + expect((file as File).name).toBe('my-skill/SKILL.md'); |
| 55 | + |
| 56 | + return new Response(JSON.stringify({ id: 'skill_version_123' }), { |
| 57 | + headers: { 'content-type': 'application/json' }, |
| 58 | + }); |
| 59 | + }); |
| 60 | + |
| 61 | + const response = await skillsClient.beta.skills.versions |
| 62 | + .create('skill_id', { |
| 63 | + files: [await toFile(Buffer.from('Example data'), 'my-skill/SKILL.md')], |
| 64 | + }) |
| 65 | + .asResponse(); |
| 66 | + |
| 67 | + expect(response).toBeInstanceOf(Response); |
| 68 | + }); |
| 69 | + |
36 | 70 | test('retrieve: only required params', async () => { |
37 | 71 | const responsePromise = client.beta.skills.versions.retrieve('version', { skill_id: 'skill_id' }); |
38 | 72 | const rawResponse = await responsePromise.asResponse(); |
|
0 commit comments