"use strict"; const {strict: assert} = require("assert"); const {zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const params = { alert_words: ["alertone", "alerttwo", "alertthree", "al*rt.*s", ".+", "emoji"], }; const people = zrequire("people"); zrequire("alert_words"); alert_words.initialize(params); people.add_active_user({ email: "tester@zulip.com", full_name: "Tester von Tester", user_id: 42, }); people.initialize_current_user(42); const regular_message = { sender_email: "another@zulip.com", content: "
a message
", }; const own_message = { sender_email: "tester@zulip.com", content: "hey this message alertone
", alerted: true, }; const other_message = { sender_email: "another@zulip.com", content: "another alertone message
", alerted: true, }; const caps_message = { sender_email: "another@zulip.com", content: "another ALERTtwo message
", alerted: true, }; const alertwordboundary_message = { sender_email: "another@zulip.com", content: "another alertthreemessage
", alerted: false, }; const multialert_message = { sender_email: "another@zulip.com", content: "another alertthreemessage alertone and then alerttwo
", alerted: true, }; const unsafe_word_message = { sender_email: "another@zulip.com", content: "gotta al*rt.*s all
", alerted: true, }; const alert_in_url_message = { sender_email: "another@zulip.com", content: "http://www.google.com/alertone/me
", alerted: true, }; const question_word_message = { sender_email: "another@zulip.com", content: "still alertone? me
", alerted: true, }; const alert_domain_message = { sender_email: "another@zulip.com", content: 'now with link www.alerttwo.us/foo/bar
', alerted: true, }; // This test ensure we are not mucking up rendered HTML content. const message_with_emoji = { sender_email: "another@zulip.com", content: 'I
emoji!
another alertone message
", ); alert_words.process_message(caps_message); assert.equal( caps_message.content, "another ALERTtwo message
", ); alert_words.process_message(multialert_message); assert.equal( multialert_message.content, "another alertthreemessage alertone and then alerttwo
", ); alert_words.process_message(unsafe_word_message); assert.equal( unsafe_word_message.content, "gotta al*rt.*s all
", ); alert_words.process_message(alert_in_url_message); assert.equal(alert_in_url_message.content, "http://www.google.com/alertone/me
"); alert_words.process_message(question_word_message); assert.equal( question_word_message.content, "still alertone? me
", ); alert_words.process_message(alert_domain_message); assert.equal( alert_domain_message.content, 'now with link www.alerttwo.us/foo/bar
', ); alert_words.process_message(message_with_emoji); assert.equal( message_with_emoji.content, 'I
emoji!