ocrcc-chatbox/__mocks__/matrix-js-sdk.js

82 lines
2.3 KiB
JavaScript
Raw Permalink Normal View History

2020-03-13 04:05:12 +00:00
export const mockRegisterRequest = jest
.fn()
.mockImplementation((params) => {
if (!params.auth) {
return Promise.reject({
data: { session: "session_id_1234" }
})
} else {
return Promise.resolve({
data: {
device_id: 'device_id_1234',
access_token: 'token_1234',
user_id: 'user_id_1234',
session: "session_id_1234"
}
})
}
})
2020-03-13 04:05:12 +00:00
export const mockLeave = jest.fn(() => {
return Promise.resolve('value');
});
2020-03-13 04:05:12 +00:00
export const mockInitCrypto = jest.fn()
export const mockStartClient = jest.fn(() => {
return Promise.resolve('value');
});
2020-09-06 19:24:41 +00:00
export const mockOnce = jest
.fn()
.mockImplementation((event, callback) => {
if (event === 'sync') {
callback('PREPARED')
}
})
2020-03-13 04:05:12 +00:00
export const mockStopClient = jest.fn(() => {
return Promise.resolve('value');
});
export const mockClearStores = jest.fn(() => {
return Promise.resolve('value');
});
export const mockGetRoom = jest.fn()
export const mockDownloadKeys = jest.fn()
export const mockSetDeviceVerified = jest.fn()
export const mockIsCryptoEnabled = jest.fn()
2020-04-29 15:31:23 +00:00
export const mockIsRoomEncrypted = jest.fn()
2020-03-13 04:05:12 +00:00
export const mockCreateRoom = jest.fn().mockReturnValue({ room_id: 'room_id_1234' })
export const mockSetPowerLevel = jest.fn()
export const mockSendTextMessage = jest.fn(() => {
return Promise.resolve('value');
});
export const mockSetDeviceKnown = jest.fn()
export const mockDeactivateAccount = jest.fn(() => {
return Promise.resolve('value');
});
export const mockOn = jest.fn()
2020-03-27 22:21:13 +00:00
export const mockSetDisplayName = jest.fn()
2020-03-13 04:05:12 +00:00
export const mockClient = {
registerRequest: mockRegisterRequest,
initCrypto: mockInitCrypto,
startClient: mockStartClient,
on: mockOn,
once: mockOnce,
leave: mockLeave,
stopClient: mockStopClient,
clearStores: mockClearStores,
getRoom: mockGetRoom,
downloadKeys: mockDownloadKeys,
setDeviceVerified: mockSetDeviceVerified,
setDeviceKnown: mockSetDeviceKnown,
isCryptoEnabled: mockIsCryptoEnabled,
2020-04-29 15:31:23 +00:00
isRoomEncrypted: mockIsRoomEncrypted,
2020-03-13 04:05:12 +00:00
createRoom: mockCreateRoom,
setPowerLevel: mockSetPowerLevel,
sendTextMessage: mockSendTextMessage,
deactivateAccount: mockDeactivateAccount,
2020-03-27 22:21:13 +00:00
setDisplayName: mockSetDisplayName,
2020-03-13 04:05:12 +00:00
}
2020-03-27 22:21:13 +00:00
export const WebStorageSessionStore = jest.fn()
2020-03-13 04:05:12 +00:00
export const createClient = jest.fn().mockReturnValue(mockClient)