From 615f79daaaf3a0ecfccc4c47c6fd98545cb19980 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Bodas Date: Thu, 29 Apr 2021 17:17:56 +0530 Subject: [PATCH] node tests: Clean up data setup in pm_conversations.js. * Extract out data as common variable so that it can be reused in other tests in the future. * Use consistent dummy user_ids across tests. * Expand the data set to cover all possible cases- - 1:1 PMs - Huddles - PMs with self --- frontend_tests/node_tests/pm_conversations.js | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/frontend_tests/node_tests/pm_conversations.js b/frontend_tests/node_tests/pm_conversations.js index 9ec2626310..c65b2cf27c 100644 --- a/frontend_tests/node_tests/pm_conversations.js +++ b/frontend_tests/node_tests/pm_conversations.js @@ -8,6 +8,16 @@ const {run_test} = require("../zjsunit/test"); const people = zrequire("people"); const pmc = zrequire("pm_conversations"); +const params = { + recent_private_conversations: [ + {user_ids: [1], max_message_id: 100}, + {user_ids: [3], max_message_id: 99}, + {user_ids: [1, 2], max_message_id: 98}, + {user_ids: [1, 2, 3], max_message_id: 97}, + {user_ids: [15], max_message_id: 96}, // self + ], +}; + function test(label, f) { run_test(label, (override) => { pmc.clear_for_testing(); @@ -30,34 +40,31 @@ test("partners", () => { }); test("insert_recent_private_message", () => { - const params = { - recent_private_conversations: [ - {user_ids: [11, 2], max_message_id: 150}, - {user_ids: [1], max_message_id: 111}, - {user_ids: [], max_message_id: 7}, - ], - }; pmc.recent.initialize(params); + // Base data assert.deepEqual(pmc.recent.get(), [ - {user_ids_string: "2,11", max_message_id: 150}, - {user_ids_string: "1", max_message_id: 111}, - {user_ids_string: "15", max_message_id: 7}, + {user_ids_string: "1", max_message_id: 100}, + {user_ids_string: "3", max_message_id: 99}, + {user_ids_string: "1,2", max_message_id: 98}, + {user_ids_string: "1,2,3", max_message_id: 97}, + {user_ids_string: "15", max_message_id: 96}, ]); - pmc.recent.insert([1], 1001); - pmc.recent.insert([2], 2001); - pmc.recent.insert([1], 3001); + // Insert new messages (which should rearrange these entries). + pmc.recent.insert([1], 1000); + pmc.recent.insert([1, 2, 3], 999); + pmc.recent.insert([], 101); // Self-PM - // try to backdate user1's latest message + // Try to backdate user1's latest message. pmc.recent.insert([1], 555); assert.deepEqual(pmc.recent.get(), [ - {user_ids_string: "1", max_message_id: 3001}, - {user_ids_string: "2", max_message_id: 2001}, - {user_ids_string: "2,11", max_message_id: 150}, - {user_ids_string: "15", max_message_id: 7}, + {user_ids_string: "1", max_message_id: 1000}, + {user_ids_string: "1,2,3", max_message_id: 999}, + {user_ids_string: "15", max_message_id: 101}, + {user_ids_string: "3", max_message_id: 99}, + {user_ids_string: "1,2", max_message_id: 98}, ]); - - assert.deepEqual(pmc.recent.get_strings(), ["1", "2", "2,11", "15"]); + assert.deepEqual(pmc.recent.get_strings(), ["1", "1,2,3", "15", "3", "1,2"]); });