Skip to content

Commit

Permalink
presence: Test listening_bots.
Browse files Browse the repository at this point in the history
  • Loading branch information
marco committed Dec 29, 2017
1 parent 38e94d9 commit eb187e9
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 0 deletions.
3 changes: 3 additions & 0 deletions frontend_tests/node_tests/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ activity.update_huddles = function () {};

global.compile_template('user_presence_row');
global.compile_template('user_presence_rows');
global.compile_template('listening_bot_presence_row');
global.compile_template('listening_bot_presence_rows');
global.compile_template('group_pms');

var presence_info = {};
Expand Down Expand Up @@ -272,6 +274,7 @@ presence.presence_info[me.user_id] = { status: activity.ACTIVE };
activity.set_user_list_filter();

(function test_presence_list_full_update() {
page_params.realm_listening_bots = ['helloworld', 'jira'];
var users = activity.build_user_sidebar();
assert.deepEqual(users, [{
name: 'Fred Flintstone',
Expand Down
20 changes: 20 additions & 0 deletions frontend_tests/node_tests/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,26 @@ function render(template_name, args) {
assert.equal(input.text().trim(), "devel");
}());

(function listening_bot_presence_rows() {
var args = {
bots: [
{
name: "helloworld",
},
{
name: "reminder",
},
],
};

var html = render('listening_bot_presence_rows', args);

global.write_handlebars_output("listening_bot_presence_rows", html);

var first_bot_displayed_name = $(html).find(".bot-name").filter(":first");
assert.equal(first_bot_displayed_name.text(), 'helloworld Bot');
}());

(function single_message() {
var message = {
msg: {
Expand Down
13 changes: 13 additions & 0 deletions zerver/tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
do_deactivate_stream,
do_deactivate_user,
do_delete_message,
do_mark_bot_listening,
do_mark_hotspot_as_read,
do_mute_topic,
do_reactivate_user,
Expand Down Expand Up @@ -965,6 +966,17 @@ def test_presence_events_multiple_clients(self) -> None:
error = schema_checker_android('events[0]', events[0])
self.assert_on_error(error)

def test_listening_bots(self) -> None:
schema_checker = self.check_events_dict([
('type', equals('realm')),
('op', equals('update')),
('property', equals('listening_bots_str')),
('value', equals('helloworld')),
])
events = self.do_test(lambda: do_mark_bot_listening(self.user_profile.realm, 'helloworld', True))
error = schema_checker('events[0]', events[0])
self.assert_on_error(error)

def test_pointer_events(self) -> None:
schema_checker = self.check_events_dict([
('type', equals('pointer')),
Expand Down Expand Up @@ -1213,6 +1225,7 @@ def do_set_realm_property_test(self, name: str) -> None:
message_retention_days=[10, 20],
name=[u'Zulip', u'New Name'],
waiting_period_threshold=[10, 20],
listening_bots_str = [u'', u'helloworld', u'helloworld,chess', u'jira'],
) # type: Dict[str, Any]

vals = test_values.get(name)
Expand Down
2 changes: 2 additions & 0 deletions zerver/tests/test_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ def test_home(self) -> None:
"realm_invite_by_admins_only",
"realm_invite_required",
"realm_is_zephyr_mirror_realm",
'realm_listening_bots',
'realm_listening_bots_str',
"realm_mandatory_topics",
"realm_message_content_edit_limit_seconds",
"realm_message_retention_days",
Expand Down
29 changes: 29 additions & 0 deletions zerver/tests/test_realm.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
do_set_realm_property,
do_deactivate_realm,
do_deactivate_stream,
do_mark_bot_listening,
)

from zerver.lib.send_email import send_future_email
Expand Down Expand Up @@ -263,6 +264,33 @@ def test_change_realm_default_language(self) -> None:
realm = get_realm('zulip')
self.assertNotEqual(realm.default_language, invalid_lang)

def test_mark_bot_listening(self) -> None:
email = self.example_email("hamlet")
self.login(email)

data = {'bot_name': 'helloworld', 'is_listening': 'true'}
response = self.client_post('/json/realm/mark_bot_listening', info=data)
self.assert_json_success(response)
realm = get_realm('zulip')
self.assertEqual(realm.listening_bots_str, 'helloworld')

data = {'bot_name': 'chess', 'is_listening': 'true'}
response = self.client_post('/json/realm/mark_bot_listening', info=data)
self.assert_json_success(response)
realm = get_realm('zulip')
self.assertEqual(realm.listening_bots_str, 'helloworld,chess')

data = {'bot_name': 'helloworld', 'is_listening': 'false'}
response = self.client_post('/json/realm/mark_bot_listening', info=data)
self.assert_json_success(response)
realm = get_realm('zulip')
self.assertEqual(realm.listening_bots_str, 'chess')

data = {'bot_name': 'chess', 'is_listening': 'false'}
response = self.client_post('/json/realm/mark_bot_listening', info=data)
self.assert_json_success(response)
realm = get_realm('zulip')
self.assertEqual(realm.listening_bots_str, '')

class RealmAPITest(ZulipTestCase):

Expand Down Expand Up @@ -297,6 +325,7 @@ def do_test_realm_update_api(self, name: str) -> None:
message_retention_days=[10, 20],
name=[u'Zulip', u'New Name'],
waiting_period_threshold=[10, 20],
listening_bots_str=[u'', u'helloworld'],
) # type: Dict[str, Any]
vals = test_values.get(name)
if Realm.property_types[name] is bool:
Expand Down

0 comments on commit eb187e9

Please sign in to comment.