From a2890925a55983bf53495cc52ad9b1f3c63a8c74 Mon Sep 17 00:00:00 2001 From: William Grant Date: Thu, 12 Oct 2023 10:43:02 +1100 Subject: [PATCH] test: fix groups wrapper values test --- .../libsession_utils_user_groups.ts | 4 +-- .../libsession_wrapper_user_groups_test.ts | 27 ++++++++++--------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/ts/session/utils/libsession/libsession_utils_user_groups.ts b/ts/session/utils/libsession/libsession_utils_user_groups.ts index 29620b2b1..874a2e095 100644 --- a/ts/session/utils/libsession/libsession_utils_user_groups.ts +++ b/ts/session/utils/libsession/libsession_utils_user_groups.ts @@ -70,11 +70,11 @@ async function insertGroupsFromDBIntoWrapperAndRefresh( return null; } - if (!isUserGroupToStoreInWrapper(foundConvo)) { + if (!SessionUtilUserGroups.isUserGroupToStoreInWrapper(foundConvo)) { return null; } - const convoType: UserGroupsType = isCommunityToStoreInWrapper(foundConvo) + const convoType: UserGroupsType = SessionUtilUserGroups.isCommunityToStoreInWrapper(foundConvo) ? 'Community' : 'LegacyGroup'; diff --git a/ts/test/session/unit/libsession_wrapper/libsession_wrapper_user_groups_test.ts b/ts/test/session/unit/libsession_wrapper/libsession_wrapper_user_groups_test.ts index df17d6ac5..96dfca564 100644 --- a/ts/test/session/unit/libsession_wrapper/libsession_wrapper_user_groups_test.ts +++ b/ts/test/session/unit/libsession_wrapper/libsession_wrapper_user_groups_test.ts @@ -3,7 +3,6 @@ import { expect } from 'chai'; import { LegacyGroupInfo } from 'libsession_util_nodejs'; import { describe } from 'mocha'; import Sinon from 'sinon'; -import { Data } from '../../../../data/data'; import { ConversationModel } from '../../../../models/conversation'; import { CONVERSATION_PRIORITIES, @@ -173,19 +172,19 @@ describe('libsession_user_groups', () => { displayNameInProfile: 'Test Group', expirationMode: 'off', expireTimer: 0, + members: [groupECKeyPair.publicKeyData.toString()], }; - Sinon.stub(Data, 'getLatestClosedGroupEncryptionKeyPair').resolves( - groupECKeyPair.toHexKeyPair() - ); - it('returns wrapper values that match with the inputted group', async () => { const group = new ConversationModel({ ...validArgs, ...groupArgs, } as any); Sinon.stub(getConversationController(), 'get').returns(group); - // Sinon.stub(SessionUtilUserGroups, 'isLegacyGroupToStoreInWrapper').returns(true); + Sinon.stub(SessionUtilUserGroups, 'isUserGroupToStoreInWrapper').returns(true); + TestUtils.stubData('getLatestClosedGroupEncryptionKeyPair').resolves( + groupECKeyPair.toHexKeyPair() + ); const wrapperGroup = await SessionUtilUserGroups.insertGroupsFromDBIntoWrapperAndRefresh( group.get('id') @@ -208,22 +207,24 @@ describe('libsession_user_groups', () => { (wrapperGroup as LegacyGroupInfo).priority, 'priority in the wrapper should match the inputted group' ).to.equal(group.get('priority')); + expect((wrapperGroup as LegacyGroupInfo).members, 'members should not be empty').to.not.be + .empty; expect( - (wrapperGroup as LegacyGroupInfo).members, - 'members in the wrapper should match the inputted group' - ).to.equal(group.get('members')); + (wrapperGroup as LegacyGroupInfo).members[0].pubkeyHex, + 'the member pubkey in the wrapper should match the inputted group member' + ).to.equal(group.get('members')[0]); expect( (wrapperGroup as LegacyGroupInfo).disappearingTimerSeconds, 'disappearingTimerSeconds in the wrapper should match the inputted group' ).to.equal(group.get('expireTimer')); expect( - (wrapperGroup as LegacyGroupInfo).encPubkey, + (wrapperGroup as LegacyGroupInfo).encPubkey.toString(), 'encPubkey in the wrapper should match the inputted group' - ).to.equal(groupECKeyPair.toHexKeyPair().publicHex); + ).to.equal(groupECKeyPair.publicKeyData.toString()); expect( - (wrapperGroup as LegacyGroupInfo).encSeckey, + (wrapperGroup as LegacyGroupInfo).encSeckey.toString(), 'encSeckey in the wrapper should match the inputted group' - ).to.equal(groupECKeyPair.toHexKeyPair().privateHex); + ).to.equal(groupECKeyPair.privateKeyData.toString()); expect( (wrapperGroup as LegacyGroupInfo).joinedAtSeconds, 'joinedAtSeconds in the wrapper should match the inputted group'