1
import { describe, expect, layer } from '@effect/vitest';
2
-import { ConfigProvider, Effect } from 'effect';
2
+import { ConfigProvider, Effect, Layer } from 'effect';
3
+import type { TriggerInstanceUpsertParams } from '@composio/client/resources/trigger-instances';
4
+import { ComposioToolkitsRepository } from 'src/services/composio-clients';
5
import { cli, MockConsole, TestLive } from 'test/__utils__';
6
+import { notFoundError } from 'test/__utils__/layers/not-found';
7
+import { recordingNodeProcess } from 'test/__utils__/services/node-process-test';
8
+import { makeToolkitsRepositoryStub } from 'test/__utils__/services/toolkits-repository-stub';
9
10
const testConfigProvider = ConfigProvider.fromEnv({
11
env: { COMPOSIO_USER_API_KEY: 'test_api_key' },
16
cliUserConfig: { developerDangerousCommandsEnabled: true },
17
} as const;
18
14
-describe('CLI: composio dev triggers mutations', () => {
19
+describe('CLI: composio dev triggers create', () => {
20
layer(TestLive(dangerousDevConfig))(
21
'[Given] create with valid args [Then] creates trigger',
22
it => {
35
36
expect(output).toContain('Trigger created');
37
expect(output).toContain('trg_gmail_new_gmail_message_con_123');
38
+ expect(lines.at(-1)).toBe(
39
+ JSON.stringify({ trigger_id: 'trg_gmail_new_gmail_message_con_123' }, null, 2)
40
+ );
41
+ })
42
+ );
43
+ }
44
+ );
45
+
46
+ layer(TestLive(dangerousDevConfig))(
47
+ '[Given] create with a JSON object config [Then] sends it as the trigger config',
48
+ it => {
49
+ it.effect('passes the parsed config and connected account to the API', () =>
50
+ Effect.gen(function* () {
51
+ const calls: Array<{ slug: string; params?: TriggerInstanceUpsertParams }> = [];
52
+ const repository = Layer.succeed(
53
+ ComposioToolkitsRepository,
54
+ makeToolkitsRepositoryStub({
55
+ createTrigger: (slug, params) =>
56
+ Effect.sync(() => {
57
+ calls.push({ slug, params });
58
+ return { trigger_id: 'trg_new' };
59
+ }),
60
+ })
61
+ );
62
+ yield* cli([
63
+ 'dev',
64
+ 'triggers',
65
+ 'create',
66
+ 'GMAIL_NEW_GMAIL_MESSAGE',
67
+ '--connected-account-id',
68
+ 'con_123',
69
+ '--trigger-config',
70
+ '{"labelIds":"INBOX"}',
71
+ ]).pipe(Effect.provide(repository));
72
+
73
+ expect(calls).toEqual([
74
+ {
75
+ slug: 'GMAIL_NEW_GMAIL_MESSAGE',
76
+ params: { connected_account_id: 'con_123', trigger_config: { labelIds: 'INBOX' } },
77
+ },
78
+ ]);
79
})
80
);
81
}
103
}
104
);
105
60
- layer(TestLive(dangerousDevConfig))('[Given] enable with ID [Then] enables trigger', it => {
61
- it.effect('enables trigger successfully', () =>
62
- Effect.gen(function* () {
63
- yield* cli(['dev', 'triggers', 'enable', 'trg_123']);
64
- const lines = yield* MockConsole.getLines({ stripAnsi: true });
65
- const output = lines.join('\n');
66
- expect(output).toContain('enabled');
67
- })
68
- );
69
- });
70
-
71
- layer(TestLive(dangerousDevConfig))('[Given] disable with ID [Then] disables trigger', it => {
72
- it.effect('disables trigger successfully', () =>
73
- Effect.gen(function* () {
74
- yield* cli(['dev', 'triggers', 'disable', 'trg_123', '--dangerously-allow']);
75
- const lines = yield* MockConsole.getLines({ stripAnsi: true });
76
- const output = lines.join('\n');
77
- expect(output).toContain('disabled');
78
- })
79
- );
80
- });
81
-
106
layer(TestLive(dangerousDevConfig))(
107
'[Given] create with non-object JSON config [Then] shows type validation error',
108
it => {
143
);
144
145
layer(TestLive(dangerousDevConfig))(
122
- '[Given] missing ID for enable [Then] warns about missing argument',
146
+ '[Given] create without a trigger name [Then] warns about missing argument',
147
it => {
124
- it.effect('shows missing id warning', () =>
148
+ it.effect('shows missing trigger-name warning', () =>
149
Effect.gen(function* () {
126
- yield* cli(['dev', 'triggers', 'enable']);
150
+ yield* cli(['dev', 'triggers', 'create']);
151
const lines = yield* MockConsole.getLines({ stripAnsi: true });
152
const output = lines.join('\n');
129
- expect(output).toContain('Missing required argument');
153
+ expect(output).toContain('Missing required argument: <trigger-name>');
154
})
155
);
156
}
157
);
158
159
layer(TestLive(dangerousDevConfig))(
136
- '[Given] missing ID for disable [Then] warns about missing argument',
160
+ '[Given] the API rejects the create [Then] reports the failure and exits 1',
161
it => {
138
- it.effect('shows missing id warning', () =>
162
+ it.effect('prints the fallback message and the list hint', () =>
163
Effect.gen(function* () {
140
- yield* cli(['dev', 'triggers', 'disable', '--dangerously-allow']);
141
- const lines = yield* MockConsole.getLines({ stripAnsi: true });
142
- const output = lines.join('\n');
143
- expect(output).toContain('Missing required argument');
164
+ const proc = recordingNodeProcess();
165
+ const repository = Layer.succeed(
166
+ ComposioToolkitsRepository,
167
+ makeToolkitsRepositoryStub({
168
+ createTrigger: () => Effect.fail(notFoundError('Trigger type not found')),
169
+ })
170
+ );
171
+ yield* cli(['dev', 'triggers', 'create', 'UNKNOWN_TRIGGER']).pipe(
172
+ Effect.provide(Layer.merge(repository, proc.layer))
173
+ );
174
+ const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
175
+
176
+ expect(output).toContain('Failed to create trigger "UNKNOWN_TRIGGER".');
177
+ expect(output).toContain('composio dev triggers list');
178
+ expect(output).not.toContain('Trigger created');
179
+ expect(proc.exitCode()).toBe(1);
180
})
181
);
182
}