add test for bot signal
This commit is contained in:
parent
5dc6aa5660
commit
6e71ba4b5b
@ -157,6 +157,10 @@ export const mockGetGroupUsers = jest.fn(() => {
|
|||||||
|
|
||||||
export const mockGetUser = jest.fn().mockReturnValue({ presence: 'online'});
|
export const mockGetUser = jest.fn().mockReturnValue({ presence: 'online'});
|
||||||
|
|
||||||
|
export const mockSendStateEvent = jest.fn(() => {
|
||||||
|
return Promise.resolve();
|
||||||
|
});
|
||||||
|
|
||||||
export const mockClient = {
|
export const mockClient = {
|
||||||
registerRequest: mockRegisterRequest,
|
registerRequest: mockRegisterRequest,
|
||||||
initCrypto: mockInitCrypto,
|
initCrypto: mockInitCrypto,
|
||||||
@ -186,6 +190,7 @@ export const mockClient = {
|
|||||||
getJoinedRoomMembers: mockGetJoinedRoomMembers,
|
getJoinedRoomMembers: mockGetJoinedRoomMembers,
|
||||||
getUser: mockGetUser,
|
getUser: mockGetUser,
|
||||||
getGroupUsers: mockGetGroupUsers,
|
getGroupUsers: mockGetGroupUsers,
|
||||||
|
sendStateEvent: mockSendStateEvent,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const WebStorageSessionStore = jest.fn()
|
export const WebStorageSessionStore = jest.fn()
|
||||||
|
@ -32,7 +32,8 @@ import {
|
|||||||
mockKick,
|
mockKick,
|
||||||
mockGetJoinedRoomMembers,
|
mockGetJoinedRoomMembers,
|
||||||
mockGetUser,
|
mockGetUser,
|
||||||
mockGetGroupUsers
|
mockGetGroupUsers,
|
||||||
|
mockSendStateEvent,
|
||||||
} from "matrix-js-sdk";
|
} from "matrix-js-sdk";
|
||||||
|
|
||||||
import OcrccBot from './bot'
|
import OcrccBot from './bot'
|
||||||
@ -100,6 +101,7 @@ describe('OcrccBot', () => {
|
|||||||
mockSendTextMessage.mockClear()
|
mockSendTextMessage.mockClear()
|
||||||
mockAppendFileSync.mockClear()
|
mockAppendFileSync.mockClear()
|
||||||
mockGetGroupUsers.mockClear()
|
mockGetGroupUsers.mockClear()
|
||||||
|
mockSendStateEvent.mockClear()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@ -325,4 +327,17 @@ describe('OcrccBot', () => {
|
|||||||
expect(mockStartClient).toHaveBeenCalled()
|
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 })
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
Loading…
Reference in New Issue
Block a user