-
Notifications
You must be signed in to change notification settings - Fork 395
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
Fix message actions #202
Fix message actions #202
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
// tslint:disable:no-implicit-dependencies | ||
import 'mocha'; | ||
import { assert } from 'chai'; | ||
import { getTypeAndConversation, IncomingEventType } from './helpers'; | ||
|
||
describe('getTypeAndConversation()', () => { | ||
describe('event types', () => { | ||
// Arrange | ||
const conversationId = 'CONVERSATION_ID'; | ||
const dummyEventBody = { | ||
event: { | ||
type: 'app_home_opened', | ||
channel: conversationId, | ||
event_ts: 'EVENT_TS', | ||
}, | ||
}; | ||
|
||
it('should find Event type for generic event', () => { | ||
// Act | ||
const typeAndConversation = getTypeAndConversation(dummyEventBody); | ||
|
||
// Assert | ||
assert(typeAndConversation.type === IncomingEventType.Event); | ||
assert(typeAndConversation.conversationId === conversationId); | ||
}); | ||
}); | ||
|
||
describe('command types', () => { | ||
// Arrange | ||
const conversationId = 'CONVERSATION_ID'; | ||
const dummyCommandBody = { | ||
command: 'COMMAND_NAME', | ||
channel_id: conversationId, | ||
response_url: 'https://hooks.slack.com/commands/RESPONSE_URL', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i don't think |
||
}; | ||
|
||
it('should find Command type for generic command', () => { | ||
// Act | ||
const typeAndConversation = getTypeAndConversation(dummyCommandBody); | ||
|
||
// Assert | ||
assert(typeAndConversation.type === IncomingEventType.Command); | ||
assert(typeAndConversation.conversationId === conversationId); | ||
}); | ||
}); | ||
|
||
describe('options types', () => { | ||
// Arrange | ||
const conversationId = 'CONVERSATION_ID'; | ||
const dummyActionBodies = createFakeOptions(conversationId); | ||
|
||
dummyActionBodies.forEach((option) => { | ||
it(`should find Option type for ${option.type}`, () => { | ||
// Act | ||
const typeAndConversation = getTypeAndConversation(option); | ||
|
||
// Assert | ||
assert(typeAndConversation.type === IncomingEventType.Options); | ||
assert(typeAndConversation.conversationId === conversationId); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('action types', () => { | ||
// Arrange | ||
const conversationId = 'CONVERSATION_ID'; | ||
const dummyActionBodies = createFakeActions(conversationId); | ||
|
||
dummyActionBodies.forEach((action) => { | ||
it(`should find Action type for ${action.type}`, () => { | ||
// Act | ||
const typeAndConversation = getTypeAndConversation(action); | ||
|
||
// Assert | ||
assert(typeAndConversation.type === IncomingEventType.Action); | ||
assert(typeAndConversation.conversationId === conversationId); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('invalid events', () => { | ||
// Arrange | ||
const fakeEventBody = { | ||
fake: 'THIS_IS_FAKE', | ||
channel: { id: 'FAKE_CONVERSATION_ID' }, | ||
}; | ||
|
||
it('should not find type for invalid event', () => { | ||
// Act | ||
const typeAndConversation = getTypeAndConversation(fakeEventBody); | ||
|
||
// Assert | ||
assert.isEmpty(typeAndConversation); | ||
}); | ||
}); | ||
}); | ||
|
||
function createFakeActions(conversationId: string): any[] { | ||
return [ | ||
// Body for a message action | ||
{ | ||
type: 'message_action', | ||
channel: { id: conversationId }, | ||
callback_id: 'CALLBACK_ID', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i don't think a |
||
}, | ||
// Body for a dialog submission | ||
{ | ||
type: 'dialog_submission', | ||
channel: { id: conversationId }, | ||
callback_id: 'CALLBACK_ID', | ||
submission: { KEY: 'VALUE' }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i don't think a |
||
}, | ||
// Body for an action within an interactive message | ||
{ | ||
type: 'interactive_message', | ||
channel: { id: conversationId }, | ||
callback_id: 'CALLBACK_ID', | ||
actions: [ | ||
{ | ||
type: 'button', | ||
name: 'NAME', | ||
value: 'VALUE', | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i don't think a |
||
], | ||
}, | ||
// Body for an action within a block | ||
{ | ||
type: 'block_actions', | ||
channel: { id: conversationId }, | ||
actions: [ | ||
{ | ||
type: 'static_select', | ||
selected_option: { | ||
text: { | ||
type: 'plain_text', | ||
text: 'ELEMENT_TEXT', | ||
}, | ||
value: 'VALUE', | ||
}, | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i don't think a real value for the first action (as long as there is something in the array) is necessary. |
||
], | ||
}, | ||
]; | ||
} | ||
|
||
function createFakeOptions(conversationId: string): any[] { | ||
return [ | ||
// Body for an options request in an interactive message | ||
{ | ||
type: 'interactive_message', | ||
channel: { id: conversationId }, | ||
name: 'OPTIONS_NAME', | ||
}, | ||
// Body for an options request in a dialog | ||
{ | ||
type: 'dialog_suggestion', | ||
channel: { id: conversationId }, | ||
name: 'OPTIONS_NAME', | ||
}, | ||
// Body for an action within a block | ||
{ | ||
type: 'block_suggestion', | ||
channel: { id: conversationId }, | ||
action_id: 'ACTION_ID', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i don't think the |
||
}, | ||
]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think
type
orevent_ts
are technically needed for the tests to succeed. right?