add test for bot signal

This commit is contained in:
Sharon Kennedy 2020-09-06 13:39:39 -04:00
parent 5dc6aa5660
commit 6e71ba4b5b
2 changed files with 21 additions and 1 deletions

View File

@ -157,6 +157,10 @@ export const mockGetGroupUsers = jest.fn(() => {
export const mockGetUser = jest.fn().mockReturnValue({ presence: 'online'});
export const mockSendStateEvent = jest.fn(() => {
return Promise.resolve();
});
export const mockClient = {
registerRequest: mockRegisterRequest,
initCrypto: mockInitCrypto,
@ -186,6 +190,7 @@ export const mockClient = {
getJoinedRoomMembers: mockGetJoinedRoomMembers,
getUser: mockGetUser,
getGroupUsers: mockGetGroupUsers,
sendStateEvent: mockSendStateEvent,
}
export const WebStorageSessionStore = jest.fn()

View File

@ -32,7 +32,8 @@ import {
mockKick,
mockGetJoinedRoomMembers,
mockGetUser,
mockGetGroupUsers
mockGetGroupUsers,
mockSendStateEvent,
} from "matrix-js-sdk";
import OcrccBot from './bot'
@ -100,6 +101,7 @@ describe('OcrccBot', () => {
mockSendTextMessage.mockClear()
mockAppendFileSync.mockClear()
mockGetGroupUsers.mockClear()
mockSendStateEvent.mockClear()
})
@ -325,4 +327,17 @@ describe('OcrccBot', () => {
expect(mockStartClient).toHaveBeenCalled()
})
})
test('#sendBotSignal should send custom state event', () => {
const bot = new OcrccBot(botConfig)
bot.start()
const test_room_id = 'test_room_id'
const signal = 'END_CHAT'
bot.sendBotSignal(test_room_id, signal)
waitForExpect(() => {
expect(mockSendStateEvent).toHaveBeenCalledWith(test_room_id, 'm.bot.signal', { signal })
})
})
})