2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2020-12-01 00:02:16 +01:00
|
|
|
const {set_global, stub_out_jquery, zrequire} = require("../zjsunit/namespace");
|
2020-12-01 00:39:47 +01:00
|
|
|
const {run_test} = require("../zjsunit/test");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const noop = function () {};
|
2014-01-31 06:24:15 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("document", {});
|
|
|
|
set_global("addEventListener", noop);
|
2020-12-01 00:02:16 +01:00
|
|
|
stub_out_jquery();
|
2014-01-31 06:24:15 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
zrequire("message_store");
|
|
|
|
zrequire("server_events_dispatch");
|
|
|
|
zrequire("server_events");
|
|
|
|
zrequire("sent_messages");
|
2017-11-08 18:48:09 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("channel", {});
|
|
|
|
set_global("home_msg_list", {
|
2016-08-05 21:42:19 +02:00
|
|
|
select_id: noop,
|
2020-07-20 22:18:43 +02:00
|
|
|
selected_id() {
|
2020-07-15 00:34:28 +02:00
|
|
|
return 1;
|
|
|
|
},
|
2014-01-31 06:24:15 +01:00
|
|
|
});
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("page_params", {test_suite: false});
|
|
|
|
set_global("reload_state", {
|
2020-07-20 22:18:43 +02:00
|
|
|
is_in_progress() {
|
2020-07-15 00:34:28 +02:00
|
|
|
return false;
|
|
|
|
},
|
2016-03-31 08:39:01 +02:00
|
|
|
});
|
2014-01-31 06:24:15 +01:00
|
|
|
|
2017-07-01 14:21:20 +02:00
|
|
|
// we also directly write to pointer
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("pointer", {});
|
2017-07-01 14:21:20 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("echo", {
|
2020-07-20 22:18:43 +02:00
|
|
|
process_from_server(messages) {
|
2016-08-05 21:42:19 +02:00
|
|
|
return messages;
|
|
|
|
},
|
2020-02-17 14:43:59 +01:00
|
|
|
update_realm_filter_rules: noop,
|
2016-08-05 21:42:19 +02:00
|
|
|
});
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("ui_report", {
|
2020-07-20 22:18:43 +02:00
|
|
|
hide_error() {
|
2020-07-15 00:34:28 +02:00
|
|
|
return false;
|
|
|
|
},
|
2020-07-20 22:18:43 +02:00
|
|
|
show_error() {
|
2020-07-15 00:34:28 +02:00
|
|
|
return false;
|
|
|
|
},
|
2017-03-23 20:37:08 +01:00
|
|
|
});
|
2016-08-05 21:42:19 +02:00
|
|
|
|
2017-07-01 14:21:20 +02:00
|
|
|
server_events.home_view_loaded();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("message_event", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = {
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "message",
|
2017-07-01 14:21:20 +02:00
|
|
|
message: {
|
2020-07-15 01:29:15 +02:00
|
|
|
content: "hello",
|
2017-07-01 14:21:20 +02:00
|
|
|
},
|
|
|
|
flags: [],
|
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let inserted;
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("message_events", {
|
2020-07-20 22:18:43 +02:00
|
|
|
insert_new_messages(messages) {
|
2017-07-01 14:21:20 +02:00
|
|
|
assert.equal(messages[0].content, event.message.content);
|
|
|
|
inserted = true;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
server_events._get_events_success([event]);
|
|
|
|
assert(inserted);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-07-01 14:21:20 +02:00
|
|
|
|
2016-08-05 21:42:19 +02:00
|
|
|
// Start blueslip tests here
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const setup = function () {
|
2014-01-31 06:24:15 +01:00
|
|
|
server_events.home_view_loaded();
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("message_events", {
|
2020-07-20 22:18:43 +02:00
|
|
|
insert_new_messages() {
|
2020-10-07 09:58:04 +02:00
|
|
|
throw new Error("insert error");
|
2016-08-05 21:42:19 +02:00
|
|
|
},
|
2020-07-20 22:18:43 +02:00
|
|
|
update_messages() {
|
2020-10-07 09:58:04 +02:00
|
|
|
throw new Error("update error");
|
2016-12-03 23:17:57 +01:00
|
|
|
},
|
2016-08-05 21:42:19 +02:00
|
|
|
});
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("stream_events", {
|
2020-07-20 22:18:43 +02:00
|
|
|
update_property() {
|
2020-10-07 09:58:04 +02:00
|
|
|
throw new Error("subs update error");
|
2016-12-03 23:17:57 +01:00
|
|
|
},
|
2016-08-05 21:42:19 +02:00
|
|
|
});
|
2014-01-31 06:24:15 +01:00
|
|
|
};
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("event_dispatch_error", () => {
|
2018-07-10 10:16:42 +02:00
|
|
|
setup();
|
2014-01-31 06:24:15 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const data = {events: [{type: "stream", op: "update", id: 1, other: "thing"}]};
|
2020-12-01 00:57:57 +01:00
|
|
|
channel.get = function (options) {
|
2014-01-31 06:24:15 +01:00
|
|
|
options.success(data);
|
|
|
|
};
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("error", "Failed to process an event\nsubs update error");
|
2018-07-10 10:16:42 +02:00
|
|
|
|
2014-01-31 06:24:15 +01:00
|
|
|
server_events.restart_get_events();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const logs = blueslip.get_test_logs("error");
|
2018-07-10 10:16:42 +02:00
|
|
|
assert.equal(logs.length, 1);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(logs[0].more_info.event.type, "stream");
|
|
|
|
assert.equal(logs[0].more_info.event.op, "update");
|
2018-12-07 22:14:28 +01:00
|
|
|
assert.equal(logs[0].more_info.event.id, 1);
|
|
|
|
assert.equal(logs[0].more_info.other, undefined);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2014-01-31 06:24:15 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("event_new_message_error", () => {
|
2018-07-10 10:16:42 +02:00
|
|
|
setup();
|
2014-01-31 06:24:15 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const data = {events: [{type: "message", id: 1, other: "thing", message: {}}]};
|
2020-12-01 00:57:57 +01:00
|
|
|
channel.get = function (options) {
|
2014-01-31 06:24:15 +01:00
|
|
|
options.success(data);
|
|
|
|
};
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("error", "Failed to insert new messages\ninsert error");
|
2018-07-10 10:16:42 +02:00
|
|
|
|
2014-01-31 06:24:15 +01:00
|
|
|
server_events.restart_get_events();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const logs = blueslip.get_test_logs("error");
|
2018-07-10 10:16:42 +02:00
|
|
|
assert.equal(logs.length, 1);
|
|
|
|
assert.equal(logs[0].more_info, undefined);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2014-01-31 06:24:15 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("event_edit_message_error", () => {
|
2018-07-10 10:16:42 +02:00
|
|
|
setup();
|
2020-07-15 01:29:15 +02:00
|
|
|
const data = {events: [{type: "update_message", id: 1, other: "thing"}]};
|
2020-12-01 00:57:57 +01:00
|
|
|
channel.get = function (options) {
|
2014-01-31 06:24:15 +01:00
|
|
|
options.success(data);
|
|
|
|
};
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("error", "Failed to update messages\nupdate error");
|
2014-01-31 06:24:15 +01:00
|
|
|
|
|
|
|
server_events.restart_get_events();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const logs = blueslip.get_test_logs("error");
|
2018-07-10 10:16:42 +02:00
|
|
|
assert.equal(logs.length, 1);
|
|
|
|
assert.equal(logs[0].more_info, undefined);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|