2019-11-02 00:06:25 +01:00
|
|
|
const noop = function () {};
|
2014-01-31 06:24:15 +01:00
|
|
|
|
|
|
|
set_global('document', {});
|
2019-07-25 09:13:22 +02:00
|
|
|
set_global('addEventListener', noop);
|
2016-07-30 20:01:15 +02:00
|
|
|
global.stub_out_jquery();
|
2014-01-31 06:24:15 +01:00
|
|
|
|
2017-12-16 23:25:31 +01:00
|
|
|
zrequire('message_store');
|
2017-11-08 18:48:09 +01:00
|
|
|
zrequire('server_events_dispatch');
|
|
|
|
zrequire('server_events');
|
2019-02-12 03:25:26 +01:00
|
|
|
zrequire('sent_messages');
|
2017-11-08 18:48:09 +01:00
|
|
|
|
2014-01-31 06:24:15 +01:00
|
|
|
set_global('channel', {});
|
|
|
|
set_global('home_msg_list', {
|
2016-08-05 21:42:19 +02:00
|
|
|
select_id: noop,
|
2016-12-03 23:17:57 +01:00
|
|
|
selected_id: function () {return 1;},
|
2014-01-31 06:24:15 +01:00
|
|
|
});
|
2014-03-07 00:44:15 +01:00
|
|
|
set_global('page_params', {test_suite: false});
|
2018-08-04 15:40:25 +02:00
|
|
|
set_global('reload_state', {
|
2016-12-03 23:17:57 +01:00
|
|
|
is_in_progress: function () {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
|
|
|
|
set_global('pointer', {});
|
|
|
|
|
2016-08-05 21:42:19 +02:00
|
|
|
set_global('echo', {
|
|
|
|
process_from_server: function (messages) {
|
|
|
|
return messages;
|
|
|
|
},
|
2020-02-17 14:43:59 +01:00
|
|
|
update_realm_filter_rules: noop,
|
2016-08-05 21:42:19 +02:00
|
|
|
});
|
2017-03-23 20:37:08 +01:00
|
|
|
set_global('ui_report', {
|
|
|
|
hide_error: function () { return false; },
|
|
|
|
show_error: function () { return false; },
|
|
|
|
});
|
2016-08-05 21:42:19 +02:00
|
|
|
|
2017-07-01 14:21:20 +02:00
|
|
|
server_events.home_view_loaded();
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('message_event', () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = {
|
2017-07-01 14:21:20 +02:00
|
|
|
type: 'message',
|
|
|
|
message: {
|
|
|
|
content: 'hello',
|
|
|
|
},
|
|
|
|
flags: [],
|
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let inserted;
|
2017-07-01 14:21:20 +02:00
|
|
|
set_global('message_events', {
|
|
|
|
insert_new_messages: function (messages) {
|
|
|
|
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
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('pointer_event', () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = {
|
2017-07-01 14:21:20 +02:00
|
|
|
type: 'pointer',
|
|
|
|
pointer: 999,
|
|
|
|
};
|
|
|
|
|
|
|
|
global.pointer.furthest_read = 0;
|
2018-08-04 08:37:23 +02:00
|
|
|
global.pointer.set_furthest_read = function (value) {
|
|
|
|
this.furthest_read = value;
|
|
|
|
};
|
2017-07-01 14:21:20 +02:00
|
|
|
global.pointer.server_furthest_read = 0;
|
2018-08-04 08:41:12 +02:00
|
|
|
global.pointer.set_server_furthest_read = function (value) {
|
|
|
|
this.server_furthest_read = value;
|
|
|
|
};
|
2017-07-01 14:21:20 +02:00
|
|
|
server_events._get_events_success([event]);
|
|
|
|
assert.equal(global.pointer.furthest_read, event.pointer);
|
|
|
|
assert.equal(global.pointer.server_furthest_read, event.pointer);
|
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();
|
2017-03-19 20:23:48 +01:00
|
|
|
set_global('message_events', {
|
2016-08-05 21:42:19 +02:00
|
|
|
insert_new_messages: function () {
|
|
|
|
throw Error('insert error');
|
|
|
|
},
|
|
|
|
update_messages: function () {
|
|
|
|
throw Error('update error');
|
2016-12-03 23:17:57 +01:00
|
|
|
},
|
2016-08-05 21:42:19 +02:00
|
|
|
});
|
2017-03-19 16:03:07 +01:00
|
|
|
set_global('stream_events', {
|
|
|
|
update_property: function () {
|
2016-08-05 21:42:19 +02:00
|
|
|
throw 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
|
|
|
};
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('event_dispatch_error', () => {
|
2018-07-10 10:16:42 +02:00
|
|
|
setup();
|
2014-01-31 06:24:15 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const data = {events: [{type: 'stream', op: 'update', id: 1, other: 'thing'}]};
|
2016-10-19 02:46:21 +02:00
|
|
|
global.channel.get = function (options) {
|
2014-01-31 06:24:15 +01:00
|
|
|
options.success(data);
|
|
|
|
};
|
|
|
|
|
2020-04-03 17:18:04 +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();
|
|
|
|
|
2018-07-10 10:16:42 +02:00
|
|
|
const logs = blueslip.get_test_logs('error');
|
|
|
|
assert.equal(logs.length, 1);
|
2018-12-07 22:14:28 +01:00
|
|
|
assert.equal(logs[0].more_info.event.type, 'stream');
|
|
|
|
assert.equal(logs[0].more_info.event.op, 'update');
|
|
|
|
assert.equal(logs[0].more_info.event.id, 1);
|
|
|
|
assert.equal(logs[0].more_info.other, undefined);
|
2020-04-03 17:18:04 +02:00
|
|
|
blueslip.reset();
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2014-01-31 06:24:15 +01:00
|
|
|
|
2018-05-15 12:40:07 +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
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const data = {events: [{type: 'message', id: 1, other: 'thing', message: {}}]};
|
2016-10-19 02:46:21 +02:00
|
|
|
global.channel.get = function (options) {
|
2014-01-31 06:24:15 +01:00
|
|
|
options.success(data);
|
|
|
|
};
|
|
|
|
|
2020-04-03 17:18:04 +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();
|
|
|
|
|
2018-07-10 10:16:42 +02:00
|
|
|
const logs = blueslip.get_test_logs('error');
|
|
|
|
assert.equal(logs.length, 1);
|
|
|
|
assert.equal(logs[0].more_info, undefined);
|
2020-04-03 17:18:04 +02:00
|
|
|
blueslip.reset();
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2014-01-31 06:24:15 +01:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('event_edit_message_error', () => {
|
2018-07-10 10:16:42 +02:00
|
|
|
setup();
|
2019-11-02 00:06:25 +01:00
|
|
|
const data = {events: [{type: 'update_message', id: 1, other: 'thing'}]};
|
2016-10-19 02:46:21 +02:00
|
|
|
global.channel.get = function (options) {
|
2014-01-31 06:24:15 +01:00
|
|
|
options.success(data);
|
|
|
|
};
|
2020-04-03 17:18:04 +02:00
|
|
|
blueslip.expect('error', 'Failed to update messages\nupdate error');
|
2014-01-31 06:24:15 +01:00
|
|
|
|
|
|
|
server_events.restart_get_events();
|
|
|
|
|
2018-07-10 10:16:42 +02:00
|
|
|
const logs = blueslip.get_test_logs('error');
|
|
|
|
assert.equal(logs.length, 1);
|
|
|
|
assert.equal(logs[0].more_info, undefined);
|
2020-04-03 17:18:04 +02:00
|
|
|
blueslip.reset();
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|