mirror of https://github.com/zulip/zulip.git
node_tests: Pass correct arguments to needs_subscribe_warning.
We were not passing any arguments to needs_subscribe_warning when testing the function itself. This commit changes the code to pass the user-id and stream-id to needs_subscribe_warning. We also remove the stubs for get_by_user_id and is_user_subscribed and do these tests by calling the original functions, because passing the arguments (user-id and stream-id) only makes sense if we use original functions for them rather than stubs.
This commit is contained in:
parent
797fb00791
commit
44d67e40cf
|
@ -1065,33 +1065,38 @@ run_test('trigger_submit_compose_form', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test('needs_subscribe_warning', () => {
|
run_test('needs_subscribe_warning', () => {
|
||||||
people.get_by_user_id = function () {
|
const invalid_user_id = 999;
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
assert.equal(compose.needs_subscribe_warning(), false);
|
const test_bot = {
|
||||||
|
full_name: 'Test Bot',
|
||||||
people.get_by_user_id = function () {
|
email: 'test-bot@example.com',
|
||||||
return {
|
user_id: 135,
|
||||||
is_bot: true,
|
is_bot: true,
|
||||||
};
|
};
|
||||||
};
|
people.add_active_user(test_bot);
|
||||||
assert.equal(compose.needs_subscribe_warning(), false);
|
|
||||||
|
|
||||||
people.get_by_user_id = function () {
|
const sub = {
|
||||||
return {
|
stream_id: 110,
|
||||||
is_bot: false,
|
name: 'stream',
|
||||||
|
can_access_subscribers: true,
|
||||||
};
|
};
|
||||||
};
|
|
||||||
stream_data.is_user_subscribed = function () {
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
assert.equal(compose.needs_subscribe_warning(), false);
|
|
||||||
|
|
||||||
stream_data.is_user_subscribed = function () {
|
stream_data.add_sub(sub);
|
||||||
return false;
|
stream_data.set_subscribers(sub, [bob.user_id, me.user_id]);
|
||||||
};
|
|
||||||
assert.equal(compose.needs_subscribe_warning(), true);
|
blueslip.expect('error', 'Unknown user_id in get_by_user_id: 999');
|
||||||
|
// Test with an invalid user id.
|
||||||
|
assert.equal(compose.needs_subscribe_warning(invalid_user_id, sub.stream_id), false);
|
||||||
|
|
||||||
|
// Test with bot user.
|
||||||
|
assert.equal(compose.needs_subscribe_warning(test_bot.user_id, sub.stream_id), false);
|
||||||
|
|
||||||
|
// Test when user is subscribed to the stream.
|
||||||
|
assert.equal(compose.needs_subscribe_warning(bob.user_id, sub.stream_id), false);
|
||||||
|
|
||||||
|
stream_data.remove_subscriber(sub.stream_id, bob.user_id);
|
||||||
|
// Test when the user is not subscribed.
|
||||||
|
assert.equal(compose.needs_subscribe_warning(bob.user_id, sub.stream_id), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test('warn_if_mentioning_unsubscribed_user', () => {
|
run_test('warn_if_mentioning_unsubscribed_user', () => {
|
||||||
|
|
Loading…
Reference in New Issue