2018-08-01 21:17:03 +02:00
|
|
|
const _page_params = {};
|
|
|
|
|
|
|
|
set_global('page_params', _page_params);
|
2018-04-20 18:22:28 +02:00
|
|
|
zrequire('people');
|
|
|
|
zrequire('presence');
|
|
|
|
zrequire('util');
|
2018-12-19 21:16:03 +01:00
|
|
|
zrequire('user_status');
|
2018-04-20 18:22:28 +02:00
|
|
|
zrequire('buddy_data');
|
2018-12-20 15:55:20 +01:00
|
|
|
zrequire('user_status');
|
2018-04-20 18:22:28 +02:00
|
|
|
|
|
|
|
// The buddy_data module is mostly tested indirectly through
|
|
|
|
// activity.js, but we should feel free to add direct tests
|
|
|
|
// here.
|
|
|
|
|
2018-12-18 19:25:14 +01:00
|
|
|
const selma = {
|
|
|
|
user_id: 1000,
|
|
|
|
full_name: 'Human Selma',
|
|
|
|
email: 'selma@example.com',
|
|
|
|
};
|
|
|
|
|
|
|
|
const me = {
|
|
|
|
user_id: 1001,
|
|
|
|
full_name: 'Human Myself',
|
|
|
|
email: 'self@example.com',
|
|
|
|
};
|
|
|
|
|
|
|
|
const bot = {
|
|
|
|
user_id: 55555,
|
|
|
|
full_name: 'Red Herring Bot',
|
|
|
|
email: 'bot@example.com',
|
|
|
|
is_bot: true,
|
|
|
|
};
|
|
|
|
|
2018-09-08 14:41:41 +02:00
|
|
|
function make_people() {
|
2018-12-18 19:25:14 +01:00
|
|
|
_.each(_.range(1002, 2000), (i) => {
|
2018-04-20 18:22:28 +02:00
|
|
|
const person = {
|
|
|
|
user_id: i,
|
2018-04-23 23:13:52 +02:00
|
|
|
full_name: `Human ${i}`,
|
2018-04-20 18:22:28 +02:00
|
|
|
email: `person${i}@example.com`,
|
|
|
|
};
|
|
|
|
people.add_in_realm(person);
|
|
|
|
});
|
2018-09-08 14:41:41 +02:00
|
|
|
|
|
|
|
people.add_in_realm(bot);
|
2018-12-18 19:25:14 +01:00
|
|
|
people.add_in_realm(selma);
|
|
|
|
people.add_in_realm(me);
|
2018-12-18 18:50:58 +01:00
|
|
|
|
2018-12-18 19:25:14 +01:00
|
|
|
people.initialize_current_user(me.user_id);
|
2018-09-08 14:41:41 +02:00
|
|
|
}
|
|
|
|
|
2018-04-20 18:22:28 +02:00
|
|
|
|
2018-12-18 19:25:14 +01:00
|
|
|
function activate_people() {
|
2018-04-20 18:22:28 +02:00
|
|
|
const server_time = 9999;
|
|
|
|
const info = {
|
|
|
|
website: {
|
|
|
|
status: "active",
|
|
|
|
timestamp: server_time,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
// Make 400 of the users active
|
2018-12-18 18:30:40 +01:00
|
|
|
presence.set_info_for_user(selma.user_id, info, server_time);
|
|
|
|
presence.set_info_for_user(me.user_id, info, server_time);
|
2018-12-18 19:25:14 +01:00
|
|
|
|
2018-12-18 18:30:40 +01:00
|
|
|
_.each(_.range(1000, 1400), (user_id) => {
|
|
|
|
presence.set_info_for_user(user_id, info, server_time);
|
2018-04-20 18:22:28 +02:00
|
|
|
});
|
|
|
|
|
2018-12-18 19:25:14 +01:00
|
|
|
|
2018-04-20 18:22:28 +02:00
|
|
|
// And then 300 not active
|
|
|
|
_.each(_.range(1400, 1700), (user_id) => {
|
2018-12-18 18:30:40 +01:00
|
|
|
presence.set_info_for_user(user_id, {}, server_time);
|
2018-04-20 18:22:28 +02:00
|
|
|
});
|
2018-12-18 19:25:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
make_people();
|
|
|
|
activate_people();
|
|
|
|
|
2018-12-19 21:16:03 +01:00
|
|
|
run_test('buddy_status', () => {
|
|
|
|
assert.equal(buddy_data.buddy_status(selma.user_id), 'active');
|
|
|
|
user_status.set_away(selma.user_id);
|
|
|
|
assert.equal(buddy_data.buddy_status(selma.user_id), 'away_them');
|
|
|
|
user_status.revoke_away(selma.user_id);
|
|
|
|
assert.equal(buddy_data.buddy_status(selma.user_id), 'active');
|
|
|
|
|
|
|
|
assert.equal(buddy_data.buddy_status(me.user_id), 'active');
|
|
|
|
user_status.set_away(me.user_id);
|
|
|
|
assert.equal(buddy_data.buddy_status(me.user_id), 'away_me');
|
|
|
|
user_status.revoke_away(me.user_id);
|
|
|
|
assert.equal(buddy_data.buddy_status(me.user_id), 'active');
|
|
|
|
});
|
|
|
|
|
2018-12-18 19:25:14 +01:00
|
|
|
run_test('simple search', () => {
|
|
|
|
const user_ids = buddy_data.get_filtered_and_sorted_user_ids('sel');
|
|
|
|
|
2018-12-18 19:29:08 +01:00
|
|
|
assert.deepEqual(user_ids, [selma.user_id]);
|
2018-06-02 01:42:05 +02:00
|
|
|
});
|
2018-04-20 18:22:28 +02:00
|
|
|
|
2018-12-18 19:25:14 +01:00
|
|
|
run_test('bulk_data_hacks', () => {
|
2018-04-23 23:13:52 +02:00
|
|
|
var user_ids;
|
2018-04-20 18:22:28 +02:00
|
|
|
|
2018-04-23 23:13:52 +02:00
|
|
|
// Even though we have 1000 users, we only get the 400 active
|
2018-04-20 18:22:28 +02:00
|
|
|
// users. This is a consequence of buddy_data.maybe_shrink_list.
|
2018-04-23 23:13:52 +02:00
|
|
|
user_ids = buddy_data.get_filtered_and_sorted_user_ids();
|
2018-04-20 18:22:28 +02:00
|
|
|
assert.equal(user_ids.length, 400);
|
2018-04-23 23:13:52 +02:00
|
|
|
|
|
|
|
user_ids = buddy_data.get_filtered_and_sorted_user_ids('');
|
|
|
|
assert.equal(user_ids.length, 400);
|
|
|
|
|
2018-12-18 19:25:14 +01:00
|
|
|
// We don't match on "so", because it's not at the start of a
|
2018-04-23 23:13:52 +02:00
|
|
|
// word in the name/email.
|
2018-12-18 19:25:14 +01:00
|
|
|
user_ids = buddy_data.get_filtered_and_sorted_user_ids('so');
|
2018-04-23 23:13:52 +02:00
|
|
|
assert.equal(user_ids.length, 0);
|
|
|
|
|
|
|
|
// We match on "h" for the first name, and the result limit
|
2018-12-18 19:29:08 +01:00
|
|
|
// is relaxed for searches. (We exclude "me", though.)
|
2018-04-23 23:13:52 +02:00
|
|
|
user_ids = buddy_data.get_filtered_and_sorted_user_ids('h');
|
2018-12-18 19:29:08 +01:00
|
|
|
assert.equal(user_ids.length, 999);
|
2018-04-23 23:13:52 +02:00
|
|
|
|
|
|
|
// We match on "p" for the email.
|
|
|
|
user_ids = buddy_data.get_filtered_and_sorted_user_ids('p');
|
2018-12-18 19:25:14 +01:00
|
|
|
assert.equal(user_ids.length, 998);
|
2018-04-23 23:13:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
// Make our shrink limit higher, and go back to an empty search.
|
|
|
|
// We won't get all 1000 users, just the present ones.
|
|
|
|
buddy_data.max_size_before_shrinking = 50000;
|
|
|
|
|
|
|
|
user_ids = buddy_data.get_filtered_and_sorted_user_ids('');
|
|
|
|
assert.equal(user_ids.length, 700);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-12-20 15:55:20 +01:00
|
|
|
|
|
|
|
run_test('level', () => {
|
|
|
|
presence.presence_info = {};
|
|
|
|
assert.equal(buddy_data.level(me.user_id), 0);
|
|
|
|
assert.equal(buddy_data.level(selma.user_id), 3);
|
|
|
|
|
|
|
|
const server_time = 9999;
|
|
|
|
const info = {
|
|
|
|
website: {
|
|
|
|
status: "active",
|
|
|
|
timestamp: server_time,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
presence.set_info_for_user(me.user_id, info, server_time);
|
|
|
|
presence.set_info_for_user(selma.user_id, info, server_time);
|
|
|
|
|
|
|
|
assert.equal(buddy_data.level(me.user_id), 0);
|
|
|
|
assert.equal(buddy_data.level(selma.user_id), 1);
|
|
|
|
|
|
|
|
user_status.set_away(me.user_id);
|
|
|
|
user_status.set_away(selma.user_id);
|
|
|
|
|
2018-12-19 21:16:03 +01:00
|
|
|
// Selma gets demoted to level 3, but "me"
|
|
|
|
// stays in level 0.
|
2018-12-20 15:55:20 +01:00
|
|
|
assert.equal(buddy_data.level(me.user_id), 0);
|
2018-12-19 21:16:03 +01:00
|
|
|
assert.equal(buddy_data.level(selma.user_id), 3);
|
2018-12-20 15:55:20 +01:00
|
|
|
});
|