fix tests

pull/1692/head
Audric Ackermann 4 years ago
parent 03fe67b974
commit 5bf844241b
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -6,7 +6,6 @@ const SchemaVersion = require('./schema_version');
const { const {
initializeAttachmentMetadata, initializeAttachmentMetadata,
} = require('../../../ts/types/message/initializeAttachmentMetadata'); } = require('../../../ts/types/message/initializeAttachmentMetadata');
const Contact = require('./contact');
const GROUP = 'group'; const GROUP = 'group';
const PRIVATE = 'private'; const PRIVATE = 'private';
@ -158,17 +157,6 @@ exports._mapAttachments = upgradeAttachment => async (message, context) => {
return Object.assign({}, message, { attachments }); return Object.assign({}, message, { attachments });
}; };
// Public API
// _mapContact :: (Contact -> Promise Contact) ->
// (Message, Context) ->
// Promise Message
exports._mapContact = upgradeContact => async (message, context) => {
const contextWithMessage = Object.assign({}, context, { message });
const upgradeWithContext = contact => upgradeContact(contact, contextWithMessage);
const contact = await Promise.all((message.contact || []).map(upgradeWithContext));
return Object.assign({}, message, { contact });
};
// _mapQuotedAttachments :: (QuotedAttachment -> Promise QuotedAttachment) -> // _mapQuotedAttachments :: (QuotedAttachment -> Promise QuotedAttachment) ->
// (Message, Context) -> // (Message, Context) ->
// Promise Message // Promise Message
@ -255,7 +243,7 @@ const toVersion5 = exports._withSchemaVersion({
}); });
const toVersion6 = exports._withSchemaVersion({ const toVersion6 = exports._withSchemaVersion({
schemaVersion: 6, schemaVersion: 6,
upgrade: () => {}, upgrade: message => message,
}); });
// IMPORTANT: Weve updated our definition of `initializeAttachmentMetadata`, so // IMPORTANT: Weve updated our definition of `initializeAttachmentMetadata`, so
// we need to run it again on existing items that have previously been incorrectly // we need to run it again on existing items that have previously been incorrectly
@ -343,8 +331,8 @@ exports.upgradeSchema = async (
if (maxVersion < index) { if (maxVersion < index) {
break; break;
} }
const currentVersion = VERSIONS[index]; const currentVersion = VERSIONS[index];
// We really do want this intra-loop await because this is a chained async action, // We really do want this intra-loop await because this is a chained async action,
// each step dependent on the previous // each step dependent on the previous
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
@ -614,21 +602,6 @@ exports.createAttachmentDataWriter = ({ writeExistingAttachmentData, logger }) =
return omit(thumbnail, ['data']); return omit(thumbnail, ['data']);
}); });
const writeContactAvatar = async messageContact => {
const { avatar } = messageContact;
if (avatar && !avatar.avatar) {
return omit(messageContact, ['avatar']);
}
await writeExistingAttachmentData(avatar.avatar);
return Object.assign({}, messageContact, {
avatar: Object.assign({}, avatar, {
avatar: omit(avatar.avatar, ['data']),
}),
});
};
const writePreviewImage = async item => { const writePreviewImage = async item => {
const { image } = item; const { image } = item;
if (!image) { if (!image) {
@ -646,7 +619,6 @@ exports.createAttachmentDataWriter = ({ writeExistingAttachmentData, logger }) =
{}, {},
await writeThumbnails(message, { logger }), await writeThumbnails(message, { logger }),
{ {
contact: await Promise.all((contact || []).map(writeContactAvatar)),
preview: await Promise.all((preview || []).map(writePreviewImage)), preview: await Promise.all((preview || []).map(writePreviewImage)),
attachments: await Promise.all( attachments: await Promise.all(
(attachments || []).map(async attachment => { (attachments || []).map(async attachment => {

@ -214,7 +214,6 @@ describe('Backup', () => {
const OUR_NUMBER = '+12025550000'; const OUR_NUMBER = '+12025550000';
const CONTACT_ONE_NUMBER = '+12025550001'; const CONTACT_ONE_NUMBER = '+12025550001';
const CONTACT_TWO_NUMBER = '+12025550002';
const toArrayBuffer = nodeBuffer => const toArrayBuffer = nodeBuffer =>
nodeBuffer.buffer.slice( nodeBuffer.buffer.slice(
@ -310,17 +309,6 @@ describe('Backup', () => {
}); });
return Object.assign({}, await loadThumbnails(message), { return Object.assign({}, await loadThumbnails(message), {
contact: await Promise.all(
(message.contact || []).map(async contact => {
return contact && contact.avatar && contact.avatar.avatar
? Object.assign({}, contact, {
avatar: Object.assign({}, contact.avatar, {
avatar: await wrappedLoadAttachment(contact.avatar.avatar),
}),
})
: contact;
})
),
attachments: await Promise.all( attachments: await Promise.all(
(message.attachments || []).map(async attachment => { (message.attachments || []).map(async attachment => {
await wrappedLoadAttachment(attachment); await wrappedLoadAttachment(attachment);
@ -401,26 +389,7 @@ describe('Backup', () => {
}, },
], ],
}, },
contact: [
{
name: {
displayName: 'Someone Somewhere',
},
number: [
{
value: CONTACT_TWO_NUMBER,
type: 1,
},
],
avatar: {
isProfile: false,
avatar: {
contentType: 'image/png',
data: FIXTURES.png,
},
},
},
],
preview: [ preview: [
{ {
url: 'https://www.instagram.com/p/BsOGulcndj-/', url: 'https://www.instagram.com/p/BsOGulcndj-/',

@ -69,7 +69,6 @@ describe('Message', () => {
path: 'ab/abcdefghi', path: 'ab/abcdefghi',
}, },
], ],
contact: [],
preview: [], preview: [],
}; };
@ -114,55 +113,6 @@ describe('Message', () => {
}, },
], ],
}, },
contact: [],
preview: [],
};
const writeExistingAttachmentData = attachment => {
assert.equal(attachment.path, 'ab/abcdefghi');
assert.deepEqual(attachment.data, stringToArrayBuffer('Its easy if you try'));
};
const actual = await Message.createAttachmentDataWriter({
writeExistingAttachmentData,
logger,
})(input);
assert.deepEqual(actual, expected);
});
it('should process contact avatars', async () => {
const input = {
body: 'Imagine there is no heaven…',
schemaVersion: 4,
attachments: [],
contact: [
{
name: 'john',
avatar: {
isProfile: false,
avatar: {
path: 'ab/abcdefghi',
data: stringToArrayBuffer('Its easy if you try'),
},
},
},
],
};
const expected = {
body: 'Imagine there is no heaven…',
schemaVersion: 4,
attachments: [],
contact: [
{
name: 'john',
avatar: {
isProfile: false,
avatar: {
path: 'ab/abcdefghi',
},
},
},
],
preview: [], preview: [],
}; };
@ -277,7 +227,6 @@ describe('Message', () => {
hasVisualMediaAttachments: undefined, hasVisualMediaAttachments: undefined,
hasFileAttachments: undefined, hasFileAttachments: undefined,
schemaVersion: Message.CURRENT_SCHEMA_VERSION, schemaVersion: Message.CURRENT_SCHEMA_VERSION,
contact: [],
}; };
const expectedAttachmentData = stringToArrayBuffer('Its easy if you try'); const expectedAttachmentData = stringToArrayBuffer('Its easy if you try');
@ -629,49 +578,4 @@ describe('Message', () => {
assert.deepEqual(result, expected); assert.deepEqual(result, expected);
}); });
}); });
describe('_mapContact', () => {
it('handles message with no contact field', async () => {
const upgradeContact = sinon.stub().throws(new Error("Shouldn't be called"));
const upgradeVersion = Message._mapContact(upgradeContact);
const message = {
body: 'hey there!',
};
const expected = {
body: 'hey there!',
contact: [],
};
const result = await upgradeVersion(message);
assert.deepEqual(result, expected);
});
it('handles one contact', async () => {
const upgradeContact = contact => Promise.resolve(contact);
const upgradeVersion = Message._mapContact(upgradeContact);
const message = {
body: 'hey there!',
contact: [
{
name: {
displayName: 'Someone somewhere',
},
},
],
};
const expected = {
body: 'hey there!',
contact: [
{
name: {
displayName: 'Someone somewhere',
},
},
],
};
const result = await upgradeVersion(message);
assert.deepEqual(result, expected);
});
});
}); });

@ -140,22 +140,6 @@ function cleanAttachments(decrypted: any) {
}; };
}); });
decrypted.contact = (decrypted.contact || []).map((item: any) => {
const { avatar } = item;
if (!avatar || !avatar.avatar) {
return item;
}
return {
...item,
avatar: {
...item.avatar,
avatar: cleanAttachment(item.avatar.avatar),
},
};
});
if (quote) { if (quote) {
if (quote.id) { if (quote.id) {
quote.id = _.toNumber(quote.id); quote.id = _.toNumber(quote.id);

@ -239,18 +239,13 @@ async function processOnionRequestErrorAtDestination({
if (statusCode === 200) { if (statusCode === 200) {
return; return;
} }
window?.log?.info('processOnionRequestErrorAtDestination. statusCode ok:', statusCode); window?.log?.info('processOnionRequestErrorAtDestination. statusCode nok:', statusCode);
process406Error(statusCode); process406Error(statusCode);
await process421Error(statusCode, body, associatedWith, destinationEd25519); await process421Error(statusCode, body, associatedWith, destinationEd25519);
processOxenServerError(statusCode, body); processOxenServerError(statusCode, body);
if (destinationEd25519) { if (destinationEd25519) {
await processAnyOtherErrorAtDestination(statusCode, body, destinationEd25519, associatedWith); await processAnyOtherErrorAtDestination(statusCode, body, destinationEd25519, associatedWith);
} else {
console.warn(
'processOnionRequestErrorAtDestination: destinationEd25519 unset. was it an open group call?',
statusCode
);
} }
} }

@ -1,5 +1,4 @@
import { Attachment } from './Attachment'; import { Attachment } from './Attachment';
import { Contact } from './Contact';
import { IndexableBoolean, IndexablePresence } from './IndexedDB'; import { IndexableBoolean, IndexablePresence } from './IndexedDB';
export type Message = UserMessage; export type Message = UserMessage;
@ -23,7 +22,6 @@ export type IncomingMessage = Readonly<
sourceDevice?: number; sourceDevice?: number;
} & SharedMessageProperties & } & SharedMessageProperties &
MessageSchemaVersion5 & MessageSchemaVersion5 &
MessageSchemaVersion6 &
ExpirationTimerUpdate ExpirationTimerUpdate
>; >;
@ -51,12 +49,6 @@ type MessageSchemaVersion5 = Partial<
}> }>
>; >;
type MessageSchemaVersion6 = Partial<
Readonly<{
contact: Array<Contact>;
}>
>;
export type LokiProfile = { export type LokiProfile = {
displayName: string; displayName: string;
avatarPointer: string; avatarPointer: string;

@ -178,7 +178,7 @@ async function bouncyDeleteAccount(reason?: string) {
} }
export async function deleteAccount(reason?: string) { export async function deleteAccount(reason?: string) {
return _.debounce(() => bouncyDeleteAccount(reason), 200); return bouncyDeleteAccount(reason);
} }
async function createAccount(identityKeyPair: any) { async function createAccount(identityKeyPair: any) {

Loading…
Cancel
Save