@slates/test 1.0.0-rc.3 → 1.0.0-rc.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config.cjs +31 -0
- package/dist/config.d.cts +6 -0
- package/dist/config.d.ts +6 -0
- package/dist/config.module.js +6 -0
- package/dist/index.cjs +68 -17
- package/dist/index.d.cts +44 -5
- package/dist/index.d.ts +44 -5
- package/dist/index.module.js +65 -17
- package/package.json +17 -9
- package/src/config.ts +5 -0
- package/src/index.test.ts +148 -3
- package/src/index.ts +1 -332
- package/src/runtime.ts +395 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slates/test",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.5",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -15,10 +15,18 @@
|
|
|
15
15
|
"type": "module",
|
|
16
16
|
"source": "src/index.ts",
|
|
17
17
|
"exports": {
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"require": "./dist/index.cjs",
|
|
21
|
+
"import": "./dist/index.module.js",
|
|
22
|
+
"default": "./dist/index.module.js"
|
|
23
|
+
},
|
|
24
|
+
"./config": {
|
|
25
|
+
"types": "./dist/config.d.ts",
|
|
26
|
+
"require": "./dist/config.cjs",
|
|
27
|
+
"import": "./dist/config.module.js",
|
|
28
|
+
"default": "./dist/config.module.js"
|
|
29
|
+
}
|
|
22
30
|
},
|
|
23
31
|
"main": "./dist/index.cjs",
|
|
24
32
|
"module": "./dist/index.module.js",
|
|
@@ -27,16 +35,16 @@
|
|
|
27
35
|
"scripts": {
|
|
28
36
|
"test": "vitest run --passWithNoTests",
|
|
29
37
|
"lint": "prettier src/**/*.ts --check",
|
|
30
|
-
"build": "tsup --config
|
|
38
|
+
"build": "tsup --config tsup.config.ts",
|
|
31
39
|
"typecheck": "tsc --noEmit"
|
|
32
40
|
},
|
|
33
41
|
"dependencies": {
|
|
34
42
|
"@lowerdeck/testing-tools": "latest",
|
|
35
|
-
"@slates/client": "1.0.0-rc.
|
|
36
|
-
"@slates/profiles": "1.0.0-rc.
|
|
43
|
+
"@slates/client": "1.0.0-rc.7",
|
|
44
|
+
"@slates/profiles": "1.0.0-rc.5"
|
|
37
45
|
},
|
|
38
46
|
"devDependencies": {
|
|
39
|
-
"@slates/provider": "1.0.0-rc.
|
|
47
|
+
"@slates/provider": "1.0.0-rc.11",
|
|
40
48
|
"@slates/tsconfig": "1.0.0-rc.1",
|
|
41
49
|
"typescript": "5.8.2",
|
|
42
50
|
"vitest": "^3.1.2",
|
package/src/config.ts
ADDED
package/src/index.test.ts
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
handleSlateTriggerWebhook,
|
|
22
22
|
loadSlatesRuntimeContext,
|
|
23
23
|
mapSlateTriggerEvent,
|
|
24
|
+
pollSlateTriggerEvents,
|
|
24
25
|
registerSlateTriggerWebhook,
|
|
25
26
|
unregisterSlateTriggerWebhook
|
|
26
27
|
} from './index';
|
|
@@ -39,6 +40,7 @@ afterEach(async () => {
|
|
|
39
40
|
delete process.env.SLATES_INTEGRATION;
|
|
40
41
|
delete process.env.SLATES_PROFILE_ID;
|
|
41
42
|
delete process.env.SLATES_STORE_PATH;
|
|
43
|
+
delete process.env.SLATES_STORE_ROOT_DIR;
|
|
42
44
|
delete process.env.SLATES_TEST_CONTEXT_PATH;
|
|
43
45
|
await Promise.all(tempDirs.splice(0).map(dir => rm(dir, { recursive: true, force: true })));
|
|
44
46
|
});
|
|
@@ -224,10 +226,41 @@ let createDemoSlate = () => {
|
|
|
224
226
|
})
|
|
225
227
|
.build();
|
|
226
228
|
|
|
229
|
+
let pollEcho = SlateTrigger.create(spec, {
|
|
230
|
+
key: 'poll_echo',
|
|
231
|
+
name: 'Poll Echo'
|
|
232
|
+
})
|
|
233
|
+
.input(
|
|
234
|
+
z.object({
|
|
235
|
+
value: z.string()
|
|
236
|
+
})
|
|
237
|
+
)
|
|
238
|
+
.output(
|
|
239
|
+
z.object({
|
|
240
|
+
echoed: z.string()
|
|
241
|
+
})
|
|
242
|
+
)
|
|
243
|
+
.polling({
|
|
244
|
+
pollEvents: async ctx => ({
|
|
245
|
+
inputs: ctx.input.state?.seen ? [] : [{ value: 'poll-value' }],
|
|
246
|
+
updatedState: {
|
|
247
|
+
seen: true
|
|
248
|
+
}
|
|
249
|
+
}),
|
|
250
|
+
handleEvent: async ctx => ({
|
|
251
|
+
type: 'demo.poll',
|
|
252
|
+
id: `poll-${ctx.input.value}`,
|
|
253
|
+
output: {
|
|
254
|
+
echoed: ctx.input.value
|
|
255
|
+
}
|
|
256
|
+
})
|
|
257
|
+
})
|
|
258
|
+
.build();
|
|
259
|
+
|
|
227
260
|
return Slate.create({
|
|
228
261
|
spec,
|
|
229
262
|
tools: [echo, fail, attachmentEcho, downloadLink],
|
|
230
|
-
triggers: [webhookEcho]
|
|
263
|
+
triggers: [webhookEcho, pollEcho]
|
|
231
264
|
});
|
|
232
265
|
};
|
|
233
266
|
|
|
@@ -272,6 +305,66 @@ describe('@slates/test', () => {
|
|
|
272
305
|
expect(context.storePath).toBe(store.storePath);
|
|
273
306
|
});
|
|
274
307
|
|
|
308
|
+
it('loads only the selected auth method from the runtime context', async () => {
|
|
309
|
+
let cwd = await createTempDir();
|
|
310
|
+
let store = await openSlatesCliStore({
|
|
311
|
+
cwd,
|
|
312
|
+
scope: {
|
|
313
|
+
key: 'integrations/demo',
|
|
314
|
+
name: 'demo'
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
let profile = store.upsertProfile({
|
|
318
|
+
name: 'Demo',
|
|
319
|
+
target: {
|
|
320
|
+
type: 'local',
|
|
321
|
+
entry: './demo-slate.mjs',
|
|
322
|
+
exportName: 'provider'
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
store.upsertAuth(profile.id, {
|
|
326
|
+
authMethodId: 'oauth',
|
|
327
|
+
authMethodName: 'Bot OAuth',
|
|
328
|
+
authType: 'auth.oauth',
|
|
329
|
+
input: {},
|
|
330
|
+
output: {
|
|
331
|
+
token: 'bot-token'
|
|
332
|
+
},
|
|
333
|
+
scopes: ['chat:write']
|
|
334
|
+
});
|
|
335
|
+
store.upsertAuth(profile.id, {
|
|
336
|
+
authMethodId: 'user_oauth',
|
|
337
|
+
authMethodName: 'User OAuth',
|
|
338
|
+
authType: 'auth.oauth',
|
|
339
|
+
input: {},
|
|
340
|
+
output: {
|
|
341
|
+
token: 'user-token'
|
|
342
|
+
},
|
|
343
|
+
scopes: ['search:read']
|
|
344
|
+
});
|
|
345
|
+
await store.save();
|
|
346
|
+
|
|
347
|
+
let runtimeContextPath = path.join(cwd, 'runtime.json');
|
|
348
|
+
await writeFile(
|
|
349
|
+
runtimeContextPath,
|
|
350
|
+
JSON.stringify({
|
|
351
|
+
integration: 'integrations/demo',
|
|
352
|
+
profileId: profile.id,
|
|
353
|
+
authMethodId: 'user_oauth',
|
|
354
|
+
storePath: store.storePath,
|
|
355
|
+
cliDir: store.dirPath
|
|
356
|
+
}),
|
|
357
|
+
'utf-8'
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
process.env.SLATES_TEST_CONTEXT_PATH = runtimeContextPath;
|
|
361
|
+
|
|
362
|
+
let context = await loadSlatesRuntimeContext({ cwd });
|
|
363
|
+
expect(context.authMethodId).toBe('user_oauth');
|
|
364
|
+
expect(Object.keys(context.profile?.auth ?? {})).toEqual(['user_oauth']);
|
|
365
|
+
expect(context.profile?.auth.user_oauth?.output.token).toBe('user-token');
|
|
366
|
+
});
|
|
367
|
+
|
|
275
368
|
it('creates local slate clients and asserts provider contracts', async () => {
|
|
276
369
|
let client = createLocalSlateTestClient({
|
|
277
370
|
slate: createDemoSlate(),
|
|
@@ -296,7 +389,7 @@ describe('@slates/test', () => {
|
|
|
296
389
|
description: 'A tiny test slate'
|
|
297
390
|
},
|
|
298
391
|
toolIds: ['echo', 'fail', 'attachment_echo', 'download_link'],
|
|
299
|
-
triggerIds: ['webhook_echo'],
|
|
392
|
+
triggerIds: ['webhook_echo', 'poll_echo'],
|
|
300
393
|
authMethodIds: ['token_auth'],
|
|
301
394
|
tools: [
|
|
302
395
|
{ id: 'echo', readOnly: false, destructive: false },
|
|
@@ -304,7 +397,10 @@ describe('@slates/test', () => {
|
|
|
304
397
|
{ id: 'attachment_echo', readOnly: true, destructive: false },
|
|
305
398
|
{ id: 'download_link', readOnly: true, destructive: false }
|
|
306
399
|
],
|
|
307
|
-
triggers: [
|
|
400
|
+
triggers: [
|
|
401
|
+
{ id: 'webhook_echo', invocationType: 'webhook' },
|
|
402
|
+
{ id: 'poll_echo', invocationType: 'polling' }
|
|
403
|
+
]
|
|
308
404
|
});
|
|
309
405
|
|
|
310
406
|
expect(contract.configSchema.properties.prefix.type).toBe('string');
|
|
@@ -431,4 +527,53 @@ describe('@slates/test', () => {
|
|
|
431
527
|
{ code: 'internal.unexpected', kind: 'internal', status: 500 }
|
|
432
528
|
);
|
|
433
529
|
});
|
|
530
|
+
|
|
531
|
+
it('wraps trigger polling flows', async () => {
|
|
532
|
+
let client = createLocalSlateTestClient({
|
|
533
|
+
slate: createDemoSlate(),
|
|
534
|
+
state: {
|
|
535
|
+
config: {
|
|
536
|
+
prefix: 'Hi'
|
|
537
|
+
},
|
|
538
|
+
auth: {
|
|
539
|
+
authenticationMethodId: 'token_auth',
|
|
540
|
+
output: {
|
|
541
|
+
token: 'secret-token'
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
|
|
547
|
+
let initialPoll = await pollSlateTriggerEvents({
|
|
548
|
+
client,
|
|
549
|
+
triggerId: 'poll_echo'
|
|
550
|
+
});
|
|
551
|
+
expect(initialPoll).toMatchObject({
|
|
552
|
+
inputs: [{ value: 'poll-value' }],
|
|
553
|
+
updatedState: {
|
|
554
|
+
seen: true
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
let mapped = await mapSlateTriggerEvent({
|
|
559
|
+
client,
|
|
560
|
+
triggerId: 'poll_echo',
|
|
561
|
+
input: initialPoll.inputs[0]!,
|
|
562
|
+
type: 'demo.poll',
|
|
563
|
+
output: {
|
|
564
|
+
echoed: 'poll-value'
|
|
565
|
+
}
|
|
566
|
+
});
|
|
567
|
+
expect(mapped.id).toBe('poll-poll-value');
|
|
568
|
+
|
|
569
|
+
let repeatedPoll = await pollSlateTriggerEvents({
|
|
570
|
+
client,
|
|
571
|
+
triggerId: 'poll_echo',
|
|
572
|
+
state: initialPoll.updatedState
|
|
573
|
+
});
|
|
574
|
+
expect(repeatedPoll.inputs).toEqual([]);
|
|
575
|
+
expect(repeatedPoll.updatedState).toEqual({
|
|
576
|
+
seen: true
|
|
577
|
+
});
|
|
578
|
+
});
|
|
434
579
|
});
|
package/src/index.ts
CHANGED
|
@@ -1,332 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
createLocalSlateTransport,
|
|
4
|
-
createSlatesClient,
|
|
5
|
-
SlateProtocolError
|
|
6
|
-
} from '@slates/client';
|
|
7
|
-
import type { SlatesProtocolClientOptions } from '@slates/client';
|
|
8
|
-
import {
|
|
9
|
-
createSlatesClientFromProfile,
|
|
10
|
-
openSlatesCliStore,
|
|
11
|
-
SlatesProfileRecord
|
|
12
|
-
} from '@slates/profiles';
|
|
13
|
-
import { readFile } from 'fs/promises';
|
|
14
|
-
|
|
15
|
-
export interface SlatesRuntimeContext {
|
|
16
|
-
integration: string | null;
|
|
17
|
-
profileId: string | null;
|
|
18
|
-
profile: SlatesProfileRecord | null;
|
|
19
|
-
storePath: string;
|
|
20
|
-
cliDir: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export type SlatesTestClient = ReturnType<typeof createSlatesClient>;
|
|
24
|
-
|
|
25
|
-
type LocalSlate = Parameters<typeof createLocalSlateTransport>[0]['slate'];
|
|
26
|
-
|
|
27
|
-
export interface ExpectedSlateAction {
|
|
28
|
-
id: string;
|
|
29
|
-
name?: string;
|
|
30
|
-
description?: string;
|
|
31
|
-
readOnly?: boolean;
|
|
32
|
-
destructive?: boolean;
|
|
33
|
-
invocationType?: 'polling' | 'webhook';
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
let getExpect = () => {
|
|
37
|
-
let maybeExpect = (globalThis as typeof globalThis & { expect?: typeof import('vitest').expect })
|
|
38
|
-
.expect;
|
|
39
|
-
|
|
40
|
-
if (!maybeExpect) {
|
|
41
|
-
throw new Error('Vitest expect is not available in the current runtime.');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return maybeExpect;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export let loadSlatesRuntimeContext = async (
|
|
48
|
-
opts: {
|
|
49
|
-
cwd?: string;
|
|
50
|
-
profile?: string | null;
|
|
51
|
-
} = {}
|
|
52
|
-
): Promise<SlatesRuntimeContext> => {
|
|
53
|
-
let runtimeContextPath = process.env.SLATES_TEST_CONTEXT_PATH;
|
|
54
|
-
if (runtimeContextPath) {
|
|
55
|
-
let raw = await readFile(runtimeContextPath, 'utf-8');
|
|
56
|
-
let parsed = JSON.parse(raw) as {
|
|
57
|
-
integration?: string | null;
|
|
58
|
-
profileId: string | null;
|
|
59
|
-
storePath: string;
|
|
60
|
-
cliDir: string;
|
|
61
|
-
};
|
|
62
|
-
let store = await openSlatesCliStore({ storePath: parsed.storePath });
|
|
63
|
-
let profile = store.getProfile(opts.profile ?? parsed.profileId ?? null);
|
|
64
|
-
|
|
65
|
-
return {
|
|
66
|
-
integration: parsed.integration ?? store.scope?.key ?? null,
|
|
67
|
-
profileId: profile?.id ?? parsed.profileId ?? null,
|
|
68
|
-
profile,
|
|
69
|
-
storePath: parsed.storePath,
|
|
70
|
-
cliDir: parsed.cliDir
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
let store = process.env.SLATES_STORE_PATH
|
|
75
|
-
? await openSlatesCliStore({ storePath: process.env.SLATES_STORE_PATH })
|
|
76
|
-
: await openSlatesCliStore({ cwd: opts.cwd });
|
|
77
|
-
let profileId = opts.profile ?? process.env.SLATES_PROFILE_ID ?? null;
|
|
78
|
-
let profile = store.getProfile(profileId);
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
integration: process.env.SLATES_INTEGRATION ?? store.scope?.key ?? null,
|
|
82
|
-
profileId: profile?.id ?? null,
|
|
83
|
-
profile,
|
|
84
|
-
storePath: store.storePath,
|
|
85
|
-
cliDir: store.dirPath
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
export let loadSlatesProfile = async (
|
|
90
|
-
opts: { cwd?: string; profile?: string | null } = {}
|
|
91
|
-
) => {
|
|
92
|
-
let context = await loadSlatesRuntimeContext(opts);
|
|
93
|
-
if (!context.profile) {
|
|
94
|
-
throw new Error('No Slates profile is available for the current test context.');
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return context.profile;
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
export let createSlatesTestClient = async (
|
|
101
|
-
opts: { cwd?: string; profile?: string | null } = {}
|
|
102
|
-
) => {
|
|
103
|
-
let context = await loadSlatesRuntimeContext(opts);
|
|
104
|
-
if (!context.profile) {
|
|
105
|
-
throw new Error('No Slates profile is available for the current test context.');
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
let store = await openSlatesCliStore({ storePath: context.storePath });
|
|
109
|
-
return createSlatesClientFromProfile(context.profile, { cwd: opts.cwd, store });
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
export let withSlateProfile = async <T>(
|
|
113
|
-
profileName: string | null | undefined,
|
|
114
|
-
cb: (ctx: { profile: SlatesProfileRecord }) => Promise<T>
|
|
115
|
-
) => {
|
|
116
|
-
let profile = await loadSlatesProfile({ profile: profileName });
|
|
117
|
-
return cb({ profile });
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
export let expectToolCall = async (d: {
|
|
121
|
-
client?: Awaited<ReturnType<typeof createSlatesTestClient>>;
|
|
122
|
-
profile?: string | null;
|
|
123
|
-
toolId: string;
|
|
124
|
-
input: Record<string, any>;
|
|
125
|
-
output?: Record<string, any>;
|
|
126
|
-
}) => {
|
|
127
|
-
let expect = getExpect();
|
|
128
|
-
let client = d.client ?? (await createSlatesTestClient({ profile: d.profile }));
|
|
129
|
-
let result = await client.invokeTool(d.toolId, d.input);
|
|
130
|
-
|
|
131
|
-
if (d.output) {
|
|
132
|
-
expect(result.output).toMatchObject(d.output);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return result;
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
export let createLocalSlateTestClient = (opts: {
|
|
139
|
-
slate: LocalSlate;
|
|
140
|
-
state?: SlatesProtocolClientOptions['state'];
|
|
141
|
-
participants?: SlatesProtocolClientOptions['participants'];
|
|
142
|
-
}) =>
|
|
143
|
-
createSlatesClient({
|
|
144
|
-
transport: createLocalSlateTransport({ slate: opts.slate }),
|
|
145
|
-
state: opts.state,
|
|
146
|
-
participants: opts.participants
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
export let getSlateContract = async (client: SlatesTestClient) => {
|
|
150
|
-
let [provider, actions, authMethods, configSchema] = await Promise.all([
|
|
151
|
-
client.identify(),
|
|
152
|
-
client.listActions(),
|
|
153
|
-
client.listAuthMethods(),
|
|
154
|
-
client.getConfigSchema()
|
|
155
|
-
]);
|
|
156
|
-
|
|
157
|
-
return {
|
|
158
|
-
provider: provider.provider,
|
|
159
|
-
actions: actions.actions,
|
|
160
|
-
tools: actions.actions.filter(action => action.type === 'action.tool'),
|
|
161
|
-
triggers: actions.actions.filter(action => action.type === 'action.trigger'),
|
|
162
|
-
authMethods: authMethods.authenticationMethods,
|
|
163
|
-
configSchema: configSchema.schema
|
|
164
|
-
};
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
let expectActionMatches = (actual: Record<string, any> | undefined, expected: ExpectedSlateAction) => {
|
|
168
|
-
let expect = getExpect();
|
|
169
|
-
expect(actual).toBeTruthy();
|
|
170
|
-
expect(actual?.id).toBe(expected.id);
|
|
171
|
-
|
|
172
|
-
if (expected.name !== undefined) {
|
|
173
|
-
expect(actual?.name).toBe(expected.name);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (expected.description !== undefined) {
|
|
177
|
-
expect(actual?.description).toBe(expected.description);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
if (expected.readOnly !== undefined) {
|
|
181
|
-
expect(actual?.tags?.readOnly ?? false).toBe(expected.readOnly);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
if (expected.destructive !== undefined) {
|
|
185
|
-
expect(actual?.tags?.destructive ?? false).toBe(expected.destructive);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (expected.invocationType !== undefined) {
|
|
189
|
-
expect((actual as { invocation?: { type?: string } } | undefined)?.invocation?.type).toBe(
|
|
190
|
-
expected.invocationType
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
export let expectSlateContract = async (d: {
|
|
196
|
-
client: SlatesTestClient;
|
|
197
|
-
provider?: {
|
|
198
|
-
id: string;
|
|
199
|
-
name?: string;
|
|
200
|
-
description?: string;
|
|
201
|
-
};
|
|
202
|
-
toolIds?: string[];
|
|
203
|
-
triggerIds?: string[];
|
|
204
|
-
authMethodIds?: string[];
|
|
205
|
-
tools?: ExpectedSlateAction[];
|
|
206
|
-
triggers?: ExpectedSlateAction[];
|
|
207
|
-
}) => {
|
|
208
|
-
let expect = getExpect();
|
|
209
|
-
let contract = await getSlateContract(d.client);
|
|
210
|
-
|
|
211
|
-
if (d.provider) {
|
|
212
|
-
expect(contract.provider.id).toBe(d.provider.id);
|
|
213
|
-
if (d.provider.name !== undefined) {
|
|
214
|
-
expect(contract.provider.name).toBe(d.provider.name);
|
|
215
|
-
}
|
|
216
|
-
if (d.provider.description !== undefined) {
|
|
217
|
-
expect(contract.provider.description).toBe(d.provider.description);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
if (d.toolIds) {
|
|
222
|
-
expect(contract.tools.map(action => action.id)).toEqual(d.toolIds);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
if (d.triggerIds) {
|
|
226
|
-
expect(contract.triggers.map(action => action.id)).toEqual(d.triggerIds);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
if (d.authMethodIds) {
|
|
230
|
-
expect(contract.authMethods.map(method => method.id)).toEqual(d.authMethodIds);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
for (let tool of d.tools ?? []) {
|
|
234
|
-
expectActionMatches(contract.tools.find(action => action.id === tool.id), tool);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
for (let trigger of d.triggers ?? []) {
|
|
238
|
-
expectActionMatches(contract.triggers.find(action => action.id === trigger.id), trigger);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
return contract;
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
export let registerSlateTriggerWebhook = async (d: {
|
|
245
|
-
client: SlatesTestClient;
|
|
246
|
-
triggerId: string;
|
|
247
|
-
webhookBaseUrl: string;
|
|
248
|
-
}) => d.client.registerTriggerWebhook(d.triggerId, d.webhookBaseUrl);
|
|
249
|
-
|
|
250
|
-
export let handleSlateTriggerWebhook = async (d: {
|
|
251
|
-
client: SlatesTestClient;
|
|
252
|
-
triggerId: string;
|
|
253
|
-
url: string;
|
|
254
|
-
method?: string;
|
|
255
|
-
headers?: Record<string, string>;
|
|
256
|
-
body?: string | Uint8Array | null;
|
|
257
|
-
state?: any;
|
|
258
|
-
}) =>
|
|
259
|
-
d.client.handleTriggerWebhook({
|
|
260
|
-
actionId: d.triggerId,
|
|
261
|
-
url: d.url,
|
|
262
|
-
method: d.method ?? 'POST',
|
|
263
|
-
headers: d.headers,
|
|
264
|
-
body: d.body,
|
|
265
|
-
state: d.state
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
export let unregisterSlateTriggerWebhook = async (d: {
|
|
269
|
-
client: SlatesTestClient;
|
|
270
|
-
triggerId: string;
|
|
271
|
-
webhookBaseUrl: string;
|
|
272
|
-
registrationDetails: any;
|
|
273
|
-
state?: any;
|
|
274
|
-
}) =>
|
|
275
|
-
d.client.unregisterTriggerWebhook({
|
|
276
|
-
actionId: d.triggerId,
|
|
277
|
-
webhookBaseUrl: d.webhookBaseUrl,
|
|
278
|
-
registrationDetails: d.registrationDetails,
|
|
279
|
-
state: d.state
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
export let mapSlateTriggerEvent = async (d: {
|
|
283
|
-
client: SlatesTestClient;
|
|
284
|
-
triggerId: string;
|
|
285
|
-
input: Record<string, any>;
|
|
286
|
-
output?: Record<string, any>;
|
|
287
|
-
type?: string;
|
|
288
|
-
}) => {
|
|
289
|
-
let expect = getExpect();
|
|
290
|
-
let result = await d.client.mapTriggerEvent(d.triggerId, d.input);
|
|
291
|
-
|
|
292
|
-
if (d.type !== undefined) {
|
|
293
|
-
expect(result.type).toBe(d.type);
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
if (d.output) {
|
|
297
|
-
expect(result.output).toMatchObject(d.output);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
return result;
|
|
301
|
-
};
|
|
302
|
-
|
|
303
|
-
export let expectSlateError = async (
|
|
304
|
-
run: Promise<unknown> | (() => Promise<unknown>),
|
|
305
|
-
expected: Record<string, any> | string | RegExp
|
|
306
|
-
) => {
|
|
307
|
-
let expect = getExpect();
|
|
308
|
-
try {
|
|
309
|
-
await (typeof run === 'function' ? run() : run);
|
|
310
|
-
} catch (error) {
|
|
311
|
-
if (typeof expected === 'string' || expected instanceof RegExp) {
|
|
312
|
-
let message = error instanceof Error ? error.message : String(error);
|
|
313
|
-
if (expected instanceof RegExp) {
|
|
314
|
-
expect(message).toMatch(expected);
|
|
315
|
-
} else {
|
|
316
|
-
expect(message).toContain(expected);
|
|
317
|
-
}
|
|
318
|
-
} else if (error instanceof SlateProtocolError) {
|
|
319
|
-
expect(error.data).toMatchObject(expected);
|
|
320
|
-
} else {
|
|
321
|
-
expect(error).toMatchObject(expected);
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
return error;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
throw new Error('Expected the operation to fail, but it completed successfully.');
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
export let createSlatesVitestConfig = (
|
|
331
|
-
config: Parameters<typeof createVitestConfig>[0] = {}
|
|
332
|
-
) => createVitestConfig(config);
|
|
1
|
+
export * from './runtime';
|