mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 05:23:35 +00:00
Add people.update_email().
The function people.update_email() is not yet connected to anything, but it sets the stage for upcoming changes. When emails get updated, fundamentally we just update the appropriate person object and add a new key to people_dict. We sort of get a shim for free--old email lookups will continue to work--but we add blueslip warnings for stale lookups.
This commit is contained in:
@@ -5,6 +5,7 @@ add_dependencies({
|
||||
global.stub_out_jquery();
|
||||
|
||||
var people = require("js/people.js");
|
||||
set_global('blueslip', {});
|
||||
|
||||
var _ = global._;
|
||||
|
||||
@@ -238,3 +239,52 @@ people.init();
|
||||
var email = people.slug_to_emails(slug);
|
||||
assert.equal(email, 'debbie71@example.com');
|
||||
}());
|
||||
|
||||
initialize();
|
||||
|
||||
(function test_updates() {
|
||||
var old_email = 'FOO@example.com';
|
||||
var new_email = 'bar@example.com';
|
||||
var user_id = 502;
|
||||
|
||||
var person = {
|
||||
email: old_email,
|
||||
user_id: user_id,
|
||||
full_name: 'Foo Barson',
|
||||
};
|
||||
people.add_in_realm(person);
|
||||
|
||||
// Do sanity checks on our data.
|
||||
assert.equal(people.get_by_email(old_email).user_id, user_id);
|
||||
assert.equal(people.realm_get(old_email).user_id, user_id);
|
||||
assert (!people.is_cross_realm_email(old_email));
|
||||
|
||||
assert.equal(people.get_by_email(new_email), undefined);
|
||||
|
||||
// DO THE EMAIL UPDATE HERE.
|
||||
people.update_email(user_id, new_email);
|
||||
|
||||
// Now look up using the new email.
|
||||
assert.equal(people.get_by_email(new_email).user_id, user_id);
|
||||
assert.equal(people.realm_get(new_email).user_id, user_id);
|
||||
assert (!people.is_cross_realm_email(new_email));
|
||||
|
||||
var all_people = people.get_all_persons();
|
||||
assert.equal(all_people.length, 2);
|
||||
|
||||
person = _.filter(all_people, function (p) {
|
||||
return (p.email === new_email);
|
||||
})[0];
|
||||
assert.equal(person.full_name, 'Foo Barson');
|
||||
|
||||
// Test shim where we can still retrieve user info using the
|
||||
// old email.
|
||||
var warning;
|
||||
global.blueslip.warn = function (w) {
|
||||
warning = w;
|
||||
};
|
||||
|
||||
person = people.get_by_email(old_email);
|
||||
assert(/Obsolete email.*FOO.*bar/.test(warning));
|
||||
assert.equal(person.user_id, user_id);
|
||||
}());
|
||||
|
||||
Reference in New Issue
Block a user