Optimize profile avatar uploads and sync urls

This commit is contained in:
Fedor Indutny 2022-03-15 17:14:20 -07:00 committed by GitHub
parent 703bb8a3a3
commit 36ce4f27a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 147 additions and 77 deletions

View file

@ -10,13 +10,17 @@ import {
decryptProfileName,
decryptProfile,
} from '../../Crypto';
import type { ConversationType } from '../../state/ducks/conversations';
import { UUID } from '../../types/UUID';
import { encryptProfileData } from '../../util/encryptProfileData';
describe('encryptProfileData', () => {
it('encrypts and decrypts properly', async () => {
const keyBuffer = getRandomBytes(32);
const conversation = {
let keyBuffer: Uint8Array;
let conversation: ConversationType;
beforeEach(() => {
keyBuffer = getRandomBytes(32);
conversation = {
aboutEmoji: '🐢',
aboutText: 'I like turtles',
familyName: 'Kid',
@ -33,8 +37,13 @@ describe('encryptProfileData', () => {
title: '',
type: 'direct' as const,
};
});
const [encrypted] = await encryptProfileData(conversation);
it('encrypts and decrypts properly', async () => {
const [encrypted] = await encryptProfileData(conversation, {
oldAvatar: undefined,
newAvatar: undefined,
});
assert.isDefined(encrypted.version);
assert.isDefined(encrypted.name);
@ -83,4 +92,22 @@ describe('encryptProfileData', () => {
assert.isDefined(encrypted.aboutEmoji);
}
});
it('sets sameAvatar to true when avatars are the same', async () => {
const [encrypted] = await encryptProfileData(conversation, {
oldAvatar: new Uint8Array([1, 2, 3]),
newAvatar: new Uint8Array([1, 2, 3]),
});
assert.isTrue(encrypted.sameAvatar);
});
it('sets sameAvatar to false when avatars are different', async () => {
const [encrypted] = await encryptProfileData(conversation, {
oldAvatar: new Uint8Array([1, 2, 3]),
newAvatar: new Uint8Array([4, 5, 6, 7]),
});
assert.isFalse(encrypted.sameAvatar);
});
});