2
import { ConfigProvider, Effect } from 'effect';
3
import { extendConfigProvider } from 'src/services/config';
4
import { cli, TestLive, MockConsole } from 'test/__utils__';
5
+import { afterEach, vi } from 'vitest';
6
7
describe('CLI: composio whoami', () => {
8
+ afterEach(() => {
9
+ vi.restoreAllMocks();
10
+ });
11
+
12
const testConfigProvider = ConfigProvider.fromMap(
13
new Map([['COMPOSIO_USER_API_KEY', 'api_key_from_test_config_provider']])
14
).pipe(extendConfigProvider);
23
const output = lines.join('\n');
24
expect(output).not.toContain(`api_key_from_test_config_provider`);
25
expect(output).not.toContain(`global_user_api_key`);
26
+ expect(output).toContain(`"email":null`);
27
+ expect(output).toContain(`"default_org_name":null`);
28
expect(output).toContain(`"default_org_id":null`);
29
expect(output).toContain(`"test_user_id":null`);
30
})
41
const output = lines.join('\n');
42
expect(output).not.toContain(`api_key_from_test_fixture`);
43
expect(output).not.toContain(`global_user_api_key`);
44
+ expect(output).toContain(`"email":null`);
45
+ expect(output).toContain(`"default_org_name":null`);
46
expect(output).toContain(`"default_org_id":null`);
47
expect(output).toContain(`"test_user_id":null`);
48
})
49
);
50
});
51
+
52
+ layer(TestLive({ baseConfigProvider: testConfigProvider }))('with session info', it => {
53
+ it.scoped('[Given] session info is available [Then] prints email and org name', () =>
54
+ Effect.gen(function* () {
55
+ vi.spyOn(globalThis, 'fetch').mockResolvedValue(
56
+ new Response(
57
+ JSON.stringify({
58
+ project: {
59
+ name: 'Test Project',
60
+ id: 'proj_123',
61
+ org_id: 'org_123',
62
+ nano_id: 'proj_nano_123',
63
+ email: 'project@example.com',
64
+ created_at: '2026-03-27T00:00:00.000Z',
65
+ updated_at: '2026-03-27T00:00:00.000Z',
66
+ org: {
67
+ name: 'Acme Org',
68
+ id: 'org_123',
69
+ plan: 'enterprise',
70
+ },
71
+ },
72
+ org_member: {
73
+ id: 'om_123',
74
+ user_id: 'usr_123',
75
+ email: 'person@example.com',
76
+ name: 'Test Person',
77
+ role: 'admin',
78
+ },
79
+ api_key: null,
80
+ }),
81
+ {
82
+ status: 200,
83
+ headers: { 'Content-Type': 'application/json' },
84
+ }
85
+ )
86
+ );
87
+
88
+ yield* cli(['whoami']);
89
+
90
+ const lines = yield* MockConsole.getLines();
91
+ const output = lines.join('\n');
92
+ expect(output).toContain(`"email":"person@example.com"`);
93
+ expect(output).toContain(`"default_org_name":"Acme Org"`);
94
+ })
95
+ );
96
+ });
97
});