people.js: Create new add_cross_realm_user function.

The people.js tests were using _add_user function to add
cross realm bots. The problem is that _add_user function
doesn't properly simulates the adding process as it doesn't
add the user in cross_realm_dict as well.

To solve this and eliminate the need of calling
people.initialize(), which means the params obj needs to be
defined, we extracted the whole logic of adding a cross realm
user into a separete function, add_cross_realm_user.
This commit is contained in:
clarammdantas 2020-05-26 22:09:17 -03:00 committed by Tim Abbott
parent 368e9572cc
commit c90c8c0b19
2 changed files with 9 additions and 5 deletions

View File

@ -265,7 +265,7 @@ run_test('basics', () => {
// Add our cross-realm bot. It won't add to our human // Add our cross-realm bot. It won't add to our human
// count, and it has no owner. // count, and it has no owner.
people._add_user(welcome_bot); people.add_cross_realm_user(welcome_bot);
assert.equal(people.get_bot_owner_user(welcome_bot), undefined); assert.equal(people.get_bot_owner_user(welcome_bot), undefined);
assert.equal(people.get_active_human_count(), 1); assert.equal(people.get_active_human_count(), 1);
assert.equal( assert.equal(

View File

@ -1048,6 +1048,13 @@ exports.add = function (person) {
exports._add_user(person); exports._add_user(person);
}; };
exports.add_cross_realm_user = function (person) {
if (!people_dict.has(person.email)) {
exports._add_user(person);
}
cross_realm_dict.set(person.user_id, person);
};
exports.deactivate = function (person) { exports.deactivate = function (person) {
// We don't fully remove a person from all of our data // We don't fully remove a person from all of our data
// structures, because deactivated users can be part // structures, because deactivated users can be part
@ -1242,10 +1249,7 @@ exports.initialize = function (my_user_id, params) {
} }
for (const person of params.cross_realm_bots) { for (const person of params.cross_realm_bots) {
if (!people_dict.has(person.email)) { exports.add_cross_realm_user(person);
exports._add_user(person);
}
cross_realm_dict.set(person.user_id, person);
} }
exports.initialize_current_user(my_user_id); exports.initialize_current_user(my_user_id);