-
Notifications
You must be signed in to change notification settings - Fork 1
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 bug with greeting [BOTKIT] #59
Merged
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
15863c6
Update botkit botkit-mock botbuilder-adapter-slack
nikitasakau 67e9bca
Used new botkit-mock in specs
nikitasakau 9fd64cd
Refactored tests in order to share the same controller
nikitasakau f910c47
Used for greeting queries plain strings
nikitasakau 32db95c
Parse greeting keys via regexp in order not to trigger on words which…
nikitasakau fce5696
Fixed tests styles, added test for fixed bug with greeting
nikitasakau d0f972a
Do not use Should in specs because it is useless
nikitasakau d379bef
Fixed warnings in spec removing SlackApiMock because it is useless
nikitasakau 744b0d6
Removed semicolons in spec helpers because we do not use them in othe…
nikitasakau eb9cfd4
Added Good afternoon as trigger for greeting because some people use it
nikitasakau 7dd236b
Removed useless imports in mention spec
nikitasakau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ module.exports = [ | |
'Hello', | ||
'Good morning', | ||
'G\'day', | ||
'\^Hi\$', | ||
'Hi', | ||
'Morning', | ||
'Hey', | ||
] |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,52 @@ | ||
const assert = require('assert') | ||
const Botmock = require('botkit-mock') | ||
|
||
const { getBasicController } = require('./helpers') | ||
const greetingController = require('../features/greeting') | ||
const replies = require('../features/greeting/replies.js') | ||
|
||
describe('Sample hears controller', () => { | ||
beforeEach(() => { | ||
this.controller = Botmock({}) | ||
this.bot = this.controller.spawn({ type: 'slack' }) | ||
this.controller = getBasicController() | ||
greetingController(this.controller) | ||
}) | ||
|
||
it( | ||
'Should return any greeting if user types `hi`', | ||
() => this.bot.usersInput([{ | ||
it('returns any greeting if user types `hi`', async () => { | ||
await this.controller.usersInput([{ | ||
type: 'message', | ||
channel: 'channel', | ||
messages: [{ | ||
text: 'hi', isAssertion: true, | ||
}], | ||
}]).then(message => assert(replies.includes(message.text))) | ||
) | ||
}) | ||
|
||
it('does not return any greeting if user types `Morning` in one line code block', async () => { | ||
await this.controller.usersInput([{ | ||
type: 'message', | ||
channel: 'channel', | ||
messages: [{ | ||
text: '`Morning`', isAssertion: true, | ||
}], | ||
}]).then(message => assert.deepEqual(message, {})) | ||
}) | ||
|
||
it( | ||
"Shouldn't return any greeting if user types hi in one line code block", | ||
() =>this.bot.usersInput([{ | ||
it('does not return any greeting if user types `Morning` in multiline code block', async () => { | ||
await this.controller.usersInput([{ | ||
type: 'message', | ||
channel: 'channel', | ||
messages: [{ | ||
text: '`hi`', isAssertion: true, | ||
text: '```Morning```', isAssertion: true, | ||
}], | ||
}]).then(message => assert.deepEqual(message, {})) | ||
) | ||
}) | ||
|
||
it( | ||
"Shouldn't return any greeting if user types hi in multiline code block", | ||
() => this.bot.usersInput([{ | ||
it('does not return any greeting if user types a word that includes greeting word', async () => { | ||
await this.controller.usersInput([{ | ||
type: 'message', | ||
channel: 'channel', | ||
messages: [{ | ||
text: '```hi```', isAssertion: true, | ||
text: 'they', isAssertion: true, | ||
}], | ||
}]).then(message => assert.deepEqual(message, {})) | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const { BotMock, SlackApiMock } = require('botkit-mock') | ||
const { SlackAdapter, SlackMessageTypeMiddleware, SlackEventMiddleware } = require('botbuilder-adapter-slack'); | ||
|
||
const { removeCodeFromMessage } = require('../../lib/middleware'); | ||
|
||
module.exports = () => { | ||
const adapter = new SlackAdapter({ | ||
clientSigningSecret: "secret", | ||
botToken: "token", | ||
debug: true | ||
}); | ||
|
||
adapter.use(new SlackEventMiddleware()) | ||
adapter.use(new SlackMessageTypeMiddleware()) | ||
|
||
const controller = new BotMock({ | ||
adapter: adapter, | ||
disable_webserver: true | ||
}); | ||
|
||
controller.middleware.ingest.use(removeCodeFromMessage) | ||
|
||
SlackApiMock.bindMockApi(controller) | ||
|
||
return controller | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const getBasicController = require('./getBasicController') | ||
|
||
module.exports = { | ||
getBasicController, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
const { BotMock, SlackApiMock } = require('botkit-mock') | ||
const assert = require('assert') | ||
const Botmock = require('botkit-mock') | ||
|
||
const { getBasicController } = require('./helpers') | ||
const mentionController = require('../features/mention.js') | ||
const replies = require('../features/mention/replies') | ||
const { removeCodeFromMessage } = require('../lib/middleware') | ||
|
||
describe('Mention controller', () => { | ||
beforeEach(() => { | ||
this.controller = Botmock({}) | ||
this.bot = this.controller.spawn({ type: 'slack' }) | ||
this.controller = getBasicController() | ||
mentionController(this.controller) | ||
}) | ||
|
||
it( | ||
'should return one of mention responds if user mentions bot', | ||
() => this.bot.usersInput([{ | ||
it('returns one of mention responds if user mentions bot', async () => { | ||
await this.controller.usersInput([{ | ||
type: 'direct_mention', | ||
channel: 'channel', | ||
messages: [{ | ||
text: 'bot', isAssertion: true, | ||
}], | ||
}]).then(message => assert(replies.includes(message.text))) | ||
) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
thoughts about moving this method to a helper method for tests? It's duplicated lot of times
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.
@AleksSenkou Do you mean
message => assert.deepEqual(message, {})
only or the wholeusersInput
?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.
@nikitasakov I'm thinking about:
thoughts?
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.
Why do you use await on promise?
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.
or:
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.
@lazycoder9 I did as in docs - https://github.com/gratifyguy/botkit-mock. Or it is not the same?