From d7e6c640592a8d4d1df980a0d3943d9555cef74d Mon Sep 17 00:00:00 2001 From: Christopher Metz Date: Tue, 11 Jul 2017 15:17:56 -0700 Subject: [PATCH] Added ambient typings for typescript users --- README.md | 2 ++ index.d.ts | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 index.d.ts diff --git a/README.md b/README.md index d2267e6..4e8b49b 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,8 @@ That's why Slack Mock provides simple, synchronous methods to queue, trigger, an To write a Slack Mock integration test queue up responses from Slack to your bot, then use Slack Mock to send a message from Slack to your bot to trigger a bot action, wait some time, then assert that your bot made the correct calls to Slack in order. How long do you wait? It depends on what your bot is doing. Play around a little and see what works. I find a 50 millisecond wait is more than enough for most flows. +For Typescript users there are ambient tpyings included. + ## Usage See the [examples tests](examples/test) for full examples of mocking both a single-team RTM bot and a full diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..8d5b79c --- /dev/null +++ b/index.d.ts @@ -0,0 +1,88 @@ +declare module "slack-mock" { + interface INSTANCE { + events: EVENT, + incomingWebhooks: INCOMINGWEBHOOK, + interactiveButtons: INTERACTIVEBUTTON, + outgoingWebhooks: OUTGOINGWEBHOOK, + rtm?: RTM, + slashCommands: SLASHCOMMAND, + web: WEB, + reset(): void + } + + interface EVENT { + send(target: string, data: DATA): Promise, + reset(): void, + calls: any[] + } + + interface INCOMINGWEBHOOK { + addResponse(opts: OPTS): void, + reset(): void, + calls: any[] + } + + interface INTERACTIVEBUTTON { + addResponse(opts: OPTS): void, + send(target: string, data: DATA): Promise, + reset(): void, + calls: any[] + } + + interface OUTGOINGWEBHOOK { + send(targetUrl: string, outgoingBody: DATA): Promise, + reset(): void, + calls: any[] + } + + interface RTM { + send(token: string, message: MESSAGE): Promise, + reset(): void, + calls: any[], + startServer(token: string): void, + stopServer(token: string): Promise + } + + interface SLASHCOMMAND { + addResponse(opts: OPTS): void, + send(target: string, data: DATA): Promise, + reset(): void, + calls: any[] + } + + interface WEB { + addResponse(opts: OPTS): void, + reset(): void, + calls: any[] + } + + interface DATA { + token?: string, + team_id?: string, + team_domain?: string, + channel_id?: string, + channel_name?: string, + user_id?: string, + user_name?: string, + command?: string, + text?: string + } + + interface OPTS { + url?: string, + statusCode?: number, + status?: number, + body?: any, + headers?: any + } + + interface MESSAGE { + type: string, + channel: string, + user: string, + text: string + } + + function init(): INSTANCE; + export = init; +}