-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for wildcard/unscoped channel/workspace event trigger def…
…initions. Fixes #222.
- Loading branch information
Filip Maj
committed
Apr 12, 2024
1 parent
0f1fee7
commit c7a5f45
Showing
3 changed files
with
276 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
262 changes: 226 additions & 36 deletions
262
src/typed-method-types/workflows/triggers/tests/event_test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,240 @@ | ||
import { assertEquals } from "../../../../dev_deps.ts"; | ||
import { TriggerTypes } from "../mod.ts"; | ||
import { SlackAPI } from "../../../../mod.ts"; | ||
import { SlackAPI, TriggerEventTypes, TriggerTypes } from "../../../../mod.ts"; | ||
import * as mf from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { event_response } from "./fixtures/sample_responses.ts"; | ||
import { ExampleWorkflow } from "./fixtures/workflows.ts"; | ||
import { EventTrigger } from "../event.ts"; | ||
|
||
Deno.test("Event triggers can set the type using the string", () => { | ||
const event: EventTrigger<ExampleWorkflow> = { | ||
type: "event", | ||
name: "test", | ||
workflow: "#/workflows/example", | ||
inputs: {}, | ||
event: { | ||
event_type: "slack#/events/reaction_added", | ||
channel_ids: ["C013ZG3K41Z"], | ||
Deno.test("Event trigger type tests", async (t) => { | ||
await t.step("Event triggers can set the type using the string", () => { | ||
const event: EventTrigger<ExampleWorkflow> = { | ||
type: "event", | ||
name: "test", | ||
workflow: "#/workflows/example", | ||
inputs: {}, | ||
event: { | ||
event_type: "slack#/events/reaction_added", | ||
channel_ids: ["C013ZG3K41Z"], | ||
}, | ||
}; | ||
assertEquals(event.type, TriggerTypes.Event); | ||
}); | ||
|
||
await t.step( | ||
"Event triggers can set the type using the TriggerTypes object", | ||
() => { | ||
const event: EventTrigger<ExampleWorkflow> = { | ||
type: TriggerTypes.Event, | ||
name: "test", | ||
workflow: "#/workflows/example", | ||
inputs: {}, | ||
event: { | ||
event_type: "slack#/events/reaction_added", | ||
channel_ids: ["C013ZG3K41Z"], | ||
}, | ||
}; | ||
assertEquals(event.type, TriggerTypes.Event); | ||
}, | ||
}; | ||
assertEquals(event.type, TriggerTypes.Event); | ||
}); | ||
); | ||
|
||
Deno.test("Event triggers can set the type using the TriggerTypes object", () => { | ||
const event: EventTrigger<ExampleWorkflow> = { | ||
type: TriggerTypes.Event, | ||
name: "test", | ||
workflow: "#/workflows/example", | ||
inputs: {}, | ||
event: { | ||
event_type: "slack#/events/reaction_added", | ||
channel_ids: ["C013ZG3K41Z"], | ||
await t.step( | ||
"shared_channel_invite_* event triggers do not require channel_ids", | ||
() => { | ||
const event: EventTrigger<ExampleWorkflow> = { | ||
type: TriggerTypes.Event, | ||
name: "test", | ||
workflow: "#/workflows/example", | ||
inputs: {}, | ||
event: { | ||
event_type: TriggerEventTypes.SharedChannelInviteAccepted, | ||
}, | ||
}; | ||
assertEquals(event.type, TriggerTypes.Event); | ||
}, | ||
}; | ||
assertEquals(event.type, TriggerTypes.Event); | ||
}); | ||
); | ||
|
||
Deno.test("shared_channel_invite_* event triggers do not require channel_ids", () => { | ||
const event: EventTrigger<ExampleWorkflow> = { | ||
type: TriggerTypes.Event, | ||
name: "test", | ||
workflow: "#/workflows/example", | ||
inputs: {}, | ||
event: { | ||
event_type: "slack#/events/shared_channel_invite_accepted", | ||
await t.step( | ||
"can define a channel-scoped event with `channel_ids`", | ||
() => { | ||
const event: EventTrigger<ExampleWorkflow> = { | ||
type: TriggerTypes.Event, | ||
name: "test", | ||
workflow: "#/workflows/example", | ||
inputs: {}, | ||
event: { | ||
event_type: TriggerEventTypes.ReactionAdded, | ||
channel_ids: ["C1234"], | ||
}, | ||
}; | ||
const _event2: EventTrigger<ExampleWorkflow> = { | ||
type: TriggerTypes.Event, | ||
name: "test", | ||
workflow: "#/workflows/example", | ||
inputs: {}, | ||
event: { | ||
event_type: TriggerEventTypes.ReactionAdded, | ||
channel_ids: ["C1234"], | ||
all_resources: false, | ||
}, | ||
}; | ||
assertEquals(event.type, TriggerTypes.Event); | ||
}, | ||
); | ||
|
||
await t.step( | ||
"can define a channel-unscoped event with `all_resources`", | ||
() => { | ||
const event: EventTrigger<ExampleWorkflow> = { | ||
type: TriggerTypes.Event, | ||
name: "test", | ||
workflow: "#/workflows/example", | ||
inputs: {}, | ||
event: { | ||
event_type: TriggerEventTypes.ReactionAdded, | ||
all_resources: true, | ||
}, | ||
}; | ||
assertEquals(event.type, TriggerTypes.Event); | ||
}, | ||
); | ||
|
||
await t.step( | ||
"channel event types must provide one of `all_resources:true` or `channel_ids`", | ||
() => { | ||
const event: EventTrigger<ExampleWorkflow> = { | ||
type: TriggerTypes.Event, | ||
name: "test", | ||
workflow: "#/workflows/example", | ||
inputs: {}, | ||
// @ts-expect-error requires one of `all_resources:true` or `channel_ids` | ||
event: { | ||
event_type: TriggerEventTypes.ReactionAdded, | ||
}, | ||
}; | ||
const _event2: EventTrigger<ExampleWorkflow> = { | ||
type: TriggerTypes.Event, | ||
name: "test", | ||
workflow: "#/workflows/example", | ||
inputs: {}, | ||
// @ts-expect-error requires one of `all_resources:true` or `channel_ids` | ||
event: { | ||
event_type: TriggerEventTypes.ReactionAdded, | ||
all_resources: false, | ||
}, | ||
}; | ||
assertEquals(event.type, TriggerTypes.Event); | ||
}, | ||
); | ||
|
||
await t.step( | ||
"channel event types must not provide both `all_resources:true` and `channel_ids`", | ||
() => { | ||
const event: EventTrigger<ExampleWorkflow> = { | ||
type: TriggerTypes.Event, | ||
name: "test", | ||
workflow: "#/workflows/example", | ||
inputs: {}, | ||
// @ts-expect-error cannot provide both `all_resources` and `channel_ids` | ||
event: { | ||
event_type: TriggerEventTypes.ReactionAdded, | ||
all_resources: true, | ||
channel_ids: ["C1234"], | ||
}, | ||
}; | ||
assertEquals(event.type, TriggerTypes.Event); | ||
}, | ||
); | ||
|
||
await t.step( | ||
"can define a workspace-scoped event with `team_ids`", | ||
() => { | ||
const event: EventTrigger<ExampleWorkflow> = { | ||
type: TriggerTypes.Event, | ||
name: "test", | ||
workflow: "#/workflows/example", | ||
inputs: {}, | ||
event: { | ||
event_type: TriggerEventTypes.UserJoinedTeam, | ||
team_ids: ["T1234"], | ||
}, | ||
}; | ||
const _event2: EventTrigger<ExampleWorkflow> = { | ||
type: TriggerTypes.Event, | ||
name: "test", | ||
workflow: "#/workflows/example", | ||
inputs: {}, | ||
event: { | ||
event_type: TriggerEventTypes.UserJoinedTeam, | ||
team_ids: ["T1234"], | ||
all_resources: false, | ||
}, | ||
}; | ||
assertEquals(event.type, TriggerTypes.Event); | ||
}, | ||
); | ||
|
||
await t.step( | ||
"can define a workspace-unscoped event with `all_resources:true` or by omitting `all_resources`", | ||
() => { | ||
const event: EventTrigger<ExampleWorkflow> = { | ||
type: TriggerTypes.Event, | ||
name: "test", | ||
workflow: "#/workflows/example", | ||
inputs: {}, | ||
event: { | ||
event_type: TriggerEventTypes.DndUpdated, | ||
all_resources: true, | ||
}, | ||
}; | ||
const _event2: EventTrigger<ExampleWorkflow> = { | ||
type: TriggerTypes.Event, | ||
name: "test", | ||
workflow: "#/workflows/example", | ||
inputs: {}, | ||
event: { | ||
event_type: TriggerEventTypes.DndUpdated, | ||
}, | ||
}; | ||
assertEquals(event.type, TriggerTypes.Event); | ||
}, | ||
); | ||
|
||
await t.step( | ||
"workspace event types must provide `team_ids` if `all_resources:false`", | ||
() => { | ||
const event: EventTrigger<ExampleWorkflow> = { | ||
type: TriggerTypes.Event, | ||
name: "test", | ||
workflow: "#/workflows/example", | ||
inputs: {}, | ||
// @ts-expect-error if `all_resources:false` then `team_ids` is required | ||
event: { | ||
event_type: TriggerEventTypes.UserJoinedTeam, | ||
all_resources: false, | ||
}, | ||
}; | ||
assertEquals(event.type, TriggerTypes.Event); | ||
}, | ||
); | ||
|
||
await t.step( | ||
"workspace event types must not provide both `all_resources:true` and `team_ids`", | ||
() => { | ||
const event: EventTrigger<ExampleWorkflow> = { | ||
type: TriggerTypes.Event, | ||
name: "test", | ||
workflow: "#/workflows/example", | ||
inputs: {}, | ||
// @ts-expect-error cannot provide both `all_resources` and `team_ids` | ||
event: { | ||
event_type: TriggerEventTypes.UserJoinedTeam, | ||
all_resources: true, | ||
team_ids: ["T1234"], | ||
}, | ||
}; | ||
assertEquals(event.type, TriggerTypes.Event); | ||
}, | ||
}; | ||
assertEquals(event.type, TriggerTypes.Event); | ||
); | ||
}); | ||
|
||
Deno.test("Mock call for event", async (t) => { | ||
|