signal-desktop/libtextsecure/test/fake_web_api.js

57 lines
1.5 KiB
JavaScript
Raw Normal View History

window.setImmediate = window.nodeSetImmediate;
const getKeysForNumberMap = {};
const messagesSentMap = {};
const fakeCall = () => Promise.resolve();
const fakeAPI = {
confirmCode: fakeCall,
getAttachment: fakeCall,
getAvatar: fakeCall,
getDevices: fakeCall,
// getKeysForNumber: fakeCall,
getMessageSocket: fakeCall,
getMyKeys: fakeCall,
getProfile: fakeCall,
getProvisioningSocket: fakeCall,
putAttachment: fakeCall,
registerKeys: fakeCall,
requestVerificationSMS: fakeCall,
requestVerificationVoice: fakeCall,
// sendMessages: fakeCall,
setSignedPreKey: fakeCall,
getKeysForNumber: function(number, deviceId) {
var res = getKeysForNumberMap[number];
if (res !== undefined) {
delete getKeysForNumberMap[number];
return Promise.resolve(res);
} else throw new Error('getKeysForNumber of unknown/used number');
},
sendMessages: function(destination, messageArray) {
for (i in messageArray) {
var msg = messageArray[i];
if (
(msg.type != 1 && msg.type != 3) ||
msg.destinationDeviceId === undefined ||
msg.destinationRegistrationId === undefined ||
msg.body === undefined ||
msg.timestamp == undefined ||
msg.relay !== undefined ||
msg.destination !== undefined
)
throw new Error('Invalid message');
messagesSentMap[
destination + '.' + messageArray[i].destinationDeviceId
] = msg;
}
},
};
window.WebAPI = {
connect: () => fakeAPI,
};