Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | import { afterEach, beforeAll, describe, expect, mock, test } from 'bun:test'; |
| 2 | import { NextRequest } from 'next/server'; |
| 3 | |
| 4 | const originalFetch = globalThis.fetch; |
| 5 | let getTool: typeof import('../../app/api/tools/[slug]/route').GET; |
| 6 | |
| 7 | beforeAll(async () => { |
| 8 | const apiKey = process.env.COMPOSIO_API_KEY; |
| 9 | process.env.COMPOSIO_API_KEY = 'test-key'; |
| 10 | try { |
| 11 | getTool = (await import('../../app/api/tools/[slug]/route')).GET; |
| 12 | } finally { |
| 13 | if (apiKey === undefined) delete process.env.COMPOSIO_API_KEY; |
| 14 | else process.env.COMPOSIO_API_KEY = apiKey; |
| 15 | } |
| 16 | }); |
| 17 | |
| 18 | afterEach(() => { |
| 19 | globalThis.fetch = originalFetch; |
| 20 | }); |
| 21 | |
| 22 | describe('tool detail Instant metadata', () => { |
| 23 | for (const version of ['latest', '20260101_00']) { |
| 24 | test(`only latest includes pricing metadata (${version})`, async () => { |
| 25 | const instant = { supported: true, price: { description: 'API price', discount: '0' } }; |
| 26 | const fetchMock = mock(async () => Response.json({ instant, input_parameters: { type: 'object' } })); |
| 27 | globalThis.fetch = Object.assign(fetchMock, { preconnect: originalFetch.preconnect }); |
| 28 | const response = await getTool( |
| 29 | new NextRequest(`https://docs.composio.dev/api/tools/EXAMPLE?version=${version}`), |
| 30 | { params: Promise.resolve({ slug: 'EXAMPLE' }) } |
| 31 | ); |
| 32 | const body = await response.json(); |
| 33 | expect(response.status).toBe(200); |
| 34 | expect(body.input_parameters).toEqual({ type: 'object' }); |
| 35 | expect(body.instant).toEqual(version === 'latest' ? instant : undefined); |
| 36 | expect(fetchMock).toHaveBeenCalledTimes(1); |
| 37 | const url = String(fetchMock.mock.calls[0]?.[0]); |
| 38 | expect(url.includes('include_pricing=true')).toBe(version === 'latest'); |
| 39 | expect(url).toContain(`version=${version}`); |
| 40 | }); |
| 41 | } |
| 42 | }); |