From 5b79f715ba448fa6602a4a73f01fb7bfc7eeddc2 Mon Sep 17 00:00:00 2001
From: Audric Ackermann <audric@loki.network>
Date: Fri, 15 May 2020 15:19:56 +1000
Subject: [PATCH] integration-test fix some tests add tests of logs

---
 integration_test/add_friends_test.js          | 26 ++++++++++++++++---
 integration_test/common.js                    |  1 -
 .../page-objects/settings.page.js             |  3 ++-
 js/background.js                              | 12 +++++++++
 libtextsecure/message_receiver.js             |  3 ++-
 5 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/integration_test/add_friends_test.js b/integration_test/add_friends_test.js
index c7b91f643..cd3f4566e 100644
--- a/integration_test/add_friends_test.js
+++ b/integration_test/add_friends_test.js
@@ -118,9 +118,27 @@ describe('Add friends', function() {
     // app trigger the friend request logic first
     const aliceLogs = await app.client.getRenderProcessLogs();
     const bobLogs = await app2.client.getRenderProcessLogs();
-    await common.logsContains(aliceLogs, `Sending undefined:friend-request message to ${common.TEST_PUBKEY2}`);
-    await common.logsContains(bobLogs, `Received a NORMAL_FRIEND_REQUEST from source: ${common.TEST_PUBKEY1}, primarySource: ${common.TEST_PUBKEY1},`);
-    await common.logsContains(bobLogs, `Sending incoming-friend-request-accept:onlineBroadcast message to ${common.TEST_PUBKEY1}`);
-    await common.logsContains(aliceLogs, `Sending outgoing-friend-request-accepted:onlineBroadcast message to ${common.TEST_PUBKEY2}`);
+    await common.logsContains(
+      aliceLogs,
+      `Sending undefined:friend-request message to ${common.TEST_PUBKEY2}`
+    );
+    await common.logsContains(
+      bobLogs,
+      `Received a NORMAL_FRIEND_REQUEST from source: ${
+        common.TEST_PUBKEY1
+      }, primarySource: ${common.TEST_PUBKEY1},`
+    );
+    await common.logsContains(
+      bobLogs,
+      `Sending incoming-friend-request-accept:onlineBroadcast message to ${
+        common.TEST_PUBKEY1
+      }`
+    );
+    await common.logsContains(
+      aliceLogs,
+      `Sending outgoing-friend-request-accepted:onlineBroadcast message to ${
+        common.TEST_PUBKEY2
+      }`
+    );
   });
 });
diff --git a/integration_test/common.js b/integration_test/common.js
index 9582925cd..985cc836f 100644
--- a/integration_test/common.js
+++ b/integration_test/common.js
@@ -427,7 +427,6 @@ module.exports = {
       .getText()
       .should.eventually.be.equal(secretWordsapp1);
 
-
     await app1.client.element(ConversationPage.allowPairingButton).click();
     await app1.client.element(ConversationPage.okButton).click();
     // validate device paired in settings list with correct secrets
diff --git a/integration_test/page-objects/settings.page.js b/integration_test/page-objects/settings.page.js
index 33a56d027..b7d532d4d 100644
--- a/integration_test/page-objects/settings.page.js
+++ b/integration_test/page-objects/settings.page.js
@@ -18,5 +18,6 @@ module.exports = {
   passwordSetModalInput: _confirm =>
     `//input[@id = 'password-modal-input${_confirm ? '-confirm' : ''}']`,
 
-  secretWordsTextInDialog: '//div[@class="device-pairing-dialog__secret-words"]/div[@class="subtle"]',
+  secretWordsTextInDialog:
+    '//div[@class="device-pairing-dialog__secret-words"]/div[@class="subtle"]',
 };
diff --git a/js/background.js b/js/background.js
index 41f636982..8e85f8269 100644
--- a/js/background.js
+++ b/js/background.js
@@ -1759,6 +1759,12 @@
     const details = ev.contactDetails;
 
     const id = details.number;
+    libloki.api.debug.logContactSync(
+      'Got sync contact message with',
+      id,
+      ' details:',
+      details
+    );
 
     libloki.api.debug.logContactSync(
       'Got sync contact message with',
@@ -1899,6 +1905,12 @@
   async function onGroupReceived(ev) {
     const details = ev.groupDetails;
     const { id } = details;
+    libloki.api.debug.logGroupSync(
+      'Got sync group message with group id',
+      id,
+      ' details:',
+      details
+    );
 
     libloki.api.debug.logGroupSync(
       'Got sync group message with group id',
diff --git a/libtextsecure/message_receiver.js b/libtextsecure/message_receiver.js
index e17871499..733d5c8dd 100644
--- a/libtextsecure/message_receiver.js
+++ b/libtextsecure/message_receiver.js
@@ -1523,7 +1523,7 @@ MessageReceiver.prototype.extend({
     const ourNumber = textsecure.storage.user.getNumber();
     const ourPrimaryNumber = window.storage.get('primaryDevicePubKey');
     const ourOtherDevices = await libloki.storage.getAllDevicePubKeysForPrimaryPubKey(
-      window.storage.get('primaryDevicePubKey')
+      ourPrimaryNumber
     );
     const ourDevices = new Set([
       ourNumber,
@@ -1709,6 +1709,7 @@ MessageReceiver.prototype.extend({
   isBlocked(number) {
     return textsecure.storage.get('blocked', []).indexOf(number) >= 0;
   },
+
   cleanAttachment(attachment) {
     return {
       ..._.omit(attachment, 'thumbnail'),