Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
ts 87 lines 3.02 KB
Raw
1 import { describe, expect, layer } from '@effect/vitest';
2 import { Effect } from 'effect';
3 import {
4 ABORTED_MESSAGE,
5 NO_API_KEY_MESSAGE,
6 } from 'src/commands/debug/api-info/debug.api-info.format';
7 import { TerminalUI } from 'src/services/terminal-ui';
8 import { cli, MockConsole, TestLive } from 'test/__utils__';
9 import { terminalUITestImpl } from 'test/__utils__/services/terminal-ui-test';
10
11 // The fixture stores `uak_test_key` with current org `org_1`.
12 const LOGGED_IN_FIXTURE = 'user-config-with-global-context';
13
14 /** A headless terminal that answers yes to every confirmation. */
15 const confirmingUI = TerminalUI.of({
16 ...terminalUITestImpl,
17 confirm: () => Effect.succeed(true),
18 });
19
20 describe('CLI: composio debug api-info', () => {
21 layer(TestLive({ fixture: LOGGED_IN_FIXTURE }))('[Given] the confirmation is declined', it => {
22 it.effect('[Then] fails with a usage error and prints nothing on stdout', () =>
23 Effect.gen(function* () {
24 const error = yield* cli(['debug', 'api-info']).pipe(Effect.flip);
25
26 expect(error).toMatchObject({
27 _tag: 'commands/CommandInputError',
28 command: 'debug',
29 message: ABORTED_MESSAGE,
30 });
31 expect(yield* MockConsole.getLines({ stream: 'stdout' })).toEqual([]);
32 })
33 );
34 });
35
36 layer(TestLive({ terminalUI: confirmingUI }))('[Given] no stored login', it => {
37 it.effect('[Then] fails with a usage error naming the missing key', () =>
38 Effect.gen(function* () {
39 const error = yield* cli(['debug', 'api-info']).pipe(Effect.flip);
40
41 expect(error).toMatchObject({
42 _tag: 'commands/CommandInputError',
43 command: 'debug',
44 message: NO_API_KEY_MESSAGE,
45 });
46 })
47 );
48 });
49
50 layer(TestLive({ fixture: 'user-config-with-empty-api-key', terminalUI: confirmingUI }))(
51 '[Given] a stored login whose key is empty',
52 it => {
53 it.effect('[Then] fails naming the missing key and prints nothing on stdout', () =>
54 Effect.gen(function* () {
55 const error = yield* cli(['debug', 'api-info']).pipe(Effect.flip);
56
57 expect(error).toMatchObject({
58 _tag: 'commands/CommandInputError',
59 command: 'debug',
60 message: NO_API_KEY_MESSAGE,
61 });
62 expect(yield* MockConsole.getLines({ stream: 'stdout' })).toEqual([]);
63 })
64 );
65 }
66 );
67
68 layer(TestLive({ fixture: LOGGED_IN_FIXTURE, terminalUI: confirmingUI }))(
69 '[Given] a stored login and a confirmation',
70 it => {
71 it.effect('[Then] prints the key, org, and consumer user id as indented JSON', () =>
72 Effect.gen(function* () {
73 yield* cli(['debug', 'api-info']);
74
75 const stdout = yield* MockConsole.getLines({ stream: 'stdout' });
76 expect(stdout).toHaveLength(1);
77 expect(JSON.parse(stdout[0] ?? '')).toEqual({
78 apiKey: 'uak_test_key',
79 orgId: 'org_1',
80 consumerUserId: 'consumer-user-org_1',
81 });
82 expect(stdout[0]).toContain('\n "apiKey"');
83 })
84 );
85 }
86 );
87 });