Skip to content

Commit 0aefe6b

Browse files
committed
chore: fix unit tests
1 parent 292e700 commit 0aefe6b

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

ts/test/session/unit/libsession_wrapper/libsession_wrapper_metagroup_test.ts

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { TestUtils } from '../../../test-utils';
1313
import { TestUserKeyPairs } from '../../../test-utils/utils';
1414

1515
function profilePicture() {
16-
return { key: new Uint8Array(range(0, 32)), url: `${Math.random()}` };
16+
return { url: `${Math.random() * 10000}`, key: new Uint8Array(range(0, 32)) };
1717
}
1818

1919
function emptyMember(pubkeyHex: PubkeyType): GroupMemberGet {
@@ -185,6 +185,7 @@ describe('libsession_metagroup', () => {
185185
'memberStatus',
186186
'nominatedAdmin',
187187
'supplement',
188+
'profileUpdatedSeconds',
188189
].sort(), // if you change this value, also make sure you add a test, testing that new field, below
189190
'this test is designed to fail if you need to add tests to test a new field of libsession'
190191
);
@@ -296,22 +297,39 @@ describe('libsession_metagroup', () => {
296297
...emptyMember(member),
297298
name: 'member name',
298299
memberStatus: 'INVITE_SENDING',
300+
profileUpdatedSeconds: 1,
301+
});
302+
303+
// second change with same timestamp does not get applied
304+
metaGroupWrapper.memberSetProfileDetails(member, {
305+
profilePicture: { key: new Uint8Array(), url: '' },
306+
name: 'new member name',
307+
profileUpdatedSeconds: 1,
308+
});
309+
expect(metaGroupWrapper.memberGetAll().length).to.be.deep.eq(1);
310+
expect(metaGroupWrapper.memberGetAll()[0]).to.be.deep.eq({
311+
...emptyMember(member),
312+
name: 'member name',
313+
memberStatus: 'INVITE_SENDING',
314+
profileUpdatedSeconds: 1,
299315
});
300316
});
301317

302318
it('can add via profile picture set', () => {
303319
const pic = profilePicture();
304320
metaGroupWrapper.memberConstructAndSet(member);
321+
metaGroupWrapper.memberSetInviteAccepted(member);
305322
metaGroupWrapper.memberSetProfileDetails(member, {
306323
profilePicture: pic,
307324
name: '',
308-
profileUpdatedSeconds: 1,
325+
profileUpdatedSeconds: 1234,
309326
});
310327
expect(metaGroupWrapper.memberGetAll().length).to.be.deep.eq(1);
311328
const expected = {
312329
...emptyMember(member),
313-
profilePicture: pic,
314-
memberStatus: 'INVITE_SENDING',
330+
profilePicture: { url: pic.url, key: Buffer.from(pic.key) },
331+
memberStatus: 'INVITE_ACCEPTED',
332+
profileUpdatedSeconds: 1234,
315333
};
316334

317335
expect(metaGroupWrapper.memberGetAll()[0]).to.be.deep.eq(expected);
@@ -374,6 +392,24 @@ describe('libsession_metagroup', () => {
374392
};
375393
expect(metaGroupWrapper.memberGetAll()).to.be.deep.eq([expected]);
376394
});
395+
396+
it('can set profileUpdatedSeconds', () => {
397+
metaGroupWrapper.memberConstructAndSet(member);
398+
metaGroupWrapper.memberSetProfileDetails(member, {
399+
name: 'member name',
400+
profileUpdatedSeconds: 1234567,
401+
profilePicture: { url: '', key: new Uint8Array() },
402+
});
403+
expect(metaGroupWrapper.memberGetAll().length).to.be.deep.eq(1);
404+
const expected: GroupMemberGet = {
405+
...emptyMember(member),
406+
memberStatus: 'INVITE_SENDING',
407+
name: 'member name',
408+
profileUpdatedSeconds: 1234567,
409+
profilePicture: { url: null, key: null },
410+
};
411+
expect(metaGroupWrapper.memberGetAll()).to.be.deep.eq([expected]);
412+
});
377413
});
378414

379415
describe('keys', () => {

ts/test/session/unit/models/ConversationModels_test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,10 @@ describe('fillConvoAttributesWithDefaults', () => {
130130
});
131131

132132
describe('profileUpdatedSeconds', () => {
133-
it('initialize profileUpdatedSeconds if not given', () => {
134-
expect(fillConvoAttributesWithDefaults({} as ConversationAttributes)).to.have.deep.property(
135-
'profileUpdatedSeconds',
136-
0
137-
);
133+
it('does not initialize profileUpdatedSeconds if not given', () => {
134+
expect(
135+
fillConvoAttributesWithDefaults({} as ConversationAttributes)
136+
).to.not.have.deep.property('profileUpdatedSeconds', 0);
138137
});
139138

140139
it('do not override profileUpdatedSeconds if given', () => {

0 commit comments

Comments
 (0)