2020-07-15 01:29:15 +02:00
|
|
|
set_global("channel", {});
|
|
|
|
zrequire("user_status");
|
2018-12-19 17:11:17 +01:00
|
|
|
|
|
|
|
function initialize() {
|
2020-02-25 12:16:26 +01:00
|
|
|
const params = {
|
|
|
|
user_status: {
|
2020-07-15 01:29:15 +02:00
|
|
|
1: {away: true, status_text: "in a meeting"},
|
2020-02-25 12:16:26 +01:00
|
|
|
2: {away: true},
|
|
|
|
3: {away: true},
|
|
|
|
},
|
2019-01-21 19:06:03 +01:00
|
|
|
};
|
2020-02-25 12:16:26 +01:00
|
|
|
user_status.initialize(params);
|
2018-12-19 17:11:17 +01:00
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("basics", () => {
|
2018-12-19 17:11:17 +01:00
|
|
|
initialize();
|
|
|
|
assert(user_status.is_away(2));
|
|
|
|
assert(!user_status.is_away(99));
|
|
|
|
|
|
|
|
assert(!user_status.is_away(4));
|
|
|
|
user_status.set_away(4);
|
|
|
|
assert(user_status.is_away(4));
|
|
|
|
user_status.revoke_away(4);
|
|
|
|
assert(!user_status.is_away(4));
|
2019-01-23 19:25:22 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(user_status.get_status_text(1), "in a meeting");
|
2019-01-23 19:25:22 +01:00
|
|
|
|
|
|
|
user_status.set_status_text({
|
|
|
|
user_id: 2,
|
2020-07-15 01:29:15 +02:00
|
|
|
status_text: "out to lunch",
|
2019-01-23 19:25:22 +01:00
|
|
|
});
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(user_status.get_status_text(2), "out to lunch");
|
2019-01-23 19:25:22 +01:00
|
|
|
|
|
|
|
user_status.set_status_text({
|
|
|
|
user_id: 2,
|
2020-07-15 01:29:15 +02:00
|
|
|
status_text: "",
|
2019-01-23 19:25:22 +01:00
|
|
|
});
|
|
|
|
assert.equal(user_status.get_status_text(2), undefined);
|
2018-12-19 17:11:17 +01:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("server", () => {
|
2018-12-19 17:11:17 +01:00
|
|
|
initialize();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let sent_data;
|
|
|
|
let success;
|
2018-12-19 17:11:17 +01:00
|
|
|
|
|
|
|
channel.post = (opts) => {
|
2019-01-23 19:25:22 +01:00
|
|
|
sent_data = opts.data;
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(opts.url, "/json/users/me/status");
|
2019-01-26 21:14:33 +01:00
|
|
|
success = opts.success;
|
2018-12-19 17:11:17 +01:00
|
|
|
};
|
|
|
|
|
2019-01-23 19:25:22 +01:00
|
|
|
assert.equal(sent_data, undefined);
|
2018-12-19 17:11:17 +01:00
|
|
|
|
|
|
|
user_status.server_set_away();
|
2019-01-23 19:25:22 +01:00
|
|
|
assert.deepEqual(sent_data, {away: true, status_text: undefined});
|
2018-12-19 17:11:17 +01:00
|
|
|
|
|
|
|
user_status.server_revoke_away();
|
2019-01-23 19:25:22 +01:00
|
|
|
assert.deepEqual(sent_data, {away: false, status_text: undefined});
|
2019-01-26 21:14:33 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let called;
|
2019-01-26 21:14:33 +01:00
|
|
|
|
|
|
|
user_status.server_update({
|
2020-07-15 01:29:15 +02:00
|
|
|
status_text: "out to lunch",
|
2019-01-26 21:14:33 +01:00
|
|
|
success: () => {
|
|
|
|
called = true;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
success();
|
|
|
|
assert(called);
|
2018-12-19 17:11:17 +01:00
|
|
|
});
|
2020-01-12 22:17:02 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("defensive checks", () => {
|
|
|
|
blueslip.expect("error", "need ints for user_id", 2);
|
|
|
|
user_status.set_away("string");
|
|
|
|
user_status.revoke_away("string");
|
2020-01-12 22:17:02 +01:00
|
|
|
});
|