Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 04:45 UTC
| 1 | import { describe, it, expect, vi, beforeEach } from 'vitest'; |
| 2 | import ComposioClient from '@composio/client'; |
| 3 | import { Keyring } from '../../src/models/Keyring'; |
| 4 | import { telemetry } from '../../src/telemetry/Telemetry'; |
| 5 | |
| 6 | vi.mock('../../src/telemetry/Telemetry', () => ({ |
| 7 | telemetry: { |
| 8 | instrument: vi.fn(), |
| 9 | }, |
| 10 | })); |
| 11 | |
| 12 | const createMockClient = () => ({ |
| 13 | keyring: { |
| 14 | listTransferKeys: vi.fn(), |
| 15 | }, |
| 16 | }); |
| 17 | |
| 18 | const rawKey = { |
| 19 | kty: 'RSA', |
| 20 | n: 'sXch3m2k0Yg', |
| 21 | e: 'AQAB', |
| 22 | alg: 'RSA-OAEP-256', |
| 23 | use: 'enc', |
| 24 | kid: 'kid_2', |
| 25 | }; |
| 26 | |
| 27 | describe('Keyring', () => { |
| 28 | let keyring: Keyring; |
| 29 | let mockClient: ReturnType<typeof createMockClient>; |
| 30 | |
| 31 | beforeEach(() => { |
| 32 | vi.clearAllMocks(); |
| 33 | mockClient = createMockClient(); |
| 34 | keyring = new Keyring(mockClient as unknown as ComposioClient); |
| 35 | }); |
| 36 | |
| 37 | it('instruments itself', () => { |
| 38 | expect(telemetry.instrument).toHaveBeenCalledWith(keyring, 'Keyring'); |
| 39 | }); |
| 40 | |
| 41 | it('returns the active kid and keeps the JWK field names', async () => { |
| 42 | mockClient.keyring.listTransferKeys.mockResolvedValue({ |
| 43 | success: true, |
| 44 | active_kid: 'kid_2', |
| 45 | keys: [rawKey, { ...rawKey, kid: 'kid_1' }], |
| 46 | }); |
| 47 | |
| 48 | const result = await keyring.listTransferKeys(); |
| 49 | |
| 50 | expect(mockClient.keyring.listTransferKeys).toHaveBeenCalledWith(undefined); |
| 51 | expect(result).toEqual({ |
| 52 | activeKid: 'kid_2', |
| 53 | keys: [rawKey, { ...rawKey, kid: 'kid_1' }], |
| 54 | }); |
| 55 | }); |
| 56 | |
| 57 | it('forwards request options', async () => { |
| 58 | mockClient.keyring.listTransferKeys.mockResolvedValue({ |
| 59 | success: true, |
| 60 | active_kid: 'kid_2', |
| 61 | keys: [rawKey], |
| 62 | }); |
| 63 | const signal = new AbortController().signal; |
| 64 | |
| 65 | await keyring.listTransferKeys({ signal }); |
| 66 | |
| 67 | expect(mockClient.keyring.listTransferKeys).toHaveBeenCalledWith({ signal }); |
| 68 | }); |
| 69 | }); |