syncMessage done

pull/1199/head
vincent 5 years ago
parent f72423c2ba
commit 152adbf4d5

@ -65,8 +65,5 @@ export async function getSyncContacts(): Promise<Array<any> | undefined> {
.filter(c => c.id !== primaryDevice.key);
// Return unique contacts
return _.uniqBy(
[...primaryContacts, ...secondaryContacts],
'id'
);
return _.uniqBy([...primaryContacts, ...secondaryContacts], 'id');
}

@ -1,13 +1,10 @@
import chai from 'chai';
import * as sinon from 'sinon';
import { PubKey } from '../../../session/types/';
import { SyncMessageUtils } from '../../../session/utils/';
import { SyncMessage } from '../../../session/messages/outgoing';
import { TestUtils } from '../../test-utils';
import { UserUtil } from '../../../util';
import { MultiDeviceProtocol } from '../../../session/protocols';
import { Integer } from '../../../types/Util';
// tslint:disable-next-line: no-require-imports no-var-requires
const chaiAsPromised = require('chai-as-promised');
@ -24,8 +21,6 @@ describe('Sync Message Utils', () => {
// Stubbed
expect(syncMessage).to.not.exist;
// expect(syncMessage instanceof SyncMessage).to.equal(true, 'message was not converted to SyncMessage');
// Further tests required
});
});
@ -52,36 +47,14 @@ describe('Sync Message Utils', () => {
let getOrCreateAndWaitStub: sinon.SinonStub;
let getOrCreatAndWaitItem: any;
// tslint:disable-next-line: insecure-random
const randomBoolean = () => !!Math.round(Math.random());
const randomMockConv = (primary: boolean) => (
// new (function(primary) {
// return {
// id: generateFakePubKey().key,
// isPrivate: () => true,
// isOurLocalDevice: () => false,
// isBlocked: () => false,
// getPrimaryDevicePubKey: () => this.isPrivate ?
// attributes: {
// secondaryStatus: !primary,
// },
// };
// })();
{}
);
// Fill half with secondaries, half with primaries
const numConversations = 20;
const primaryConversations = new Array(numConversations / 2)
.fill({})
.map(() => randomMockConv(true));
.map(() => new TestUtils.MockPrivateConversation({ isPrimary: true }));
const secondaryConversations = new Array(numConversations / 2)
.fill({})
.map(() => randomMockConv(false));
.map(() => new TestUtils.MockPrivateConversation({ isPrimary: false }));
const conversations = [...primaryConversations, ...secondaryConversations];
const sandbox = sinon.createSandbox();
@ -102,7 +75,8 @@ describe('Sync Message Utils', () => {
// Scale result in sync with secondaryConversations on callCount
getOrCreateAndWaitStub = sandbox.stub().callsFake(() => {
const item = secondaryConversations[getOrCreateAndWaitStub.callCount - 1];
const item =
secondaryConversations[getOrCreateAndWaitStub.callCount - 1];
// Make the item a primary device to match the call in SyncMessage under secondaryContactsPromise
getOrCreatAndWaitItem = {
@ -150,14 +124,12 @@ describe('Sync Message Utils', () => {
// We should have numConversations unique contacts
expect(contacts).to.have.length(numConversations);
// All contacts should be primary; half of which some from secondaries in secondaryContactsPromise
expect(contacts?.find(c => c.attributes.secondaryStatus)).to.not.exist;
expect(contacts)
expect(contacts?.filter(c => c.isPrimary)).to.have.length(
numConversations / 2
);
});
});
// MAKE MORE SPECIFIC, CHECK PARAMETERS
});

@ -10,8 +10,10 @@ import {
ClosedGroupChatMessage,
OpenGroupMessage,
} from '../../session/messages/outgoing';
import { Integer } from '../../types/Util';
import { ConversationModel, ConversationAttributes } from '../../../js/models/conversation';
import {
ConversationAttributes,
} from '../../../js/models/conversation';
import { TestUtils } from '.';
const globalAny: any = global;
const sandbox = sinon.createSandbox();
@ -79,11 +81,11 @@ export function generateFakePubKey(): PubKey {
return new PubKey(pubkeyString);
}
export function generateFakePubKeys(amount: Integer): Array<PubKey> {
export function generateFakePubKeys(amount: number): Array<PubKey> {
const numPubKeys = amount > 0 ? Math.floor(amount) : 0;
// tslint:disable-next-line: no-unnecessary-callback-wrapper
return new Array(amount).fill(0).map(() => generateFakePubKey());
return new Array(numPubKeys).fill(0).map(() => generateFakePubKey());
}
export function generateChatMessage(identifier?: string): ChatMessage {
@ -126,19 +128,34 @@ export function generateClosedGroupMessage(
});
}
// Mock ConversationModel
export class MockPrivateConversation implements ConversationModel {
interface MockPrivateConversationParams {
id?: string;
isPrimary: boolean;
}
export class MockPrivateConversation {
public id: string;
public isPrimary: boolean;
public attributes: ConversationAttributes;
constructor(isPrimary: boolean) {
this.isPrimary = isPrimary;
constructor(params: MockPrivateConversationParams) {
const dayInSeconds = 86400;
this.isPrimary = params.isPrimary;
this.id = params.id ?? TestUtils.generateFakePubKey().key;
this.id = TestUtils.generateFakePubKey().key;
this.attributes = {
members
}
members: [],
left: false,
expireTimer: dayInSeconds,
profileSharing: true,
mentionedUs: false,
unreadCount: 99,
isArchived: false,
active_at: Date.now(),
timestamp: Date.now(),
secondaryStatus: !this.isPrimary,
};
}
public isPrivate() {
@ -154,10 +171,6 @@ export class MockPrivateConversation implements ConversationModel {
}
public getPrimaryDevicePubKey() {
return this.isPrimary
? this.id
: TestUtils.generateFakePubKey().key;
return this.isPrimary ? this.id : TestUtils.generateFakePubKey().key;
}
}
const myconv = new MockPrivateConversation(false) ;
}

@ -1,8 +1,3 @@
// Integer Type - primarily for incremental values in ConversationModel etc
export type Integer = number & { __int__: void };
export const roundToInt = (num: number): Integer => Math.round(num) as Integer;
export type RenderTextCallbackType = (options: {
text: string;
key: number;

Loading…
Cancel
Save