2014-01-31 06:24:15 +01:00
|
|
|
var assert = require('assert');
|
|
|
|
|
|
|
|
add_dependencies({
|
|
|
|
util: 'js/util.js',
|
2016-12-03 23:17:57 +01:00
|
|
|
tutorial: 'js/tutorial.js',
|
2014-01-31 06:24:15 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
var noop = function () {};
|
|
|
|
|
|
|
|
set_global('document', {});
|
|
|
|
set_global('window', {
|
2016-12-03 23:17:57 +01:00
|
|
|
addEventListener: noop,
|
2014-01-31 06:24:15 +01:00
|
|
|
});
|
2016-07-30 20:01:15 +02:00
|
|
|
|
|
|
|
global.stub_out_jquery();
|
2014-01-31 06:24:15 +01:00
|
|
|
|
|
|
|
set_global('blueslip', {});
|
|
|
|
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});
|
2016-03-31 08:39:01 +02:00
|
|
|
set_global('reload', {
|
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
|
|
|
|
2016-08-05 21:42:19 +02:00
|
|
|
set_global('echo', {
|
|
|
|
process_from_server: function (messages) {
|
|
|
|
return messages;
|
|
|
|
},
|
2016-12-03 23:17:57 +01:00
|
|
|
set_realm_filters: noop,
|
2016-08-05 21:42:19 +02:00
|
|
|
});
|
|
|
|
|
2014-01-31 06:24:15 +01:00
|
|
|
var server_events = require('js/server_events.js');
|
|
|
|
|
2016-08-05 21:42:19 +02:00
|
|
|
// Start blueslip tests here
|
|
|
|
|
2014-01-31 06:24:15 +01:00
|
|
|
var setup = function (results) {
|
|
|
|
server_events.home_view_loaded();
|
2016-08-05 21:42:19 +02:00
|
|
|
set_global('message_store', {
|
|
|
|
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
|
|
|
});
|
|
|
|
set_global('subs', {
|
|
|
|
update_subscription_properties: function () {
|
|
|
|
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
|
|
|
global.blueslip.error = function (msg, more_info, stack) {
|
|
|
|
results.msg = msg;
|
|
|
|
results.more_info = more_info;
|
|
|
|
results.stack = stack;
|
|
|
|
};
|
2014-02-10 22:48:49 +01:00
|
|
|
global.blueslip.exception_msg = function (ex) {
|
|
|
|
return ex.message;
|
|
|
|
};
|
2014-01-31 06:24:15 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
(function test_event_dispatch_error() {
|
|
|
|
var results = {};
|
|
|
|
setup(results);
|
|
|
|
|
|
|
|
var 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);
|
|
|
|
};
|
|
|
|
|
|
|
|
server_events.restart_get_events();
|
|
|
|
|
2014-02-10 22:48:49 +01:00
|
|
|
assert.equal(results.msg, 'Failed to process an event\n' +
|
2016-08-05 21:42:19 +02:00
|
|
|
'subs update error');
|
2014-01-31 06:24:15 +01:00
|
|
|
assert.equal(results.more_info.event.type , 'stream');
|
|
|
|
assert.equal(results.more_info.event.op , 'update');
|
|
|
|
assert.equal(results.more_info.event.id , 1);
|
|
|
|
assert.equal(results.more_info.other , undefined);
|
|
|
|
}());
|
|
|
|
|
|
|
|
|
|
|
|
(function test_event_new_message_error() {
|
|
|
|
var results = {};
|
|
|
|
setup(results);
|
|
|
|
|
|
|
|
var 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);
|
|
|
|
};
|
|
|
|
|
|
|
|
server_events.restart_get_events();
|
|
|
|
|
2014-02-10 22:48:49 +01:00
|
|
|
assert.equal(results.msg, 'Failed to insert new messages\n' +
|
2016-08-05 21:42:19 +02:00
|
|
|
'insert error');
|
2014-01-31 06:24:15 +01:00
|
|
|
assert.equal(results.more_info, undefined);
|
|
|
|
}());
|
|
|
|
|
|
|
|
(function test_event_edit_message_error() {
|
|
|
|
var results = {};
|
|
|
|
setup(results);
|
|
|
|
|
|
|
|
var 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);
|
|
|
|
};
|
|
|
|
|
|
|
|
server_events.restart_get_events();
|
|
|
|
|
2014-02-10 22:48:49 +01:00
|
|
|
assert.equal(results.msg, 'Failed to update messages\n' +
|
2016-08-05 21:42:19 +02:00
|
|
|
'update error');
|
2014-01-31 06:24:15 +01:00
|
|
|
assert.equal(results.more_info, undefined);
|
|
|
|
}());
|