signal-desktop/libtextsecure/test/fake_web_api.js

62 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-10-30 20:34:04 +00:00
// Copyright 2018-2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
window.setImmediate = window.nodeSetImmediate;
const getKeysForIdentifierMap = {};
const messagesSentMap = {};
const fakeCall = () => Promise.resolve();
const fakeAPI = {
confirmCode: fakeCall,
getAttachment: fakeCall,
getAvatar: fakeCall,
getDevices: fakeCall,
// getKeysForIdentifier : fakeCall,
2021-02-18 16:40:26 +00:00
getMessageSocket: () => new window.MockSocket('ws://localhost:8081/'),
getMyKeys: fakeCall,
getProfile: fakeCall,
getProvisioningSocket: fakeCall,
putAttachment: fakeCall,
registerKeys: fakeCall,
requestVerificationSMS: fakeCall,
requestVerificationVoice: fakeCall,
// sendMessages: fakeCall,
setSignedPreKey: fakeCall,
getKeysForIdentifier(number) {
const res = getKeysForIdentifierMap[number];
if (res !== undefined) {
delete getKeysForIdentifierMap[number];
return Promise.resolve(res);
2018-07-21 21:51:20 +00:00
}
throw new Error('getKeysForIdentfier of unknown/used number');
},
2018-07-21 21:51:20 +00:00
sendMessages(destination, messageArray) {
2018-11-02 18:02:53 +00:00
for (let i = 0, max = messageArray.length; i < max; i += 1) {
2018-07-21 21:51:20 +00:00
const msg = messageArray[i];
if (
2018-11-02 18:02:53 +00:00
(msg.type !== 1 && msg.type !== 3) ||
msg.destinationDeviceId === undefined ||
msg.destinationRegistrationId === undefined ||
msg.body === undefined ||
2018-11-02 18:02:53 +00:00
msg.timestamp === undefined ||
msg.relay !== undefined ||
msg.destination !== undefined
) {
throw new Error('Invalid message');
}
messagesSentMap[
2018-07-21 21:51:20 +00:00
`${destination}.${messageArray[i].destinationDeviceId}`
] = msg;
}
},
};
window.WebAPI = {
connect: () => fakeAPI,
};