fix tests
This commit is contained in:
parent
cef8acad0c
commit
fefda571d6
@ -79,6 +79,17 @@ export const mockSendTextMessage = jest.fn()
|
||||
return Promise.resolve()
|
||||
})
|
||||
|
||||
export const mockSendMessage = jest.fn()
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.reject({
|
||||
name: "UnknownDeviceError",
|
||||
devices: ['device1', 'device2']
|
||||
})
|
||||
})
|
||||
.mockImplementation(() => {
|
||||
return Promise.resolve()
|
||||
})
|
||||
|
||||
export const mockSetDeviceKnown = jest.fn()
|
||||
|
||||
export const mockInvite = jest.fn()
|
||||
@ -138,6 +149,12 @@ export const mockGetJoinedRoomMembers = jest.fn(() => {
|
||||
})
|
||||
});
|
||||
|
||||
export const mockGetGroupUsers = jest.fn(() => {
|
||||
return Promise.resolve({
|
||||
chunk: { user_id: 'user_id_1', user_id: 'user_id_2' }
|
||||
})
|
||||
});
|
||||
|
||||
export const mockGetUser = jest.fn().mockReturnValue({ presence: 'online'});
|
||||
|
||||
export const mockClient = {
|
||||
@ -156,6 +173,7 @@ export const mockClient = {
|
||||
isCryptoEnabled: mockIsCryptoEnabled,
|
||||
createRoom: mockCreateRoom,
|
||||
setPowerLevel: mockSetPowerLevel,
|
||||
sendMessage: mockSendMessage,
|
||||
sendTextMessage: mockSendTextMessage,
|
||||
deactivateAccount: mockDeactivateAccount,
|
||||
login: mockLogin,
|
||||
@ -167,6 +185,7 @@ export const mockClient = {
|
||||
kick: mockKick,
|
||||
getJoinedRoomMembers: mockGetJoinedRoomMembers,
|
||||
getUser: mockGetUser,
|
||||
getGroupUsers: mockGetGroupUsers,
|
||||
}
|
||||
|
||||
export const WebStorageSessionStore = jest.fn()
|
||||
|
@ -19,7 +19,7 @@ const MAX_RETRIES = 3;
|
||||
class OcrccBot {
|
||||
constructor() {
|
||||
this.awaitingFacilitator = {};
|
||||
this.client = null;
|
||||
this.client = matrix.createClient(process.env.MATRIX_SERVER_URL);
|
||||
this.joinedRooms = [];
|
||||
this.activeChatrooms = {};
|
||||
}
|
||||
@ -450,9 +450,8 @@ class OcrccBot {
|
||||
|
||||
start() {
|
||||
const localStorage = this.createLocalStorage();
|
||||
const tmpClient = matrix.createClient(process.env.MATRIX_SERVER_URL);
|
||||
|
||||
tmpClient
|
||||
this.client
|
||||
.login("m.login.password", {
|
||||
user: process.env.BOT_USERNAME,
|
||||
password: process.env.BOT_PASSWORD,
|
||||
|
@ -20,6 +20,7 @@ import {
|
||||
mockClearStores,
|
||||
mockOn,
|
||||
mockOnce,
|
||||
mockSendMessage,
|
||||
mockSendTextMessage,
|
||||
mockLogin,
|
||||
mockGetDevices,
|
||||
@ -30,7 +31,8 @@ import {
|
||||
mockInvite,
|
||||
mockKick,
|
||||
mockGetJoinedRoomMembers,
|
||||
mockGetUser
|
||||
mockGetUser,
|
||||
mockGetGroupUsers
|
||||
} from "matrix-js-sdk";
|
||||
|
||||
import OcrccBot from './bot'
|
||||
@ -63,13 +65,14 @@ describe('OcrccBot', () => {
|
||||
mockKick.mockClear()
|
||||
mockGetJoinedRoomMembers.mockClear()
|
||||
mockGetUser.mockClear()
|
||||
mockSendMessage.mockClear()
|
||||
mockSendTextMessage.mockClear()
|
||||
mockAppendFileSync.mockClear()
|
||||
mockGetGroupUsers.mockClear()
|
||||
})
|
||||
|
||||
test('constructor should inititialize matrix client', () => {
|
||||
test('constructor should inititialize class variables', () => {
|
||||
const bot = new OcrccBot()
|
||||
expect(createClient).toHaveBeenCalledWith(process.env.MATRIX_SERVER_URL)
|
||||
expect(bot.joinedRooms).toEqual([])
|
||||
expect(bot.awaitingFacilitator).toEqual({})
|
||||
expect(bot.activeChatrooms).toEqual({})
|
||||
@ -99,7 +102,7 @@ describe('OcrccBot', () => {
|
||||
expect(mockSetDeviceVerified).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
waitForExpect(() => {
|
||||
expect(mockSendTextMessage).toHaveBeenCalledWith(testRoom, testMsg)
|
||||
expect(mockSendMessage).toHaveBeenCalledWith(testRoom, testMsg)
|
||||
})
|
||||
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user