2019-11-02 00:06:25 +01:00
|
|
|
const pmc = zrequire('pm_conversations');
|
2017-06-01 07:46:23 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('partners', () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const user1_id = 1;
|
|
|
|
const user2_id = 2;
|
|
|
|
const user3_id = 3;
|
2017-06-01 07:46:23 +02:00
|
|
|
|
|
|
|
pmc.set_partner(user1_id);
|
|
|
|
pmc.set_partner(user3_id);
|
|
|
|
|
|
|
|
assert.equal(pmc.is_partner(user1_id), true);
|
|
|
|
assert.equal(pmc.is_partner(user2_id), false);
|
|
|
|
assert.equal(pmc.is_partner(user3_id), true);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-02-09 18:10:39 +01:00
|
|
|
|
2019-11-21 21:01:15 +01:00
|
|
|
zrequire("people");
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('insert_recent_private_message', () => {
|
2020-02-26 23:36:38 +01:00
|
|
|
const params = {
|
2019-11-21 21:01:15 +01:00
|
|
|
recent_private_conversations: [
|
tests: Use tricky server data in unit tests.
The server may send us ids in the order
[11, 2], instead of [2, 11]. We don't want
to rely on server behavior, regardless, for
the sort.
Our tests now show we process that data.
The current code is is still buggy and causes
us to show the same huddle two different times
for situations where the lexical sort doesn't
match the numerical sort.
This happens on czo often, where Tim is user
7, and his id sorts lexically after ids like
58, 622, 4444, etc.
2020-01-01 15:26:25 +01:00
|
|
|
{user_ids: [11, 2],
|
2019-11-21 21:01:15 +01:00
|
|
|
max_message_id: 150,
|
|
|
|
},
|
|
|
|
{user_ids: [1],
|
|
|
|
max_message_id: 111,
|
|
|
|
},
|
|
|
|
{user_ids: [],
|
|
|
|
max_message_id: 7,
|
|
|
|
},
|
|
|
|
],
|
2020-02-26 23:36:38 +01:00
|
|
|
};
|
2019-11-21 21:01:15 +01:00
|
|
|
people.initialize_current_user(15);
|
2020-02-26 23:36:38 +01:00
|
|
|
pmc.recent.initialize(params);
|
2019-11-21 21:01:15 +01:00
|
|
|
|
|
|
|
assert.deepEqual(pmc.recent.get(), [
|
2020-01-01 15:55:36 +01:00
|
|
|
{user_ids_string: '2,11', max_message_id: 150},
|
2019-11-21 21:01:15 +01:00
|
|
|
{user_ids_string: '1', max_message_id: 111},
|
|
|
|
{user_ids_string: '15', max_message_id: 7},
|
|
|
|
]);
|
|
|
|
|
2020-01-01 15:42:46 +01:00
|
|
|
pmc.recent.insert([1], 1001);
|
|
|
|
pmc.recent.insert([2], 2001);
|
|
|
|
pmc.recent.insert([1], 3001);
|
2018-02-09 18:10:39 +01:00
|
|
|
|
2019-11-21 20:47:14 +01:00
|
|
|
// try to backdate user1's latest message
|
2020-01-01 15:42:46 +01:00
|
|
|
pmc.recent.insert([1], 555);
|
2018-02-09 18:10:39 +01:00
|
|
|
|
|
|
|
assert.deepEqual(pmc.recent.get(), [
|
2019-11-21 20:47:14 +01:00
|
|
|
{user_ids_string: '1', max_message_id: 3001},
|
|
|
|
{user_ids_string: '2', max_message_id: 2001},
|
2020-01-01 15:55:36 +01:00
|
|
|
{user_ids_string: '2,11', max_message_id: 150},
|
2019-11-21 21:01:15 +01:00
|
|
|
{user_ids_string: '15', max_message_id: 7},
|
2018-02-09 18:10:39 +01:00
|
|
|
]);
|
2018-02-09 21:13:38 +01:00
|
|
|
|
2020-01-01 15:55:36 +01:00
|
|
|
assert.deepEqual(pmc.recent.get_strings(), ['1', '2', '2,11', '15']);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|