-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: initial tests for typing indicator
- Loading branch information
Marc Littlemore
committed
Mar 16, 2019
1 parent
cff1baa
commit a640176
Showing
5 changed files
with
159 additions
and
28 deletions.
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
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,5 +1,88 @@ | ||
// const bokitMiddlewareTyping = require('../../src/index'); | ||
const typingMiddleware = require('../../src/index'); | ||
|
||
test('testing Jest', () => { | ||
expect(3).toBe(3); | ||
test('should return a function', () => { | ||
expect(typeof typingMiddleware).toBe('function'); | ||
}); | ||
|
||
describe('when typing is not supported by the bot platform', () => { | ||
let spyNext; | ||
const fakeBot = { | ||
startTyping: false, | ||
}; | ||
|
||
beforeEach(() => { | ||
spyNext = jest.fn(); | ||
}); | ||
|
||
test('should call next', () => { | ||
const fakeMessage = {}; | ||
const sendMiddleware = typingMiddleware(); | ||
|
||
sendMiddleware(fakeBot, fakeMessage, spyNext); | ||
|
||
expect(spyNext.mock.calls.length).toBe(1); | ||
}); | ||
}); | ||
|
||
describe('when typing is supported by the bot platform', () => { | ||
let spyNext; | ||
let spyBotSend; | ||
let fakeBot; | ||
|
||
beforeEach(() => { | ||
spyNext = jest.fn(); | ||
spyBotSend = jest.fn(); | ||
|
||
fakeBot = { | ||
startTyping: true, | ||
send: spyBotSend, | ||
}; | ||
}); | ||
|
||
test('should call next if message contains typing indicator', () => { | ||
const fakeMessage = { | ||
sender_action: 'typing_on', | ||
}; | ||
|
||
const sendMiddleware = typingMiddleware(); | ||
|
||
sendMiddleware(fakeBot, fakeMessage, spyNext); | ||
|
||
expect(spyNext).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('should call bot.send', () => { | ||
const fakeMessage = {}; | ||
|
||
const sendMiddleware = typingMiddleware(); | ||
|
||
sendMiddleware(fakeBot, fakeMessage, spyNext); | ||
|
||
expect(spyBotSend).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('should call bot.send with expected message', () => { | ||
const expectedUserId = 'expectedUserId'; | ||
const expectedChannel = 'expectedChannel'; | ||
|
||
const fakeMessage = { | ||
to: expectedUserId, | ||
channel: expectedChannel, | ||
}; | ||
|
||
const expectedMessage = { | ||
recipient: { id: expectedUserId }, | ||
channel: expectedChannel, | ||
sender_action: 'typing_on', | ||
}; | ||
|
||
const sendMiddleware = typingMiddleware(); | ||
|
||
sendMiddleware(fakeBot, fakeMessage, spyNext); | ||
|
||
expect(spyBotSend).toHaveBeenCalledWith( | ||
expectedMessage, | ||
expect.any(Function) | ||
); | ||
}); | ||
}); |
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