From a62a19145ced094d04025430950df8bba93305dd Mon Sep 17 00:00:00 2001 From: Vincent Date: Mon, 29 Jun 2020 08:29:09 +1000 Subject: [PATCH] group-tests --- js/modules/data.d.ts | 2 +- ts/test/session/utils/Groups_test.ts | 17 ++++++++++++ ts/test/session/utils/SyncMessage_test.ts | 4 +-- ts/test/test-utils/utils/message.ts | 33 +++++++++++++++++------ 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/js/modules/data.d.ts b/js/modules/data.d.ts index 711cb0a29..a1ec157ed 100644 --- a/js/modules/data.d.ts +++ b/js/modules/data.d.ts @@ -1,5 +1,5 @@ import { ConversationType } from '../../ts/state/ducks/conversations'; -import { Mesasge } from '../../ts/types/Message'; +import { Message } from '../../ts/types/Message'; export type IdentityKey = { id: string; diff --git a/ts/test/session/utils/Groups_test.ts b/ts/test/session/utils/Groups_test.ts index 0aa2840c8..34d35c0c6 100644 --- a/ts/test/session/utils/Groups_test.ts +++ b/ts/test/session/utils/Groups_test.ts @@ -14,9 +14,26 @@ chai.use(chaiAsPromised); const { expect } = chai; describe('Groups Utils', () => { + const sandbox = sinon.createSandbox(); + + + + describe('getGroupMembers', () => { + let ConversationControllerStub: sinon.SinonStub; + + beforeEach(async () => { + const mockConversation = TestUtils.MockGroupConversation({ type: 'group' }); + + ConversationControllerStub = TestUtils.stubWindow('ConversationCollection', { + get: sandbox.stub().returns(mockConversation), + }); + }); + it('', async () => { // + + // should all be primary keys }); }); diff --git a/ts/test/session/utils/SyncMessage_test.ts b/ts/test/session/utils/SyncMessage_test.ts index 086fa0abb..c2403565f 100644 --- a/ts/test/session/utils/SyncMessage_test.ts +++ b/ts/test/session/utils/SyncMessage_test.ts @@ -51,10 +51,10 @@ describe('Sync Message Utils', () => { const numConversations = 20; const primaryConversations = new Array(numConversations / 2) .fill({}) - .map(() => new TestUtils.MockPrivateConversation({ isPrimary: true })); + .map(() => new TestUtils.MockConversation({ type: 'primary' })); const secondaryConversations = new Array(numConversations / 2) .fill({}) - .map(() => new TestUtils.MockPrivateConversation({ isPrimary: false })); + .map(() => new TestUtils.MockConversation({ type: 'secondary' })); const conversations = [...primaryConversations, ...secondaryConversations]; const sandbox = sinon.createSandbox(); diff --git a/ts/test/test-utils/utils/message.ts b/ts/test/test-utils/utils/message.ts index 21b365f7f..1bd76bd32 100644 --- a/ts/test/test-utils/utils/message.ts +++ b/ts/test/test-utils/utils/message.ts @@ -5,7 +5,7 @@ import { } from '../../../session/messages/outgoing'; import { v4 as uuid } from 'uuid'; import { OpenGroup } from '../../../session/types'; -import { generateFakePubKey } from './pubkey'; +import { generateFakePubKey, generateFakePubKeys } from './pubkey'; import { ConversationAttributes } from '../../../../js/models/conversation'; export function generateChatMessage(identifier?: string): ChatMessage { @@ -48,24 +48,37 @@ export function generateClosedGroupMessage( }); } -interface MockPrivateConversationParams { +interface MockConversationParams { id?: string; - isPrimary: boolean; + type: MockConversationType; + members?: Array; } -export class MockPrivateConversation { +export enum MockConversationType { + Primary = 'primary', + Secondary = 'secondary', + Group = 'group', +} + +export class MockConversation { public id: string; - public isPrimary: boolean; + public type: MockConversationType; public attributes: ConversationAttributes; + public isPrimary?: boolean; - constructor(params: MockPrivateConversationParams) { + constructor(params: MockConversationParams) { const dayInSeconds = 86400; - this.isPrimary = params.isPrimary; + this.type = params.type; this.id = params.id ?? generateFakePubKey().key; + this.isPrimary = this.type === MockConversationType.Primary; + + const members = this.type === MockConversationType.Group + ? params.members ?? generateFakePubKeys(10).map(m => m.key) + : []; this.attributes = { - members: [], + members, left: false, expireTimer: dayInSeconds, profileSharing: true, @@ -91,6 +104,10 @@ export class MockPrivateConversation { } public getPrimaryDevicePubKey() { + if (this.type === MockConversationType.Group) { + return undefined; + } + return this.isPrimary ? this.id : generateFakePubKey().key; } }