From edfcbe2d67095998290e3f132c5798fbe4ee1122 Mon Sep 17 00:00:00 2001 From: William Grant Date: Wed, 11 Oct 2023 16:16:28 +1100 Subject: [PATCH] fix: dont use ourNumber in contacts tests --- .../libsession/libsession_utils_contacts.ts | 1 - .../libsession_wrapper_contacts_test.ts | 57 +++++++------------ 2 files changed, 20 insertions(+), 38 deletions(-) diff --git a/ts/session/utils/libsession/libsession_utils_contacts.ts b/ts/session/utils/libsession/libsession_utils_contacts.ts index 072873572..95820bc48 100644 --- a/ts/session/utils/libsession/libsession_utils_contacts.ts +++ b/ts/session/utils/libsession/libsession_utils_contacts.ts @@ -61,7 +61,6 @@ async function insertContactFromDBIntoWrapperAndRefresh( const dbApprovedMe = !!foundConvo.get('didApproveMe') || false; const dbBlocked = !!foundConvo.isBlocked() || false; const priority = foundConvo.get('priority') || 0; - window.log.debug(`WIP: [unit testing]\nfoundConvo.get('priority') ${foundConvo.get('priority')}`); const expirationMode = foundConvo.getExpirationMode() || undefined; const expireTimer = foundConvo.getExpireTimer() || 0; diff --git a/ts/test/session/unit/libsession_wrapper/libsession_wrapper_contacts_test.ts b/ts/test/session/unit/libsession_wrapper/libsession_wrapper_contacts_test.ts index b8fd23ec0..6b3a05793 100644 --- a/ts/test/session/unit/libsession_wrapper/libsession_wrapper_contacts_test.ts +++ b/ts/test/session/unit/libsession_wrapper/libsession_wrapper_contacts_test.ts @@ -222,18 +222,17 @@ describe('libsession_contacts', () => { expireTimer: 0, }; - const contact = new ConversationModel({ - ...validArgs, - ...contactArgs, - id: ourNumber, - } as any); - Sinon.stub(getConversationController(), 'get').returns(contact); - Sinon.stub(SessionUtilContact, 'isContactToStoreInWrapper').returns(true); - Sinon.stub(ContactsWrapperActions, 'set').resolves(); - it('the returned wrapper values matche with the inputted contact', async () => { + const contact = new ConversationModel({ + ...validArgs, + ...contactArgs, + } as any); + Sinon.stub(getConversationController(), 'get').returns(contact); + Sinon.stub(SessionUtilContact, 'isContactToStoreInWrapper').returns(true); + Sinon.stub(ContactsWrapperActions, 'set').resolves(); + const wrapperContact = await SessionUtilContact.insertContactFromDBIntoWrapperAndRefresh( - ourNumber + contact.get('id') ); expect(wrapperContact, 'something should be returned from the wrapper').to.not.be.null; @@ -277,8 +276,18 @@ describe('libsession_contacts', () => { ).to.equal(contact.get('expireTimer')); }); it('if disappearing messages is on then the wrapper returned values should match the inputted contact', async () => { + const contact = new ConversationModel({ + ...validArgs, + ...contactArgs, + expirationMode: 'deleteAfterSend', + expireTimer: 300, + } as any); + Sinon.stub(getConversationController(), 'get').returns(contact); + Sinon.stub(SessionUtilContact, 'isContactToStoreInWrapper').returns(true); + Sinon.stub(ContactsWrapperActions, 'set').resolves(); + const wrapperContact = await SessionUtilContact.insertContactFromDBIntoWrapperAndRefresh( - ourNumber + contact.get('id') ); expect(wrapperContact, 'something should be returned from the wrapper').to.not.be.null; @@ -286,32 +295,6 @@ describe('libsession_contacts', () => { throw Error('something should be returned from the wrapper'); } - expect(wrapperContact.id, 'id in the wrapper should match the inputted contact').to.equal( - contact.id - ); - expect( - wrapperContact.approved, - 'approved in the wrapper should match the inputted contact' - ).to.equal(contact.isApproved()); - expect( - wrapperContact.approvedMe, - 'approvedMe in the wrapper should match the inputted contact' - ).to.equal(contact.didApproveMe()); - expect( - wrapperContact.blocked, - 'blocked in the wrapper should match the inputted contact' - ).to.equal(contact.isBlocked()); - expect( - wrapperContact.priority, - 'priority in the wrapper should match the inputted contact' - ).to.equal(contact.get('priority')); - expect( - wrapperContact.nickname, - 'nickname in the wrapper should match the inputted contact' - ).to.equal(contact.get('nickname')); - expect(wrapperContact.name, 'name in the wrapper should match the inputted contact').to.equal( - contact.get('displayNameInProfile') - ); expect( wrapperContact.expirationMode, 'expirationMode in the wrapper should match the inputted contact'