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:
sahil839 2020-07-14 02:19:18 +05:30 committed by Tim Abbott
parent 797fb00791
commit 44d67e40cf
1 changed files with 27 additions and 22 deletions

View File

@ -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;
const test_bot = {
full_name: 'Test Bot',
email: 'test-bot@example.com',
user_id: 135,
is_bot: true,
};
people.add_active_user(test_bot);
const sub = {
stream_id: 110,
name: 'stream',
can_access_subscribers: true,
}; };
assert.equal(compose.needs_subscribe_warning(), false); stream_data.add_sub(sub);
stream_data.set_subscribers(sub, [bob.user_id, me.user_id]);
people.get_by_user_id = function () { blueslip.expect('error', 'Unknown user_id in get_by_user_id: 999');
return { // Test with an invalid user id.
is_bot: true, assert.equal(compose.needs_subscribe_warning(invalid_user_id, sub.stream_id), false);
};
};
assert.equal(compose.needs_subscribe_warning(), false);
people.get_by_user_id = function () { // Test with bot user.
return { assert.equal(compose.needs_subscribe_warning(test_bot.user_id, sub.stream_id), false);
is_bot: false,
};
};
stream_data.is_user_subscribed = function () {
return true;
};
assert.equal(compose.needs_subscribe_warning(), false);
stream_data.is_user_subscribed = function () { // Test when user is subscribed to the stream.
return false; assert.equal(compose.needs_subscribe_warning(bob.user_id, sub.stream_id), false);
};
assert.equal(compose.needs_subscribe_warning(), true); 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', () => {