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 { describe, expect, test } from 'bun:test'; |
| 2 | import { |
| 3 | cleanupVerificationSessions, |
| 4 | listAllSessionConfigs, |
| 5 | } from '../src/session-config-verification'; |
| 6 | |
| 7 | describe('Session config verification', () => { |
| 8 | test.each([false, true])('reads every page with archived=%s', async archived => { |
| 9 | const cursors: (string | undefined)[] = []; |
| 10 | const items = await listAllSessionConfigs( |
| 11 | { |
| 12 | async list(params) { |
| 13 | expect(params?.archived).toBe(archived); |
| 14 | cursors.push(params?.cursor); |
| 15 | return { |
| 16 | items: [ |
| 17 | { |
| 18 | id: params?.cursor === undefined ? 'sc_first' : 'sc_target', |
| 19 | name: 'Verification config', |
| 20 | archived, |
| 21 | createdAt: '2026-09-01T00:00:00Z', |
| 22 | updatedAt: '2026-09-01T00:00:00Z', |
| 23 | }, |
| 24 | ], |
| 25 | nextCursor: params?.cursor === undefined ? 'page_2' : null, |
| 26 | }; |
| 27 | }, |
| 28 | }, |
| 29 | { archived } |
| 30 | ); |
| 31 | |
| 32 | expect(items.map(item => item.id)).toEqual(['sc_first', 'sc_target']); |
| 33 | expect(cursors).toEqual([undefined, 'page_2']); |
| 34 | }); |
| 35 | |
| 36 | test('stops a repeated cursor instead of hanging', async () => { |
| 37 | await expect( |
| 38 | listAllSessionConfigs({ |
| 39 | list: async () => ({ items: [], nextCursor: 'same_page' }), |
| 40 | }) |
| 41 | ).rejects.toThrow('pagination repeated cursor'); |
| 42 | }); |
| 43 | |
| 44 | test('surfaces cleanup errors and still tries the remaining Sessions', async () => { |
| 45 | const attempted: string[] = []; |
| 46 | await expect( |
| 47 | cleanupVerificationSessions(['trs_failed', 'trs_ok'], async id => { |
| 48 | attempted.push(id); |
| 49 | if (id === 'trs_failed') throw new Error('Deletion failed'); |
| 50 | return { deleted: true }; |
| 51 | }) |
| 52 | ).rejects.toThrow('Could not delete session trs_failed'); |
| 53 | expect(attempted).toEqual(['trs_failed', 'trs_ok']); |
| 54 | }); |
| 55 | |
| 56 | test('treats an unconfirmed deletion as a cleanup failure', async () => { |
| 57 | await expect( |
| 58 | cleanupVerificationSessions(['trs_failed'], async () => ({ deleted: false })) |
| 59 | ).rejects.toThrow('Could not delete session trs_failed'); |
| 60 | }); |
| 61 | |
| 62 | test('succeeds when every Session is deleted', async () => { |
| 63 | await expect( |
| 64 | cleanupVerificationSessions(['trs_ok'], async () => ({ deleted: true })) |
| 65 | ).resolves.toBeUndefined(); |
| 66 | }); |
| 67 | }); |