signal-desktop/libtextsecure/test/fake_web_api.js
Ken Powers a90246cbe5 Passive UUID support
Co-authored-by: Scott Nonnenberg <scott@signal.org>
2020-03-24 16:59:35 -07:00

57 lines
1.5 KiB
JavaScript

window.setImmediate = window.nodeSetImmediate;
const getKeysForIdentifierMap = {};
const messagesSentMap = {};
const fakeCall = () => Promise.resolve();
const fakeAPI = {
confirmCode: fakeCall,
getAttachment: fakeCall,
getAvatar: fakeCall,
getDevices: fakeCall,
// getKeysForIdentifier : fakeCall,
getMessageSocket: fakeCall,
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);
}
throw new Error('getKeysForIdentfier of unknown/used number');
},
sendMessages(destination, messageArray) {
for (let i = 0, max = messageArray.length; i < max; i += 1) {
const 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,
};