Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ambient typings for typescript users #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
88 changes: 88 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -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<any>,
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<any>,
reset(): void,
calls: any[]
}

interface OUTGOINGWEBHOOK {
send(targetUrl: string, outgoingBody: DATA): Promise<any>,
reset(): void,
calls: any[]
}

interface RTM {
send(token: string, message: MESSAGE): Promise<any>,
reset(): void,
calls: any[],
startServer(token: string): void,
stopServer(token: string): Promise<any>
}

interface SLASHCOMMAND {
addResponse(opts: OPTS): void,
send(target: string, data: DATA): Promise<any>,
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;
}