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