2018-04-20 18:22:28 +02:00
|
|
|
zrequire('people');
|
|
|
|
zrequire('presence');
|
|
|
|
zrequire('util');
|
|
|
|
zrequire('buddy_data');
|
|
|
|
|
|
|
|
// The buddy_data module is mostly tested indirectly through
|
|
|
|
// activity.js, but we should feel free to add direct tests
|
|
|
|
// here.
|
|
|
|
|
|
|
|
|
|
|
|
set_global('page_params', {});
|
|
|
|
|
|
|
|
(function make_people() {
|
|
|
|
_.each(_.range(1000, 2000), (i) => {
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
}());
|
|
|
|
|
|
|
|
(function activate_people() {
|
|
|
|
const server_time = 9999;
|
|
|
|
const info = {
|
|
|
|
website: {
|
|
|
|
status: "active",
|
|
|
|
timestamp: server_time,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
// Make 400 of the users active
|
|
|
|
_.each(_.range(1000, 1400), (user_id) => {
|
|
|
|
presence.set_user_status(user_id, info, server_time);
|
|
|
|
});
|
|
|
|
|
|
|
|
// And then 300 not active
|
|
|
|
_.each(_.range(1400, 1700), (user_id) => {
|
|
|
|
presence.set_user_status(user_id, {}, server_time);
|
|
|
|
});
|
|
|
|
}());
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('user_ids', () => {
|
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);
|
|
|
|
|
|
|
|
// We don't match on "s", because it's not at the start of a
|
|
|
|
// word in the name/email.
|
|
|
|
user_ids = buddy_data.get_filtered_and_sorted_user_ids('s');
|
|
|
|
assert.equal(user_ids.length, 0);
|
|
|
|
|
|
|
|
// We match on "h" for the first name, and the result limit
|
|
|
|
// is relaxed for searches.
|
|
|
|
user_ids = buddy_data.get_filtered_and_sorted_user_ids('h');
|
|
|
|
assert.equal(user_ids.length, 1000);
|
|
|
|
|
|
|
|
// We match on "p" for the email.
|
|
|
|
user_ids = buddy_data.get_filtered_and_sorted_user_ids('p');
|
|
|
|
assert.equal(user_ids.length, 1000);
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
});
|