npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@slack-wrench/fixtures

v2.2.4

Published

Slack api fixtures for testing

Downloads

425

Readme

Slack Fixtures

This package contains type-safe fixtures and application wrappers for testing slack applications.

Install

yarn add --dev @slack-wrench/fixtures
# or
npm install --save-dev @slack-wrench/fixtures

Usage

Currently, we only support a subset of Slack's Event's API. We're implementing them as we need them and hope to have others do the same.

Events

import { events } from '@slack-wrench/fixtures';

Messages

events.message(
  text: string,
  options: Partial<MessageEvent> = {},
)
// : MessageEvent => { text, user, ts, ... }

Creates a message event.

Arguments:

Returns: Object containing a message event

Slash Commands

import { slashCommand } from '@slack-wrench/fixtures';

slashCommand(
  command: string,
  options?: Partial<SlashCommand>,
)
// : SlashCommand => { command, user_id, team_id, ... }

Creates a slash command event.

Example:

// sending a text field
slashCommand('/command', { text: 'I just used a command!' });

Arguments:

Returns: Object containing a Slash Command event

Actions

import { actions } from '@slack-wrench/fixtures';

Block Button Action

actions.blockButtonAction(
  action?: Partial<ButtonAction>,
  options?: Partial<BlockButtonAction>,
)
// : BlockButtonAction => { type: 'block_actions', actions: [ { type: 'button', ...} ], user, ... }

Creates an event from a block button action.

Arguments:

  • action: Overrides to ButtonAction values (normally a subset of { action_id, block_id, value }
  • options: Any fields to override on the default BlockAction event

Returns: Object containing a block action event

View Submit Action

view.viewSubmitAction(
  view?: Partial<ViewOutput>,
  options?: Partial<BlockButtonAction>,
)
// : ViewSubmitAction => { type: 'view_submission', view: { id: 'editView', state: {}, ...} ], user, ... }

Creates an event from a view submit action.

Arguments:

Returns: Object containing a view submit action event

Global Fields

import { fields } from '@slack-wrench/fixtures';

The fields returned for all of the fixtures are set and accessible through fields . This can be really helpful when writing tests. It also enables you to change the fields if you need them to be specific.

Overriding

All of the fields used by fixtures can be overridden globally. This might be helpful if you need something like the team domain and id to be specific for your app.

// Here are a few examples of things you can change. This will affect all fixtures.

// Update the team id
fields.team.id = 'TANOTHERTEAM';
fields.team.domain = 'another-team';

// or as an object
fields.team = {
  id: 'TANOTHERTEAM',
  domain: 'another-team',
};

// Update the callback_id
fields.callback_id = 'FancyCallbackId';

If you want to reset the fields to their original values, you can call reset. This is potentially helpful in testing hooks.

beforeEach(() => {
  fields.reset();
});

Serverless Tester

import { ServerlessTester } from '@slack-wrench/fixtures';

A helper class for testing root level applications exposing slack endpoints.

import { ServerlessTester } from '@slack-wrench/fixtures';
import { App, ExpressReceiver } from '@slack/bolt';

const receiver = new ExpressReceiver({ signingSecret, endpoints });
const app = new App({ receiver, token });
handler = new ServerlessTester(receiver.app, signingSecret);

Arguments:

  • application: App to test, supports any framework that serverless-http does eg: Express and Koa
  • signingSecret: Secret to sign all requests with, this should be the same string your application uses to verify requests.

Send Slack Events

Use handler.sendSlackEvent to send Slack fixture events to your application.

const result = await handler.sendSlackEvent(slashCommand(command));
expect(result.statusCode).toEqual(200);

Arguments:

  • event: Fixture/Slack event to simulate.
  • path: a path to POST the event to, defaults to /slack/events, Bolt's default.

Send HTTP Requests

Use handler.sendHttp to send any http event to your application.

const result = await handler.sendHttp({
  body: 'How are you?',
  httpMethod: 'GET',
  path: '/',
});
expect(result.statusCode).toEqual(200);

Arguments:

  • event: Request event to simulate.
  • path: a path to POST the event to, defaults to /slack/events, Bolt's default.