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

Add tests to verify incoming event type handler works #269

Merged
merged 6 commits into from
Oct 4, 2019
Merged
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
153 changes: 153 additions & 0 deletions src/App.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,159 @@ describe('App', () => {
return overrides;
}

describe('routing', () => {

function createReceiverEvents(): ReceiverEvent[] {
return [
{ // IncomingEventType.Event (app.event)
body: {
event: {},
},
respond: noop,
ack: noop,
},
{ // IncomingEventType.Command (app.command)
body: {
command: '/COMMAND_NAME',
},
respond: noop,
ack: noop,
},
{ // IncomingEventType.Action (app.action)
body: {
type: 'block_actions',
actions: [{
action_id: 'block_action_id'
}],
channel: {},
user: {},
team: {},
},
respond: noop,
ack: noop,
},
{ // IncomingEventType.Action (app.action)
body: {
type: 'message_action',
callback_id: 'message_action_callback_id',
channel: {},
user: {},
team: {},
},
respond: noop,
ack: noop,
},
{ // IncomingEventType.Action (app.action)
body: {
type: 'interactive_message',
callback_id: 'interactive_message_callback_id',
actions: [{}],
channel: {},
user: {},
team: {},
},
respond: noop,
ack: noop,
},
{ // IncomingEventType.Action with dialog submission (app.action)
body: {
type: 'dialog_submission',
callback_id: 'dialog_submission_callback_id',
channel: {},
user: {},
team: {},
},
respond: noop,
ack: noop,
},
{ // IncomingEventType.Action for an external_select block (app.options)
body: {
type: 'block_suggestion',
action_id: 'external_select_action_id',
channel: {},
user: {},
team: {},
actions: [],
},
respond: noop,
ack: noop,
},
{ // IncomingEventType.Action for "data_source": "external" in dialogs (app.options)
body: {
type: 'dialog_suggestion',
callback_id: 'dialog_suggestion_callback_id',
name: 'the name',
channel: {},
user: {},
team: {},
},
respond: noop,
ack: noop,
},
{ // IncomingEventType.ViewSubmitAction (app.view)
body: {
type: 'view_submission',
channel: {},
user: {},
team: {},
view: {
callback_id: 'view_callback_id',
}
},
respond: noop,
ack: noop,
},
// TODO: https://github.com/slackapi/bolt/issues/263
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shanedewael How about merging this PR before #276 and removing these comments out to verify your change works?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is a good idea!

// {
// body: {
// type: 'view_closed',
// channel: {},
// user: {},
// team: {},
// view: {
// callback_id: 'view_callback_id',
// }
// },
// respond: noop,
// ack: noop,
// },
];
}

it('should acknowledge any of possible events', async () => {
// Arrange
const ackFn = sinon.fake.resolves({});
const actionFn = sinon.fake.resolves({});
const viewFn = sinon.fake.resolves({});
const optionsFn = sinon.fake.resolves({});
const overrides = buildOverrides(withNoopWebClient());
const App = await importApp(overrides); // tslint:disable-line:variable-name
const dummyReceiverEvents = createReceiverEvents();

// Act
const app = new App({ receiver: fakeReceiver, authorize: sinon.fake.resolves(dummyAuthorizationResult) });
app.use((_args) => { ackFn(); });
app.action('block_action_id', ({ }) => { actionFn(); })
app.action({ callback_id: 'message_action_callback_id' }, ({ }) => { actionFn(); })
app.action({ callback_id: 'interactive_message_callback_id' }, ({ }) => { actionFn(); })
app.action({ callback_id: 'dialog_submission_callback_id' }, ({ }) => { actionFn(); })
app.view('view_callback_id', ({ }) => { viewFn(); })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add one for view_cancel? I can do this when we merge this before my branch lands.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shanedewael yes, we need to have it. I haven't added the one commented out yet as we didn't decide the design at that time.

app.options('external_select_action_id', ({ }) => { optionsFn(); });
app.options({ callback_id: 'dialog_suggestion_callback_id' }, ({ }) => { optionsFn(); });

app.error(fakeErrorHandler);
dummyReceiverEvents.forEach(dummyEvent => fakeReceiver.emit('message', dummyEvent));
await delay();

// Assert
assert.equal(actionFn.callCount, 4);
assert.equal(viewFn.callCount, 1);
assert.equal(optionsFn.callCount, 2);
assert.equal(ackFn.callCount, dummyReceiverEvents.length);
assert(fakeErrorHandler.notCalled);
});
});

describe('say()', () => {

function createChannelContextualReceiverEvents(channelId: string): ReceiverEvent[] {
Expand Down