mirror of https://github.com/zulip/zulip.git
tests: Use override for current_user.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
8e49ca163b
commit
9cd2408e0d
|
@ -164,7 +164,7 @@ run_test("reload_defaults", () => {
|
|||
|
||||
test("get_status", ({override}) => {
|
||||
page_params.realm_users = [];
|
||||
current_user.user_id = 999;
|
||||
override(current_user, "user_id", 999);
|
||||
|
||||
assert.equal(presence.get_status(current_user.user_id), "active");
|
||||
assert.equal(presence.get_status(alice.user_id), "active");
|
||||
|
|
|
@ -166,7 +166,7 @@ test("user_circle, level", ({override}) => {
|
|||
assert.equal(buddy_data.level(fred.user_id), 3);
|
||||
});
|
||||
|
||||
test("title_data", () => {
|
||||
test("title_data", ({override}) => {
|
||||
page_params.presence_history_limit_days_for_web_app = 365;
|
||||
add_canned_users();
|
||||
|
||||
|
@ -213,7 +213,7 @@ test("title_data", () => {
|
|||
third_line: "translated: Active now",
|
||||
show_you: true,
|
||||
};
|
||||
current_user.user_id = me.user_id;
|
||||
override(current_user, "user_id", me.user_id);
|
||||
assert.deepEqual(buddy_data.get_title_data(me.user_id, is_group), expected_data);
|
||||
|
||||
expected_data = {
|
||||
|
|
|
@ -265,7 +265,7 @@ test_ui("send_message", ({override, override_rewire, mock_template}) => {
|
|||
stub_state = initialize_state_stub_dict();
|
||||
compose_state.topic("");
|
||||
compose_state.set_message_type("private");
|
||||
current_user.user_id = new_user.user_id;
|
||||
override(current_user, "user_id", new_user.user_id);
|
||||
override(compose_pm_pill, "get_emails", () => "alice@example.com");
|
||||
|
||||
const server_message_id = 127;
|
||||
|
@ -401,7 +401,7 @@ test_ui("enter_with_preview_open", ({override, override_rewire}) => {
|
|||
show_button_spinner_called = true;
|
||||
});
|
||||
|
||||
current_user.user_id = new_user.user_id;
|
||||
override(current_user, "user_id", new_user.user_id);
|
||||
|
||||
// Test sending a message with content.
|
||||
compose_state.set_message_type("stream");
|
||||
|
|
|
@ -305,14 +305,14 @@ test_ui("validate", ({mock_template}) => {
|
|||
assert.ok(missing_topic_error_rendered);
|
||||
});
|
||||
|
||||
test_ui("get_invalid_recipient_emails", ({override_rewire}) => {
|
||||
test_ui("get_invalid_recipient_emails", ({override, override_rewire}) => {
|
||||
const welcome_bot = {
|
||||
email: "welcome-bot@example.com",
|
||||
user_id: 124,
|
||||
full_name: "Welcome Bot",
|
||||
};
|
||||
|
||||
current_user.user_id = me.user_id;
|
||||
override(current_user, "user_id", me.user_id);
|
||||
|
||||
const params = {};
|
||||
params.realm_users = [];
|
||||
|
@ -325,8 +325,8 @@ test_ui("get_invalid_recipient_emails", ({override_rewire}) => {
|
|||
assert.deepEqual(compose_validate.get_invalid_recipient_emails(), []);
|
||||
});
|
||||
|
||||
test_ui("test_stream_wildcard_mention_allowed", ({override_rewire}) => {
|
||||
current_user.user_id = me.user_id;
|
||||
test_ui("test_stream_wildcard_mention_allowed", ({override, override_rewire}) => {
|
||||
override(current_user, "user_id", me.user_id);
|
||||
|
||||
// First, check for large streams (>15 subscribers) where the wildcard mention
|
||||
// policy matters.
|
||||
|
@ -334,40 +334,40 @@ test_ui("test_stream_wildcard_mention_allowed", ({override_rewire}) => {
|
|||
|
||||
realm.realm_wildcard_mention_policy =
|
||||
settings_config.wildcard_mention_policy_values.by_everyone.code;
|
||||
current_user.is_guest = true;
|
||||
current_user.is_admin = false;
|
||||
override(current_user, "is_guest", true);
|
||||
override(current_user, "is_admin", false);
|
||||
assert.ok(compose_validate.stream_wildcard_mention_allowed());
|
||||
|
||||
realm.realm_wildcard_mention_policy =
|
||||
settings_config.wildcard_mention_policy_values.nobody.code;
|
||||
current_user.is_admin = true;
|
||||
override(current_user, "is_admin", true);
|
||||
assert.ok(!compose_validate.stream_wildcard_mention_allowed());
|
||||
|
||||
realm.realm_wildcard_mention_policy =
|
||||
settings_config.wildcard_mention_policy_values.by_members.code;
|
||||
current_user.is_guest = true;
|
||||
current_user.is_admin = false;
|
||||
override(current_user, "is_guest", true);
|
||||
override(current_user, "is_admin", false);
|
||||
assert.ok(!compose_validate.stream_wildcard_mention_allowed());
|
||||
|
||||
current_user.is_guest = false;
|
||||
override(current_user, "is_guest", false);
|
||||
assert.ok(compose_validate.stream_wildcard_mention_allowed());
|
||||
|
||||
realm.realm_wildcard_mention_policy =
|
||||
settings_config.wildcard_mention_policy_values.by_moderators_only.code;
|
||||
current_user.is_moderator = false;
|
||||
override(current_user, "is_moderator", false);
|
||||
assert.ok(!compose_validate.stream_wildcard_mention_allowed());
|
||||
|
||||
current_user.is_moderator = true;
|
||||
override(current_user, "is_moderator", true);
|
||||
assert.ok(compose_validate.stream_wildcard_mention_allowed());
|
||||
|
||||
realm.realm_wildcard_mention_policy =
|
||||
settings_config.wildcard_mention_policy_values.by_admins_only.code;
|
||||
current_user.is_admin = false;
|
||||
override(current_user, "is_admin", false);
|
||||
assert.ok(!compose_validate.stream_wildcard_mention_allowed());
|
||||
|
||||
// TODO: Add a by_admins_only case when we implement stream-level administrators.
|
||||
|
||||
current_user.is_admin = true;
|
||||
override(current_user, "is_admin", true);
|
||||
assert.ok(compose_validate.stream_wildcard_mention_allowed());
|
||||
|
||||
realm.realm_wildcard_mention_policy =
|
||||
|
@ -377,7 +377,7 @@ test_ui("test_stream_wildcard_mention_allowed", ({override_rewire}) => {
|
|||
realm.realm_waiting_period_threshold = 10;
|
||||
|
||||
assert.ok(compose_validate.stream_wildcard_mention_allowed());
|
||||
current_user.is_admin = false;
|
||||
override(current_user, "is_admin", false);
|
||||
assert.ok(!compose_validate.stream_wildcard_mention_allowed());
|
||||
|
||||
// Now, check for small streams (<=15 subscribers) where the wildcard mention
|
||||
|
@ -385,18 +385,18 @@ test_ui("test_stream_wildcard_mention_allowed", ({override_rewire}) => {
|
|||
override_rewire(peer_data, "get_subscriber_count", () => 14);
|
||||
realm.realm_wildcard_mention_policy =
|
||||
settings_config.wildcard_mention_policy_values.by_admins_only.code;
|
||||
current_user.is_admin = false;
|
||||
current_user.is_guest = true;
|
||||
override(current_user, "is_admin", false);
|
||||
override(current_user, "is_guest", true);
|
||||
assert.ok(compose_validate.stream_wildcard_mention_allowed());
|
||||
});
|
||||
|
||||
test_ui("validate_stream_message", ({override_rewire, mock_template}) => {
|
||||
test_ui("validate_stream_message", ({override, override_rewire, mock_template}) => {
|
||||
// This test is in kind of continuation to test_validate but since it is
|
||||
// primarily used to get coverage over functions called from validate()
|
||||
// we are separating it up in different test. Though their relative position
|
||||
// of execution should not be changed.
|
||||
mock_banners();
|
||||
current_user.user_id = me.user_id;
|
||||
override(current_user, "user_id", me.user_id);
|
||||
realm.realm_mandatory_topics = false;
|
||||
|
||||
const special_sub = {
|
||||
|
@ -440,13 +440,13 @@ test_ui("validate_stream_message", ({override_rewire, mock_template}) => {
|
|||
assert.ok(wildcards_not_allowed_rendered);
|
||||
});
|
||||
|
||||
test_ui("test_validate_stream_message_post_policy_admin_only", ({mock_template}) => {
|
||||
test_ui("test_validate_stream_message_post_policy_admin_only", ({mock_template, override}) => {
|
||||
// This test is in continuation with test_validate but it has been separated out
|
||||
// for better readability. Their relative position of execution should not be changed.
|
||||
// Although the position with respect to test_validate_stream_message does not matter
|
||||
// as different stream is used for this test.
|
||||
mock_banners();
|
||||
current_user.is_admin = false;
|
||||
override(current_user, "is_admin", false);
|
||||
const sub_stream_102 = {
|
||||
stream_id: 102,
|
||||
name: "stream102",
|
||||
|
@ -476,8 +476,8 @@ test_ui("test_validate_stream_message_post_policy_admin_only", ({mock_template})
|
|||
// Reset error message.
|
||||
compose_state.set_stream_id(social_sub.stream_id);
|
||||
|
||||
current_user.is_admin = false;
|
||||
current_user.is_guest = true;
|
||||
override(current_user, "is_admin", false);
|
||||
override(current_user, "is_guest", true);
|
||||
|
||||
compose_state.topic("topic102");
|
||||
compose_state.set_stream_id(sub_stream_102.stream_id);
|
||||
|
@ -486,12 +486,12 @@ test_ui("test_validate_stream_message_post_policy_admin_only", ({mock_template})
|
|||
assert.ok(banner_rendered);
|
||||
});
|
||||
|
||||
test_ui("test_validate_stream_message_post_policy_moderators_only", ({mock_template}) => {
|
||||
test_ui("test_validate_stream_message_post_policy_moderators_only", ({mock_template, override}) => {
|
||||
mock_banners();
|
||||
|
||||
current_user.is_admin = false;
|
||||
current_user.is_moderator = false;
|
||||
current_user.is_guest = false;
|
||||
override(current_user, "is_admin", false);
|
||||
override(current_user, "is_moderator", false);
|
||||
override(current_user, "is_guest", false);
|
||||
|
||||
const sub = {
|
||||
stream_id: 104,
|
||||
|
@ -520,40 +520,43 @@ test_ui("test_validate_stream_message_post_policy_moderators_only", ({mock_templ
|
|||
// Reset error message.
|
||||
compose_state.set_stream_id(social_sub.stream_id);
|
||||
|
||||
current_user.is_guest = true;
|
||||
override(current_user, "is_guest", true);
|
||||
assert.ok(!compose_validate.validate());
|
||||
assert.ok(banner_rendered);
|
||||
});
|
||||
|
||||
test_ui("test_validate_stream_message_post_policy_full_members_only", ({mock_template}) => {
|
||||
mock_banners();
|
||||
current_user.is_admin = false;
|
||||
current_user.is_guest = true;
|
||||
const sub = {
|
||||
stream_id: 103,
|
||||
name: "stream103",
|
||||
subscribed: true,
|
||||
stream_post_policy: settings_config.stream_post_policy_values.non_new_members.code,
|
||||
};
|
||||
test_ui(
|
||||
"test_validate_stream_message_post_policy_full_members_only",
|
||||
({mock_template, override}) => {
|
||||
mock_banners();
|
||||
override(current_user, "is_admin", false);
|
||||
override(current_user, "is_guest", true);
|
||||
const sub = {
|
||||
stream_id: 103,
|
||||
name: "stream103",
|
||||
subscribed: true,
|
||||
stream_post_policy: settings_config.stream_post_policy_values.non_new_members.code,
|
||||
};
|
||||
|
||||
stream_data.add_sub(sub);
|
||||
compose_state.topic("topic103");
|
||||
compose_state.set_stream_id(sub.stream_id);
|
||||
let banner_rendered = false;
|
||||
mock_template("compose_banner/compose_banner.hbs", false, (data) => {
|
||||
assert.equal(data.classname, compose_banner.CLASSNAMES.no_post_permissions);
|
||||
assert.equal(
|
||||
data.banner_text,
|
||||
$t({
|
||||
defaultMessage: "You do not have permission to post in this channel.",
|
||||
}),
|
||||
);
|
||||
banner_rendered = true;
|
||||
return "<banner-stub>";
|
||||
});
|
||||
assert.ok(!compose_validate.validate());
|
||||
assert.ok(banner_rendered);
|
||||
});
|
||||
stream_data.add_sub(sub);
|
||||
compose_state.topic("topic103");
|
||||
compose_state.set_stream_id(sub.stream_id);
|
||||
let banner_rendered = false;
|
||||
mock_template("compose_banner/compose_banner.hbs", false, (data) => {
|
||||
assert.equal(data.classname, compose_banner.CLASSNAMES.no_post_permissions);
|
||||
assert.equal(
|
||||
data.banner_text,
|
||||
$t({
|
||||
defaultMessage: "You do not have permission to post in this channel.",
|
||||
}),
|
||||
);
|
||||
banner_rendered = true;
|
||||
return "<banner-stub>";
|
||||
});
|
||||
assert.ok(!compose_validate.validate());
|
||||
assert.ok(banner_rendered);
|
||||
},
|
||||
);
|
||||
|
||||
test_ui("test_check_overflow_text", ({mock_template}) => {
|
||||
realm.max_message_length = 10000;
|
||||
|
|
|
@ -168,7 +168,7 @@ test("videos", ({override}) => {
|
|||
});
|
||||
|
||||
realm.realm_video_chat_provider = realm_available_video_chat_providers.zoom.id;
|
||||
current_user.has_zoom_token = false;
|
||||
override(current_user, "has_zoom_token", false);
|
||||
|
||||
window.open = (url) => {
|
||||
assert.ok(url.endsWith("/calls/zoom/register"));
|
||||
|
|
|
@ -1969,10 +1969,10 @@ function possibly_silent_list(list, is_silent) {
|
|||
}));
|
||||
}
|
||||
|
||||
test("filter_and_sort_mentions (normal)", () => {
|
||||
test("filter_and_sort_mentions (normal)", ({override}) => {
|
||||
compose_state.set_message_type("stream");
|
||||
const is_silent = false;
|
||||
current_user.user_id = 101;
|
||||
override(current_user, "user_id", 101);
|
||||
let suggestions = ct.filter_and_sort_mentions(is_silent, "al");
|
||||
|
||||
const mention_all = broadcast_item(ct.broadcast_mentions()[0]);
|
||||
|
@ -1983,7 +1983,7 @@ test("filter_and_sort_mentions (normal)", () => {
|
|||
|
||||
// call_center group is shown in typeahead even when user is member of
|
||||
// one of the subgroups of can_mention_group.
|
||||
current_user.user_id = 104;
|
||||
override(current_user, "user_id", 104);
|
||||
suggestions = ct.filter_and_sort_mentions(is_silent, "al");
|
||||
assert.deepEqual(
|
||||
suggestions,
|
||||
|
@ -1993,7 +1993,7 @@ test("filter_and_sort_mentions (normal)", () => {
|
|||
// call_center group is not shown in typeahead when user is neither
|
||||
// a direct member of can_mention_group nor a member of any of its
|
||||
// recursive subgroups.
|
||||
current_user.user_id = 102;
|
||||
override(current_user, "user_id", 102);
|
||||
suggestions = ct.filter_and_sort_mentions(is_silent, "al");
|
||||
assert.deepEqual(
|
||||
suggestions,
|
||||
|
@ -2001,7 +2001,7 @@ test("filter_and_sort_mentions (normal)", () => {
|
|||
);
|
||||
});
|
||||
|
||||
test("filter_and_sort_mentions (silent)", () => {
|
||||
test("filter_and_sort_mentions (silent)", ({override}) => {
|
||||
const is_silent = true;
|
||||
|
||||
let suggestions = ct.filter_and_sort_mentions(is_silent, "al");
|
||||
|
@ -2014,7 +2014,7 @@ test("filter_and_sort_mentions (silent)", () => {
|
|||
// call_center group is shown in typeahead irrespective of whether
|
||||
// user is member of can_mention_group or its subgroups for a
|
||||
// silent mention.
|
||||
current_user.user_id = 102;
|
||||
override(current_user, "user_id", 102);
|
||||
suggestions = ct.filter_and_sort_mentions(is_silent, "al");
|
||||
assert.deepEqual(
|
||||
suggestions,
|
||||
|
@ -2022,7 +2022,7 @@ test("filter_and_sort_mentions (silent)", () => {
|
|||
);
|
||||
});
|
||||
|
||||
test("typeahead_results", () => {
|
||||
test("typeahead_results", ({override}) => {
|
||||
const stream_list = [
|
||||
denmark_stream,
|
||||
sweden_stream,
|
||||
|
@ -2136,7 +2136,7 @@ test("typeahead_results", () => {
|
|||
// Earlier user group and stream mentions were autocompleted by their
|
||||
// description too. This is now removed as it often led to unexpected
|
||||
// behaviour, and did not have any great discoverability advantage.
|
||||
current_user.user_id = 101;
|
||||
override(current_user, "user_id", 101);
|
||||
// Autocomplete user group mentions by group name.
|
||||
assert_mentions_matches("hamletchar", [not_silent(hamletcharacters)]);
|
||||
|
||||
|
|
|
@ -127,7 +127,6 @@ message_lists.all_rendered_message_lists = () => [cached_message_list, message_l
|
|||
|
||||
// page_params is highly coupled to dispatching now
|
||||
page_params.test_suite = false;
|
||||
current_user.is_admin = true;
|
||||
realm.realm_description = "already set description";
|
||||
|
||||
// For data-oriented modules, just use them, don't stub them.
|
||||
|
@ -453,7 +452,7 @@ run_test("scheduled_messages", ({override}) => {
|
|||
});
|
||||
|
||||
run_test("realm settings", ({override}) => {
|
||||
current_user.is_admin = true;
|
||||
override(current_user, "is_admin", true);
|
||||
realm.realm_date_created = new Date("2023-01-01Z");
|
||||
|
||||
override(settings_org, "check_disable_direct_message_initiator_group_dropdown", noop);
|
||||
|
@ -834,7 +833,7 @@ run_test("submessage", ({override}) => {
|
|||
|
||||
run_test("typing", ({override}) => {
|
||||
// Simulate that we are not typing.
|
||||
current_user.user_id = typing_person1.user_id + 1;
|
||||
override(current_user, "user_id", typing_person1.user_id + 1);
|
||||
|
||||
let event = event_fixtures.typing__start;
|
||||
{
|
||||
|
@ -857,10 +856,10 @@ run_test("typing", ({override}) => {
|
|||
}
|
||||
|
||||
// Get line coverage--we ignore our own typing events.
|
||||
current_user.user_id = typing_person1.user_id;
|
||||
override(current_user, "user_id", typing_person1.user_id);
|
||||
event = event_fixtures.typing__start;
|
||||
dispatch(event);
|
||||
current_user.user_id = undefined; // above change shouldn't effect stream_typing tests below
|
||||
override(current_user, "user_id", undefined); // above change shouldn't effect stream_typing tests below
|
||||
});
|
||||
|
||||
run_test("stream_typing", ({override}) => {
|
||||
|
|
|
@ -188,8 +188,8 @@ run_test("process_from_server for messages to add to narrow", ({override}) => {
|
|||
]);
|
||||
});
|
||||
|
||||
run_test("build_display_recipient", () => {
|
||||
current_user.user_id = 123;
|
||||
run_test("build_display_recipient", ({override}) => {
|
||||
override(current_user, "user_id", 123);
|
||||
|
||||
const params = {};
|
||||
params.realm_users = [
|
||||
|
@ -321,7 +321,7 @@ run_test("insert_local_message streams", ({override}) => {
|
|||
run_test("insert_local_message direct message", ({override}) => {
|
||||
const local_id_float = 102.01;
|
||||
|
||||
current_user.user_id = 123;
|
||||
override(current_user, "user_id", 123);
|
||||
|
||||
const params = {};
|
||||
params.realm_users = [
|
||||
|
|
|
@ -2567,8 +2567,8 @@ run_test("equals", () => {
|
|||
);
|
||||
});
|
||||
|
||||
run_test("adjusted_terms_if_moved", () => {
|
||||
current_user.email = me.email;
|
||||
run_test("adjusted_terms_if_moved", ({override}) => {
|
||||
override(current_user, "email", me.email);
|
||||
// should return null for non-stream messages containing no
|
||||
// `with` operator
|
||||
let raw_terms = [{operator: "channel", operand: foo_stream_id.toString()}];
|
||||
|
|
|
@ -92,7 +92,7 @@ run_test("is_topic_editable", ({override}) => {
|
|||
};
|
||||
realm.realm_allow_message_editing = true;
|
||||
override(settings_data, "user_can_move_messages_to_another_topic", () => true);
|
||||
current_user.is_admin = true;
|
||||
override(current_user, "is_admin", true);
|
||||
|
||||
assert.equal(message_edit.is_topic_editable(message), false);
|
||||
|
||||
|
@ -109,7 +109,7 @@ run_test("is_topic_editable", ({override}) => {
|
|||
override(settings_data, "user_can_move_messages_to_another_topic", () => false);
|
||||
assert.equal(message_edit.is_topic_editable(message), false);
|
||||
|
||||
current_user.is_admin = false;
|
||||
override(current_user, "is_admin", false);
|
||||
assert.equal(message_edit.is_topic_editable(message), false);
|
||||
|
||||
message.topic = "translated: (no topic)";
|
||||
|
@ -128,7 +128,7 @@ run_test("is_topic_editable", ({override}) => {
|
|||
message.timestamp = current_timestamp - 600000;
|
||||
assert.equal(message_edit.is_topic_editable(message), false);
|
||||
|
||||
current_user.is_moderator = true;
|
||||
override(current_user, "is_moderator", true);
|
||||
assert.equal(message_edit.is_topic_editable(message), true);
|
||||
|
||||
realm.realm_allow_message_editing = false;
|
||||
|
@ -146,7 +146,7 @@ run_test("is_stream_editable", ({override}) => {
|
|||
};
|
||||
realm.realm_allow_message_editing = true;
|
||||
override(settings_data, "user_can_move_messages_between_streams", () => true);
|
||||
current_user.is_admin = true;
|
||||
override(current_user, "is_admin", true);
|
||||
|
||||
assert.equal(message_edit.is_stream_editable(message), false);
|
||||
|
||||
|
@ -163,7 +163,7 @@ run_test("is_stream_editable", ({override}) => {
|
|||
override(settings_data, "user_can_move_messages_between_streams", () => false);
|
||||
assert.equal(message_edit.is_stream_editable(message), false);
|
||||
|
||||
current_user.is_admin = false;
|
||||
override(current_user, "is_admin", false);
|
||||
assert.equal(message_edit.is_stream_editable(message), false);
|
||||
|
||||
realm.realm_move_messages_between_streams_limit_seconds = 259200;
|
||||
|
@ -175,12 +175,12 @@ run_test("is_stream_editable", ({override}) => {
|
|||
message.timestamp = current_timestamp - 600000;
|
||||
assert.equal(message_edit.is_stream_editable(message), false);
|
||||
|
||||
current_user.is_moderator = true;
|
||||
override(current_user, "is_moderator", true);
|
||||
assert.equal(message_edit.is_stream_editable(message), true);
|
||||
});
|
||||
|
||||
run_test("get_deletability", ({override}) => {
|
||||
current_user.is_admin = true;
|
||||
override(current_user, "is_admin", true);
|
||||
override(settings_data, "user_can_delete_any_message", () => true);
|
||||
override(settings_data, "user_can_delete_own_message", () => false);
|
||||
realm.realm_message_content_delete_limit_seconds = null;
|
||||
|
|
|
@ -230,7 +230,7 @@ run_test("change_message_id", () => {
|
|||
assert.equal(list.change_message_id(13, 15), undefined);
|
||||
});
|
||||
|
||||
run_test("last_sent_by_me", () => {
|
||||
run_test("last_sent_by_me", ({override}) => {
|
||||
const list = new MessageList({
|
||||
data: new MessageListData({
|
||||
excludes_muted_topics: false,
|
||||
|
@ -253,7 +253,7 @@ run_test("last_sent_by_me", () => {
|
|||
];
|
||||
|
||||
list.append(items);
|
||||
current_user.user_id = 3;
|
||||
override(current_user, "user_id", 3);
|
||||
// Look for the last message where user_id == 3 (our ID)
|
||||
assert.equal(list.get_last_message_sent_by_me().id, 2);
|
||||
});
|
||||
|
|
|
@ -5,7 +5,7 @@ const assert = require("node:assert/strict");
|
|||
const {mock_esm, set_global, zrequire} = require("./lib/namespace");
|
||||
const {run_test, noop} = require("./lib/test");
|
||||
const blueslip = require("./lib/zblueslip");
|
||||
const {current_user, realm} = require("./lib/zpage_params");
|
||||
const {realm} = require("./lib/zpage_params");
|
||||
|
||||
mock_esm("../src/settings_data", {
|
||||
user_can_access_all_other_users: () => true,
|
||||
|
@ -22,7 +22,6 @@ mock_esm("../src/recent_senders", {
|
|||
|
||||
set_global("document", "document-stub");
|
||||
realm.realm_allow_message_editing = true;
|
||||
current_user.is_admin = true;
|
||||
|
||||
const util = zrequire("util");
|
||||
const people = zrequire("people");
|
||||
|
|
|
@ -68,16 +68,16 @@ test("profile_incomplete_alert", ({override}) => {
|
|||
override(timerender, "should_display_profile_incomplete_alert", () => true);
|
||||
|
||||
// Show alert.
|
||||
current_user.is_admin = true;
|
||||
override(current_user, "is_admin", true);
|
||||
realm.realm_description = "Organization imported from Slack!";
|
||||
assert.equal(navbar_alerts.check_profile_incomplete(), true);
|
||||
|
||||
// Avoid showing if the user is not admin.
|
||||
current_user.is_admin = false;
|
||||
override(current_user, "is_admin", false);
|
||||
assert.equal(navbar_alerts.check_profile_incomplete(), false);
|
||||
|
||||
// Avoid showing if the realm description is already updated.
|
||||
current_user.is_admin = true;
|
||||
override(current_user, "is_admin", true);
|
||||
assert.equal(navbar_alerts.check_profile_incomplete(), true);
|
||||
realm.realm_description = "Organization description already set!";
|
||||
assert.equal(navbar_alerts.check_profile_incomplete(), false);
|
||||
|
|
|
@ -57,7 +57,7 @@ user_topics.update_user_topics(
|
|||
|
||||
function test(label, f) {
|
||||
run_test(label, (helpers) => {
|
||||
current_user.is_admin = false;
|
||||
helpers.override(current_user, "is_admin", false);
|
||||
page_params.realm_users = [];
|
||||
helpers.override(user_settings, "enable_followed_topic_desktop_notifications", true);
|
||||
helpers.override(user_settings, "enable_followed_topic_audible_notifications", true);
|
||||
|
|
|
@ -11,15 +11,13 @@ const assert = require("node:assert/strict");
|
|||
const {zrequire} = require("./lib/namespace");
|
||||
const {run_test} = require("./lib/test");
|
||||
const blueslip = require("./lib/zblueslip");
|
||||
const {current_user, page_params} = require("./lib/zpage_params");
|
||||
const {page_params} = require("./lib/zpage_params");
|
||||
|
||||
const peer_data = zrequire("peer_data");
|
||||
const people = zrequire("people");
|
||||
const stream_data = zrequire("stream_data");
|
||||
|
||||
current_user.is_admin = false;
|
||||
page_params.realm_users = [];
|
||||
current_user.is_guest = false;
|
||||
|
||||
const me = {
|
||||
email: "me@zulip.com",
|
||||
|
|
|
@ -707,14 +707,14 @@ test_people("set_custom_profile_field_data", () => {
|
|||
assert.equal(person.profile_data[field.id].rendered_value, "<p>Field value</p>");
|
||||
});
|
||||
|
||||
test_people("is_current_user_only_owner", () => {
|
||||
test_people("is_current_user_only_owner", ({override}) => {
|
||||
const person = people.get_by_email(me.email);
|
||||
person.is_owner = false;
|
||||
current_user.is_owner = false;
|
||||
override(current_user, "is_owner", false);
|
||||
assert.ok(!people.is_current_user_only_owner());
|
||||
|
||||
person.is_owner = true;
|
||||
current_user.is_owner = true;
|
||||
override(current_user, "is_owner", true);
|
||||
assert.ok(people.is_current_user_only_owner());
|
||||
|
||||
people.add_active_user(realm_owner);
|
||||
|
@ -1262,13 +1262,13 @@ test_people("initialize", () => {
|
|||
assert.equal(page_params.realm_non_active_users, undefined);
|
||||
});
|
||||
|
||||
test_people("predicate_for_user_settings_filters", () => {
|
||||
test_people("predicate_for_user_settings_filters", ({override}) => {
|
||||
/*
|
||||
This function calls matches_user_settings_search,
|
||||
so that is where we do more thorough testing.
|
||||
This test is just a sanity check for now.
|
||||
*/
|
||||
current_user.is_admin = false;
|
||||
override(current_user, "is_admin", false);
|
||||
|
||||
const fred_smith = {full_name: "Fred Smith", role: 100};
|
||||
|
||||
|
@ -1307,15 +1307,15 @@ test_people("predicate_for_user_settings_filters", () => {
|
|||
);
|
||||
});
|
||||
|
||||
test_people("matches_user_settings_search", () => {
|
||||
test_people("matches_user_settings_search", ({override}) => {
|
||||
const match = people.matches_user_settings_search;
|
||||
|
||||
current_user.is_admin = false;
|
||||
override(current_user, "is_admin", false);
|
||||
|
||||
assert.equal(match({email: "fred@example.com"}, "fred"), false);
|
||||
assert.equal(match({full_name: "Fred Smith"}, "fr"), true);
|
||||
|
||||
current_user.is_admin = true;
|
||||
override(current_user, "is_admin", true);
|
||||
|
||||
assert.equal(match({delivery_email: "fred@example.com"}, "fr"), true);
|
||||
assert.equal(
|
||||
|
|
|
@ -132,8 +132,8 @@ test("muted_users", () => {
|
|||
assert.deepEqual(pmc.recent.get_strings(), ["3", "1,2,3", "15"]);
|
||||
});
|
||||
|
||||
test("has_conversation", () => {
|
||||
current_user.user_id = me.user_id;
|
||||
test("has_conversation", ({override}) => {
|
||||
override(current_user, "user_id", me.user_id);
|
||||
pmc.recent.initialize(params);
|
||||
|
||||
// Tests if `has_conversation` returns `true` when there are previous
|
||||
|
|
|
@ -156,12 +156,12 @@ function test(label, f) {
|
|||
}
|
||||
|
||||
// Test functions
|
||||
test("my_message_all_actions", () => {
|
||||
test("my_message_all_actions", ({override}) => {
|
||||
// Set page parameters.
|
||||
set_page_params_no_edit_restrictions();
|
||||
realm.realm_can_delete_any_message_group = everyone.id;
|
||||
realm.realm_can_delete_own_message_group = everyone.id;
|
||||
current_user.user_id = me.user_id;
|
||||
override(current_user, "user_id", me.user_id);
|
||||
// Get message with maximum permissions available
|
||||
// Initialize message list
|
||||
const list = init_message_list();
|
||||
|
|
|
@ -112,7 +112,7 @@ people.add_active_user(alexus);
|
|||
|
||||
function test(label, f) {
|
||||
run_test(label, (helpers) => {
|
||||
current_user.user_id = alice_user_id;
|
||||
helpers.override(current_user, "user_id", alice_user_id);
|
||||
f(helpers);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -56,8 +56,8 @@ function new_stream_id() {
|
|||
return _stream_id;
|
||||
}
|
||||
|
||||
function init() {
|
||||
current_user.is_admin = true;
|
||||
function init({override}) {
|
||||
override(current_user, "is_admin", true);
|
||||
|
||||
people.init();
|
||||
people.add_active_user(bob);
|
||||
|
@ -79,7 +79,7 @@ function get_suggestions(query, pill_query = "") {
|
|||
|
||||
function test(label, f) {
|
||||
run_test(label, (helpers) => {
|
||||
init();
|
||||
init(helpers);
|
||||
f(helpers);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -91,11 +91,11 @@ test("generate_botserverrc_content", () => {
|
|||
assert.equal(content, expected);
|
||||
});
|
||||
|
||||
test("can_create_new_bots", () => {
|
||||
current_user.is_admin = true;
|
||||
test("can_create_new_bots", ({override}) => {
|
||||
override(current_user, "is_admin", true);
|
||||
assert.ok(settings_bots.can_create_new_bots());
|
||||
|
||||
current_user.is_admin = false;
|
||||
override(current_user, "is_admin", false);
|
||||
realm.realm_bot_creation_policy = 1;
|
||||
assert.ok(settings_bots.can_create_new_bots());
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
const assert = require("node:assert/strict");
|
||||
|
||||
const {mock_esm, zrequire} = require("./lib/namespace");
|
||||
const {mock_esm, with_overrides, zrequire} = require("./lib/namespace");
|
||||
const {run_test} = require("./lib/test");
|
||||
const {current_user, page_params, realm} = require("./lib/zpage_params");
|
||||
|
||||
|
@ -30,13 +30,13 @@ const isaac = {
|
|||
|
||||
const group_permission_settings = mock_esm("../src/group_permission_settings", {});
|
||||
|
||||
run_test("user_can_change_email", () => {
|
||||
run_test("user_can_change_email", ({override}) => {
|
||||
const can_change_email = settings_data.user_can_change_email;
|
||||
|
||||
current_user.is_admin = true;
|
||||
override(current_user, "is_admin", true);
|
||||
assert.equal(can_change_email(), true);
|
||||
|
||||
current_user.is_admin = false;
|
||||
override(current_user, "is_admin", false);
|
||||
realm.realm_email_changes_disabled = true;
|
||||
assert.equal(can_change_email(), false);
|
||||
|
||||
|
@ -44,13 +44,13 @@ run_test("user_can_change_email", () => {
|
|||
assert.equal(can_change_email(), true);
|
||||
});
|
||||
|
||||
run_test("user_can_change_name", () => {
|
||||
run_test("user_can_change_name", ({override}) => {
|
||||
const can_change_name = settings_data.user_can_change_name;
|
||||
|
||||
current_user.is_admin = true;
|
||||
override(current_user, "is_admin", true);
|
||||
assert.equal(can_change_name(), true);
|
||||
|
||||
current_user.is_admin = false;
|
||||
override(current_user, "is_admin", false);
|
||||
realm.realm_name_changes_disabled = true;
|
||||
realm.server_name_changes_disabled = false;
|
||||
assert.equal(can_change_name(), false);
|
||||
|
@ -64,13 +64,13 @@ run_test("user_can_change_name", () => {
|
|||
assert.equal(can_change_name(), false);
|
||||
});
|
||||
|
||||
run_test("user_can_change_avatar", () => {
|
||||
run_test("user_can_change_avatar", ({override}) => {
|
||||
const can_change_avatar = settings_data.user_can_change_avatar;
|
||||
|
||||
current_user.is_admin = true;
|
||||
override(current_user, "is_admin", true);
|
||||
assert.equal(can_change_avatar(), true);
|
||||
|
||||
current_user.is_admin = false;
|
||||
override(current_user, "is_admin", false);
|
||||
realm.realm_avatar_changes_disabled = true;
|
||||
realm.server_avatar_changes_disabled = false;
|
||||
assert.equal(can_change_avatar(), false);
|
||||
|
@ -84,47 +84,47 @@ run_test("user_can_change_avatar", () => {
|
|||
assert.equal(can_change_avatar(), false);
|
||||
});
|
||||
|
||||
run_test("user_can_change_logo", () => {
|
||||
run_test("user_can_change_logo", ({override}) => {
|
||||
const can_change_logo = settings_data.user_can_change_logo;
|
||||
|
||||
current_user.is_admin = true;
|
||||
override(current_user, "is_admin", true);
|
||||
realm.zulip_plan_is_not_limited = true;
|
||||
assert.equal(can_change_logo(), true);
|
||||
|
||||
current_user.is_admin = false;
|
||||
override(current_user, "is_admin", false);
|
||||
realm.zulip_plan_is_not_limited = false;
|
||||
assert.equal(can_change_logo(), false);
|
||||
|
||||
current_user.is_admin = true;
|
||||
override(current_user, "is_admin", true);
|
||||
realm.zulip_plan_is_not_limited = false;
|
||||
assert.equal(can_change_logo(), false);
|
||||
|
||||
current_user.is_admin = false;
|
||||
override(current_user, "is_admin", false);
|
||||
realm.zulip_plan_is_not_limited = true;
|
||||
assert.equal(can_change_logo(), false);
|
||||
});
|
||||
|
||||
function test_policy(label, policy, validation_func) {
|
||||
run_test(label, () => {
|
||||
current_user.is_admin = true;
|
||||
run_test(label, ({override}) => {
|
||||
override(current_user, "is_admin", true);
|
||||
realm[policy] = settings_config.common_policy_values.by_admins_only.code;
|
||||
assert.equal(validation_func(), true);
|
||||
|
||||
current_user.is_admin = false;
|
||||
override(current_user, "is_admin", false);
|
||||
assert.equal(validation_func(), false);
|
||||
|
||||
current_user.is_moderator = true;
|
||||
override(current_user, "is_moderator", true);
|
||||
realm[policy] = settings_config.common_policy_values.by_moderators_only.code;
|
||||
assert.equal(validation_func(), true);
|
||||
|
||||
current_user.is_moderator = false;
|
||||
override(current_user, "is_moderator", false);
|
||||
assert.equal(validation_func(), false);
|
||||
|
||||
current_user.is_guest = true;
|
||||
override(current_user, "is_guest", true);
|
||||
realm[policy] = settings_config.common_policy_values.by_members.code;
|
||||
assert.equal(validation_func(), false);
|
||||
|
||||
current_user.is_guest = false;
|
||||
override(current_user, "is_guest", false);
|
||||
assert.equal(validation_func(), true);
|
||||
|
||||
page_params.is_spectator = true;
|
||||
|
@ -135,7 +135,7 @@ function test_policy(label, policy, validation_func) {
|
|||
assert.equal(validation_func(), true);
|
||||
|
||||
realm[policy] = settings_config.common_policy_values.by_full_members.code;
|
||||
current_user.user_id = 30;
|
||||
override(current_user, "user_id", 30);
|
||||
isaac.date_joined = new Date(Date.now());
|
||||
settings_data.initialize(isaac.date_joined);
|
||||
realm.realm_waiting_period_threshold = 10;
|
||||
|
@ -169,33 +169,33 @@ test_policy(
|
|||
);
|
||||
|
||||
function test_message_policy(label, policy, validation_func) {
|
||||
run_test(label, () => {
|
||||
current_user.is_admin = true;
|
||||
run_test(label, ({override}) => {
|
||||
override(current_user, "is_admin", true);
|
||||
realm[policy] = settings_config.common_message_policy_values.by_admins_only.code;
|
||||
assert.equal(validation_func(), true);
|
||||
|
||||
current_user.is_admin = false;
|
||||
current_user.is_moderator = true;
|
||||
override(current_user, "is_admin", false);
|
||||
override(current_user, "is_moderator", true);
|
||||
assert.equal(validation_func(), false);
|
||||
|
||||
realm[policy] = settings_config.common_message_policy_values.by_moderators_only.code;
|
||||
assert.equal(validation_func(), true);
|
||||
|
||||
current_user.is_moderator = false;
|
||||
override(current_user, "is_moderator", false);
|
||||
assert.equal(validation_func(), false);
|
||||
|
||||
current_user.is_guest = true;
|
||||
override(current_user, "is_guest", true);
|
||||
realm[policy] = settings_config.common_message_policy_values.by_everyone.code;
|
||||
assert.equal(validation_func(), true);
|
||||
|
||||
realm[policy] = settings_config.common_message_policy_values.by_members.code;
|
||||
assert.equal(validation_func(), false);
|
||||
|
||||
current_user.is_guest = false;
|
||||
override(current_user, "is_guest", false);
|
||||
assert.equal(validation_func(), true);
|
||||
|
||||
realm[policy] = settings_config.common_message_policy_values.by_full_members.code;
|
||||
current_user.user_id = 30;
|
||||
override(current_user, "user_id", 30);
|
||||
isaac.date_joined = new Date(Date.now());
|
||||
realm.realm_waiting_period_threshold = 10;
|
||||
settings_data.initialize(isaac.date_joined);
|
||||
|
@ -213,16 +213,16 @@ test_message_policy(
|
|||
settings_data.user_can_move_messages_to_another_topic,
|
||||
);
|
||||
|
||||
run_test("user_can_move_messages_to_another_topic_nobody_case", () => {
|
||||
current_user.is_admin = true;
|
||||
current_user.is_guest = false;
|
||||
run_test("user_can_move_messages_to_another_topic_nobody_case", ({override}) => {
|
||||
override(current_user, "is_admin", true);
|
||||
override(current_user, "is_guest", false);
|
||||
realm.realm_edit_topic_policy = settings_config.edit_topic_policy_values.nobody.code;
|
||||
assert.equal(settings_data.user_can_move_messages_to_another_topic(), false);
|
||||
});
|
||||
|
||||
run_test("user_can_move_messages_between_streams_nobody_case", () => {
|
||||
current_user.is_admin = true;
|
||||
current_user.is_guest = false;
|
||||
run_test("user_can_move_messages_between_streams_nobody_case", ({override}) => {
|
||||
override(current_user, "is_admin", true);
|
||||
override(current_user, "is_guest", false);
|
||||
realm.realm_move_messages_between_streams_policy =
|
||||
settings_config.move_messages_between_streams_policy_values.nobody.code;
|
||||
assert.equal(settings_data.user_can_move_messages_between_streams(), false);
|
||||
|
@ -260,80 +260,82 @@ run_test("using_dark_theme", ({override}) => {
|
|||
assert.equal(settings_data.using_dark_theme(), false);
|
||||
});
|
||||
|
||||
run_test("user_can_invite_others_to_realm_nobody_case", () => {
|
||||
current_user.is_admin = true;
|
||||
current_user.is_guest = false;
|
||||
run_test("user_can_invite_others_to_realm_nobody_case", ({override}) => {
|
||||
override(current_user, "is_admin", true);
|
||||
override(current_user, "is_guest", false);
|
||||
realm.realm_invite_to_realm_policy =
|
||||
settings_config.email_invite_to_realm_policy_values.nobody.code;
|
||||
assert.equal(settings_data.user_can_invite_users_by_email(), false);
|
||||
});
|
||||
|
||||
run_test("user_email_not_configured", () => {
|
||||
run_test("user_email_not_configured", ({override}) => {
|
||||
const user_email_not_configured = settings_data.user_email_not_configured;
|
||||
|
||||
current_user.is_owner = false;
|
||||
override(current_user, "is_owner", false);
|
||||
assert.equal(user_email_not_configured(), false);
|
||||
|
||||
current_user.is_owner = true;
|
||||
current_user.delivery_email = "";
|
||||
override(current_user, "is_owner", true);
|
||||
override(current_user, "delivery_email", "");
|
||||
assert.equal(user_email_not_configured(), true);
|
||||
|
||||
current_user.delivery_email = "name@example.com";
|
||||
override(current_user, "delivery_email", "name@example.com");
|
||||
assert.equal(user_email_not_configured(), false);
|
||||
});
|
||||
|
||||
function test_realm_group_settings(setting_name, validation_func) {
|
||||
const admin_user_id = 1;
|
||||
const moderator_user_id = 2;
|
||||
const member_user_id = 3;
|
||||
with_overrides(({override}) => {
|
||||
const admin_user_id = 1;
|
||||
const moderator_user_id = 2;
|
||||
const member_user_id = 3;
|
||||
|
||||
const admins = {
|
||||
name: "Admins",
|
||||
id: 1,
|
||||
members: new Set([admin_user_id]),
|
||||
is_system_group: true,
|
||||
direct_subgroup_ids: new Set([]),
|
||||
};
|
||||
const moderators = {
|
||||
name: "Moderators",
|
||||
id: 2,
|
||||
members: new Set([moderator_user_id]),
|
||||
is_system_group: true,
|
||||
direct_subgroup_ids: new Set([1]),
|
||||
};
|
||||
const admins = {
|
||||
name: "Admins",
|
||||
id: 1,
|
||||
members: new Set([admin_user_id]),
|
||||
is_system_group: true,
|
||||
direct_subgroup_ids: new Set([]),
|
||||
};
|
||||
const moderators = {
|
||||
name: "Moderators",
|
||||
id: 2,
|
||||
members: new Set([moderator_user_id]),
|
||||
is_system_group: true,
|
||||
direct_subgroup_ids: new Set([1]),
|
||||
};
|
||||
|
||||
group_permission_settings.get_group_permission_setting_config = () => ({
|
||||
allow_everyone_group: false,
|
||||
group_permission_settings.get_group_permission_setting_config = () => ({
|
||||
allow_everyone_group: false,
|
||||
});
|
||||
|
||||
user_groups.initialize({realm_user_groups: [admins, moderators]});
|
||||
page_params.is_spectator = true;
|
||||
assert.equal(validation_func(), false);
|
||||
|
||||
page_params.is_spectator = false;
|
||||
override(current_user, "is_guest", false);
|
||||
realm[setting_name] = 1;
|
||||
override(current_user, "user_id", admin_user_id);
|
||||
assert.equal(validation_func(), true);
|
||||
|
||||
override(current_user, "user_id", moderator_user_id);
|
||||
assert.equal(validation_func(), false);
|
||||
|
||||
realm[setting_name] = 2;
|
||||
override(current_user, "user_id", moderator_user_id);
|
||||
assert.equal(validation_func(), true);
|
||||
|
||||
override(current_user, "user_id", member_user_id);
|
||||
assert.equal(validation_func(), false);
|
||||
|
||||
override(current_user, "user_id", moderator_user_id);
|
||||
override(current_user, "is_guest", true);
|
||||
assert.equal(validation_func(), false);
|
||||
|
||||
group_permission_settings.get_group_permission_setting_config = () => ({
|
||||
allow_everyone_group: true,
|
||||
});
|
||||
assert.equal(validation_func(), true);
|
||||
});
|
||||
|
||||
user_groups.initialize({realm_user_groups: [admins, moderators]});
|
||||
page_params.is_spectator = true;
|
||||
assert.equal(validation_func(), false);
|
||||
|
||||
page_params.is_spectator = false;
|
||||
current_user.is_guest = false;
|
||||
realm[setting_name] = 1;
|
||||
current_user.user_id = admin_user_id;
|
||||
assert.equal(validation_func(), true);
|
||||
|
||||
current_user.user_id = moderator_user_id;
|
||||
assert.equal(validation_func(), false);
|
||||
|
||||
realm[setting_name] = 2;
|
||||
current_user.user_id = moderator_user_id;
|
||||
assert.equal(validation_func(), true);
|
||||
|
||||
current_user.user_id = member_user_id;
|
||||
assert.equal(validation_func(), false);
|
||||
|
||||
current_user.user_id = moderator_user_id;
|
||||
current_user.is_guest = true;
|
||||
assert.equal(validation_func(), false);
|
||||
|
||||
group_permission_settings.get_group_permission_setting_config = () => ({
|
||||
allow_everyone_group: true,
|
||||
});
|
||||
assert.equal(validation_func(), true);
|
||||
}
|
||||
|
||||
run_test("user_can_create_multiuse_invite", () => {
|
||||
|
@ -343,7 +345,7 @@ run_test("user_can_create_multiuse_invite", () => {
|
|||
);
|
||||
});
|
||||
|
||||
run_test("can_manage_user_group", () => {
|
||||
run_test("can_manage_user_group", ({override}) => {
|
||||
const admins = {
|
||||
description: "Administrators",
|
||||
name: "role:administrators",
|
||||
|
@ -407,30 +409,30 @@ run_test("can_manage_user_group", () => {
|
|||
|
||||
page_params.is_spectator = false;
|
||||
realm.realm_can_manage_all_groups = admins.id;
|
||||
current_user.user_id = 3;
|
||||
override(current_user, "user_id", 3);
|
||||
assert.ok(!settings_data.can_manage_user_group(students.id));
|
||||
|
||||
// non-admin group_creator
|
||||
current_user.user_id = 4;
|
||||
override(current_user, "user_id", 4);
|
||||
assert.ok(settings_data.can_manage_user_group(students.id));
|
||||
|
||||
// admin user
|
||||
current_user.user_id = 1;
|
||||
override(current_user, "user_id", 1);
|
||||
assert.ok(settings_data.can_manage_user_group(students.id));
|
||||
|
||||
// moderator user
|
||||
current_user.user_id = 2;
|
||||
override(current_user, "user_id", 2);
|
||||
assert.ok(!settings_data.can_manage_user_group(students.id));
|
||||
|
||||
realm.realm_can_manage_all_groups = members.id;
|
||||
current_user.user_id = 3;
|
||||
override(current_user, "user_id", 3);
|
||||
assert.ok(!settings_data.can_manage_user_group(students.id));
|
||||
|
||||
current_user.user_id = 2;
|
||||
override(current_user, "user_id", 2);
|
||||
assert.ok(settings_data.can_manage_user_group(students.id));
|
||||
|
||||
realm.realm_can_manage_all_groups = admins.id;
|
||||
current_user.user_id = 2;
|
||||
override(current_user, "user_id", 2);
|
||||
assert.ok(!settings_data.can_manage_user_group(students.id));
|
||||
|
||||
const event = {
|
||||
|
@ -442,11 +444,11 @@ run_test("can_manage_user_group", () => {
|
|||
user_groups.update(event);
|
||||
assert.ok(settings_data.can_manage_user_group(students.id));
|
||||
|
||||
current_user.user_id = 3;
|
||||
override(current_user, "user_id", 3);
|
||||
assert.ok(settings_data.can_manage_user_group(students.id));
|
||||
});
|
||||
|
||||
run_test("can_join_user_group", () => {
|
||||
run_test("can_join_user_group", ({override}) => {
|
||||
const admins = {
|
||||
description: "Administrators",
|
||||
name: "role:administrators",
|
||||
|
@ -516,11 +518,11 @@ run_test("can_join_user_group", () => {
|
|||
|
||||
page_params.is_spectator = false;
|
||||
// admin user
|
||||
current_user.user_id = 1;
|
||||
override(current_user, "user_id", 1);
|
||||
assert.ok(settings_data.can_join_user_group(students.id));
|
||||
|
||||
// moderator user
|
||||
current_user.user_id = 2;
|
||||
override(current_user, "user_id", 2);
|
||||
assert.ok(!settings_data.can_join_user_group(students.id));
|
||||
|
||||
let event = {
|
||||
|
@ -532,11 +534,11 @@ run_test("can_join_user_group", () => {
|
|||
user_groups.update(event);
|
||||
assert.ok(settings_data.can_join_user_group(students.id));
|
||||
|
||||
current_user.user_id = 1;
|
||||
override(current_user, "user_id", 1);
|
||||
assert.ok(settings_data.can_join_user_group(students.id));
|
||||
|
||||
// Some other user.
|
||||
current_user.user_id = 5;
|
||||
override(current_user, "user_id", 5);
|
||||
assert.ok(!settings_data.can_join_user_group(students.id));
|
||||
|
||||
event = {
|
||||
|
@ -551,16 +553,16 @@ run_test("can_join_user_group", () => {
|
|||
user_groups.update(event);
|
||||
assert.ok(settings_data.can_join_user_group(students.id));
|
||||
|
||||
current_user.user_id = 2;
|
||||
override(current_user, "user_id", 2);
|
||||
assert.ok(!settings_data.can_join_user_group(students.id));
|
||||
|
||||
// User can join the group if they can add anyone in the group which
|
||||
// depends on can_manage_group and realm.can_manage_all_groups settings.
|
||||
current_user.user_id = 4;
|
||||
override(current_user, "user_id", 4);
|
||||
assert.ok(settings_data.can_join_user_group(students.id));
|
||||
|
||||
realm.realm_can_manage_all_groups = moderators.id;
|
||||
current_user.user_id = 2;
|
||||
override(current_user, "user_id", 2);
|
||||
assert.ok(settings_data.can_join_user_group(students.id));
|
||||
});
|
||||
|
||||
|
@ -583,7 +585,7 @@ run_test("type_id_to_string", () => {
|
|||
assert.equal(settings_data.bot_type_id_to_string(5), undefined);
|
||||
});
|
||||
|
||||
run_test("user_can_access_all_other_users", () => {
|
||||
run_test("user_can_access_all_other_users", ({override}) => {
|
||||
const guest_user_id = 1;
|
||||
const member_user_id = 2;
|
||||
|
||||
|
@ -610,10 +612,10 @@ run_test("user_can_access_all_other_users", () => {
|
|||
assert.ok(settings_data.user_can_access_all_other_users());
|
||||
|
||||
page_params.is_spectator = false;
|
||||
current_user.user_id = member_user_id;
|
||||
override(current_user, "user_id", member_user_id);
|
||||
assert.ok(settings_data.user_can_access_all_other_users());
|
||||
|
||||
current_user.user_id = guest_user_id;
|
||||
override(current_user, "user_id", guest_user_id);
|
||||
assert.ok(!settings_data.user_can_access_all_other_users());
|
||||
|
||||
realm.realm_can_access_all_users_group = everyone.id;
|
||||
|
@ -645,7 +647,7 @@ run_test("user_can_create_private_streams", () => {
|
|||
);
|
||||
});
|
||||
|
||||
run_test("user_can_create_web_public_streams", () => {
|
||||
run_test("user_can_create_web_public_streams", ({override}) => {
|
||||
realm.server_web_public_streams_enabled = true;
|
||||
realm.realm_enable_spectator_access = true;
|
||||
|
||||
|
@ -661,7 +663,7 @@ run_test("user_can_create_web_public_streams", () => {
|
|||
is_system_group: true,
|
||||
direct_subgroup_ids: new Set([]),
|
||||
};
|
||||
current_user.user_id = owner_user_id;
|
||||
override(current_user, "user_id", owner_user_id);
|
||||
user_groups.initialize({realm_user_groups: [owners]});
|
||||
|
||||
realm.server_web_public_streams_enabled = true;
|
||||
|
|
|
@ -33,7 +33,7 @@ initialize_user_settings({user_settings: {}});
|
|||
function test(label, f) {
|
||||
run_test(label, (helpers) => {
|
||||
$("#realm-icon-upload-widget .upload-spinner-background").css = noop;
|
||||
current_user.is_admin = false;
|
||||
helpers.override(current_user, "is_admin", false);
|
||||
realm.realm_domains = [
|
||||
{domain: "example.com", allow_subdomains: true},
|
||||
{domain: "example.org", allow_subdomains: false},
|
||||
|
@ -788,8 +788,8 @@ test("test get_sorted_options_list", () => {
|
|||
);
|
||||
});
|
||||
|
||||
test("misc", () => {
|
||||
current_user.is_admin = false;
|
||||
test("misc", ({override}) => {
|
||||
override(current_user, "is_admin", false);
|
||||
$("#user-avatar-upload-widget").length = 1;
|
||||
$("#user_details_section").length = 1;
|
||||
|
||||
|
@ -843,7 +843,7 @@ test("misc", () => {
|
|||
assert.ok($("#user-avatar-upload-widget .image_upload_button").hasClass("hide"));
|
||||
|
||||
// If organization admin, these UI elements are never disabled.
|
||||
current_user.is_admin = true;
|
||||
override(current_user, "is_admin", true);
|
||||
settings_account.update_name_change_display();
|
||||
assert.ok(!$("#full_name").prop("disabled"));
|
||||
assert.ok(!$("#full_name_input_container").hasClass("disabled_setting_tooltip"));
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
const assert = require("node:assert/strict");
|
||||
|
||||
const {mock_esm, zrequire} = require("./lib/namespace");
|
||||
const {mock_esm, with_overrides, zrequire} = require("./lib/namespace");
|
||||
const {run_test, noop} = require("./lib/test");
|
||||
const $ = require("./lib/zjquery");
|
||||
const {current_user, realm} = require("./lib/zpage_params");
|
||||
|
@ -52,32 +52,34 @@ mock_esm("sortablejs", {default: Sortable});
|
|||
const settings_profile_fields = zrequire("settings_profile_fields");
|
||||
|
||||
function test_populate(opts, template_data) {
|
||||
const fields_data = opts.fields_data;
|
||||
with_overrides(({override}) => {
|
||||
const fields_data = opts.fields_data;
|
||||
|
||||
realm.custom_profile_field_types = custom_profile_field_types;
|
||||
current_user.is_admin = opts.is_admin;
|
||||
const $table = $("#admin_profile_fields_table");
|
||||
const $rows = $.create("rows");
|
||||
const $form = $.create("forms");
|
||||
$table.set_find_results("tr.profile-field-row", $rows);
|
||||
$table.set_find_results("tr.profile-field-form", $form);
|
||||
realm.custom_profile_field_types = custom_profile_field_types;
|
||||
override(current_user, "is_admin", opts.is_admin);
|
||||
const $table = $("#admin_profile_fields_table");
|
||||
const $rows = $.create("rows");
|
||||
const $form = $.create("forms");
|
||||
$table.set_find_results("tr.profile-field-row", $rows);
|
||||
$table.set_find_results("tr.profile-field-form", $form);
|
||||
|
||||
$table[0] = "stub";
|
||||
$table[0] = "stub";
|
||||
|
||||
$rows.remove = noop;
|
||||
$form.remove = noop;
|
||||
$rows.remove = noop;
|
||||
$form.remove = noop;
|
||||
|
||||
let num_appends = 0;
|
||||
$table.append = () => {
|
||||
num_appends += 1;
|
||||
};
|
||||
let num_appends = 0;
|
||||
$table.append = () => {
|
||||
num_appends += 1;
|
||||
};
|
||||
|
||||
loading.destroy_indicator = noop;
|
||||
loading.destroy_indicator = noop;
|
||||
|
||||
settings_profile_fields.do_populate_profile_fields(fields_data);
|
||||
settings_profile_fields.do_populate_profile_fields(fields_data);
|
||||
|
||||
assert.deepEqual(template_data, opts.expected_template_data);
|
||||
assert.equal(num_appends, fields_data.length);
|
||||
assert.deepEqual(template_data, opts.expected_template_data);
|
||||
assert.equal(num_appends, fields_data.length);
|
||||
});
|
||||
}
|
||||
|
||||
run_test("populate_profile_fields", ({mock_template}) => {
|
||||
|
|
|
@ -35,13 +35,13 @@ const test_user103 = {
|
|||
|
||||
function test(label, f) {
|
||||
run_test(label, (helpers) => {
|
||||
current_user.is_admin = false;
|
||||
helpers.override(current_user, "is_admin", false);
|
||||
people.init();
|
||||
people.add_active_user(me);
|
||||
people.add_active_user(test_user101);
|
||||
people.add_active_user(test_user102);
|
||||
people.add_active_user(test_user103);
|
||||
current_user.user_id = me.user_id;
|
||||
helpers.override(current_user, "user_id", me.user_id);
|
||||
people.initialize_current_user(me.user_id);
|
||||
f(helpers);
|
||||
});
|
||||
|
@ -70,11 +70,11 @@ test("basics", () => {
|
|||
assert.ok(!stream_create_subscribers_data.must_be_subscribed(test_user101.user_id));
|
||||
});
|
||||
|
||||
test("must_be_subscribed", () => {
|
||||
current_user.is_admin = false;
|
||||
test("must_be_subscribed", ({override}) => {
|
||||
override(current_user, "is_admin", false);
|
||||
assert.ok(stream_create_subscribers_data.must_be_subscribed(me.user_id));
|
||||
assert.ok(!stream_create_subscribers_data.must_be_subscribed(test_user101.user_id));
|
||||
current_user.is_admin = true;
|
||||
override(current_user, "is_admin", true);
|
||||
assert.ok(!stream_create_subscribers_data.must_be_subscribed(me.user_id));
|
||||
assert.ok(!stream_create_subscribers_data.must_be_subscribed(test_user101.user_id));
|
||||
});
|
||||
|
|
|
@ -72,9 +72,9 @@ const everyone_group = {
|
|||
|
||||
function test(label, f) {
|
||||
run_test(label, (helpers) => {
|
||||
current_user.is_admin = false;
|
||||
helpers.override(current_user, "is_admin", false);
|
||||
page_params.realm_users = [];
|
||||
current_user.is_guest = false;
|
||||
helpers.override(current_user, "is_guest", false);
|
||||
people.init();
|
||||
people.add_active_user(me);
|
||||
people.initialize_current_user(me.user_id);
|
||||
|
@ -270,7 +270,7 @@ test("basics", () => {
|
|||
]);
|
||||
});
|
||||
|
||||
test("get_streams_for_user", () => {
|
||||
test("get_streams_for_user", ({override}) => {
|
||||
const denmark = {
|
||||
subscribed: true,
|
||||
color: "blue",
|
||||
|
@ -340,12 +340,12 @@ test("get_streams_for_user", () => {
|
|||
]);
|
||||
assert.deepEqual(stream_data.get_streams_for_user(test_user.user_id).can_subscribe, []);
|
||||
// Verify can subscribe if we're an administrator.
|
||||
current_user.is_admin = true;
|
||||
override(current_user, "is_admin", true);
|
||||
assert.deepEqual(stream_data.get_streams_for_user(test_user.user_id).can_subscribe, [
|
||||
world,
|
||||
errors,
|
||||
]);
|
||||
current_user.is_admin = false;
|
||||
override(current_user, "is_admin", false);
|
||||
|
||||
realm.realm_invite_to_stream_policy = settings_config.common_policy_values.by_members.code;
|
||||
assert.deepEqual(stream_data.get_streams_for_user(test_user.user_id).can_subscribe, [
|
||||
|
@ -383,7 +383,7 @@ test("renames", () => {
|
|||
assert.equal(actual_id, 42);
|
||||
});
|
||||
|
||||
test("admin_options", () => {
|
||||
test("admin_options", ({override}) => {
|
||||
function make_sub() {
|
||||
const sub = {
|
||||
subscribed: false,
|
||||
|
@ -409,7 +409,7 @@ test("admin_options", () => {
|
|||
}
|
||||
|
||||
// non-admins can't do anything
|
||||
current_user.is_admin = false;
|
||||
override(current_user, "is_admin", false);
|
||||
let sub = make_sub();
|
||||
assert.ok(!is_realm_admin(sub));
|
||||
assert.ok(!can_change_stream_permissions(sub));
|
||||
|
@ -418,7 +418,7 @@ test("admin_options", () => {
|
|||
assert.equal(sub.color, "blue");
|
||||
|
||||
// the remaining cases are for admin users
|
||||
current_user.is_admin = true;
|
||||
override(current_user, "is_admin", true);
|
||||
|
||||
// admins can make public streams become private
|
||||
sub = make_sub();
|
||||
|
@ -440,7 +440,7 @@ test("admin_options", () => {
|
|||
assert.ok(can_change_stream_permissions(sub));
|
||||
});
|
||||
|
||||
test("stream_settings", () => {
|
||||
test("stream_settings", ({override}) => {
|
||||
const cinnamon = {
|
||||
stream_id: 1,
|
||||
name: "c",
|
||||
|
@ -517,7 +517,7 @@ test("stream_settings", () => {
|
|||
// For guest user only retrieve subscribed streams
|
||||
sub_rows = stream_settings_data.get_updated_unsorted_subs();
|
||||
assert.equal(sub_rows.length, 3);
|
||||
current_user.is_guest = true;
|
||||
override(current_user, "is_guest", true);
|
||||
sub_rows = stream_settings_data.get_updated_unsorted_subs();
|
||||
assert.equal(sub_rows[0].name, "c");
|
||||
assert.equal(sub_rows[1].name, "a");
|
||||
|
@ -877,10 +877,10 @@ test("create_sub", () => {
|
|||
assert.equal(antarctica_sub.color, "#76ce90");
|
||||
});
|
||||
|
||||
test("creator_id", () => {
|
||||
test("creator_id", ({override}) => {
|
||||
people.add_active_user(test_user);
|
||||
realm.realm_can_access_all_users_group = everyone_group.id;
|
||||
current_user.user_id = me.user_id;
|
||||
override(current_user, "user_id", me.user_id);
|
||||
// When creator id is not a valid user id
|
||||
assert.throws(() => stream_data.maybe_get_creator_details(-1), {
|
||||
name: "Error",
|
||||
|
@ -973,7 +973,7 @@ test("edge_cases", () => {
|
|||
stream_settings_data.sort_for_stream_settings(bad_stream_ids);
|
||||
});
|
||||
|
||||
test("get_invite_stream_data", () => {
|
||||
test("get_invite_stream_data", ({override}) => {
|
||||
// add default stream
|
||||
const orie = {
|
||||
name: "Orie",
|
||||
|
@ -986,7 +986,7 @@ test("get_invite_stream_data", () => {
|
|||
people.init();
|
||||
people.add_active_user(me);
|
||||
people.initialize_current_user(me.user_id);
|
||||
current_user.is_admin = true;
|
||||
override(current_user, "is_admin", true);
|
||||
|
||||
stream_data.add_sub(orie);
|
||||
stream_data.set_realm_default_streams([orie]);
|
||||
|
@ -1052,7 +1052,7 @@ test("get_invite_stream_data", () => {
|
|||
assert.deepEqual(stream_data.get_invite_stream_data(), expected_list);
|
||||
});
|
||||
|
||||
test("can_post_messages_in_stream", () => {
|
||||
test("can_post_messages_in_stream", ({override}) => {
|
||||
const social = {
|
||||
subscribed: true,
|
||||
color: "red",
|
||||
|
@ -1063,23 +1063,23 @@ test("can_post_messages_in_stream", () => {
|
|||
history_public_to_subscribers: false,
|
||||
stream_post_policy: settings_config.stream_post_policy_values.admins.code,
|
||||
};
|
||||
current_user.is_admin = false;
|
||||
override(current_user, "is_admin", false);
|
||||
assert.equal(stream_data.can_post_messages_in_stream(social), false);
|
||||
|
||||
current_user.is_admin = true;
|
||||
override(current_user, "is_admin", true);
|
||||
assert.equal(stream_data.can_post_messages_in_stream(social), true);
|
||||
|
||||
social.stream_post_policy = settings_config.stream_post_policy_values.moderators.code;
|
||||
current_user.is_moderator = false;
|
||||
current_user.is_admin = false;
|
||||
override(current_user, "is_moderator", false);
|
||||
override(current_user, "is_admin", false);
|
||||
|
||||
assert.equal(stream_data.can_post_messages_in_stream(social), false);
|
||||
|
||||
current_user.is_moderator = true;
|
||||
override(current_user, "is_moderator", true);
|
||||
assert.equal(stream_data.can_post_messages_in_stream(social), true);
|
||||
|
||||
social.stream_post_policy = settings_config.stream_post_policy_values.non_new_members.code;
|
||||
current_user.is_moderator = false;
|
||||
override(current_user, "is_moderator", false);
|
||||
me.date_joined = new Date(Date.now());
|
||||
realm.realm_waiting_period_threshold = 10;
|
||||
assert.equal(stream_data.can_post_messages_in_stream(social), false);
|
||||
|
@ -1087,7 +1087,7 @@ test("can_post_messages_in_stream", () => {
|
|||
me.date_joined = new Date(Date.now() - 20 * 86400000);
|
||||
assert.equal(stream_data.can_post_messages_in_stream(social), true);
|
||||
|
||||
current_user.is_guest = true;
|
||||
override(current_user, "is_guest", true);
|
||||
assert.equal(stream_data.can_post_messages_in_stream(social), false);
|
||||
|
||||
social.stream_post_policy = settings_config.stream_post_policy_values.everyone.code;
|
||||
|
@ -1097,7 +1097,7 @@ test("can_post_messages_in_stream", () => {
|
|||
assert.equal(stream_data.can_post_messages_in_stream(social), false);
|
||||
});
|
||||
|
||||
test("can_unsubscribe_others", () => {
|
||||
test("can_unsubscribe_others", ({override}) => {
|
||||
const admin_user_id = 1;
|
||||
const moderator_user_id = 2;
|
||||
const member_user_id = 3;
|
||||
|
@ -1165,17 +1165,17 @@ test("can_unsubscribe_others", () => {
|
|||
|
||||
// Even with the nobody system group, admins can still unsubscribe others.
|
||||
sub.can_remove_subscribers_group = nobody.id;
|
||||
current_user.is_admin = true;
|
||||
override(current_user, "is_admin", true);
|
||||
assert.equal(stream_data.can_unsubscribe_others(sub), true);
|
||||
current_user.is_admin = false;
|
||||
override(current_user, "is_admin", false);
|
||||
assert.equal(stream_data.can_unsubscribe_others(sub), false);
|
||||
|
||||
// This isn't a real state, but we want coverage on !can_view_subscribers.
|
||||
sub.subscribed = false;
|
||||
sub.invite_only = true;
|
||||
current_user.is_admin = true;
|
||||
override(current_user, "is_admin", true);
|
||||
assert.equal(stream_data.can_unsubscribe_others(sub), true);
|
||||
current_user.is_admin = false;
|
||||
override(current_user, "is_admin", false);
|
||||
assert.equal(stream_data.can_unsubscribe_others(sub), false);
|
||||
});
|
||||
|
||||
|
@ -1279,7 +1279,7 @@ test("options for dropdown widget", () => {
|
|||
]);
|
||||
});
|
||||
|
||||
test("can_access_stream_email", () => {
|
||||
test("can_access_stream_email", ({override}) => {
|
||||
const social = {
|
||||
subscribed: true,
|
||||
color: "red",
|
||||
|
@ -1289,10 +1289,10 @@ test("can_access_stream_email", () => {
|
|||
invite_only: true,
|
||||
history_public_to_subscribers: false,
|
||||
};
|
||||
current_user.is_admin = false;
|
||||
override(current_user, "is_admin", false);
|
||||
assert.equal(stream_data.can_access_stream_email(social), true);
|
||||
|
||||
current_user.is_admin = true;
|
||||
override(current_user, "is_admin", true);
|
||||
assert.equal(stream_data.can_access_stream_email(social), true);
|
||||
|
||||
social.subscribed = false;
|
||||
|
@ -1301,10 +1301,10 @@ test("can_access_stream_email", () => {
|
|||
social.invite_only = false;
|
||||
assert.equal(stream_data.can_access_stream_email(social), true);
|
||||
|
||||
current_user.is_admin = false;
|
||||
override(current_user, "is_admin", false);
|
||||
assert.equal(stream_data.can_access_stream_email(social), true);
|
||||
|
||||
current_user.is_guest = true;
|
||||
override(current_user, "is_guest", true);
|
||||
assert.equal(stream_data.can_access_stream_email(social), false);
|
||||
|
||||
social.subscribed = true;
|
||||
|
|
|
@ -5,11 +5,10 @@ const assert = require("node:assert/strict");
|
|||
const {mock_esm, set_global, zrequire} = require("./lib/namespace");
|
||||
const {run_test, noop} = require("./lib/test");
|
||||
const $ = require("./lib/zjquery");
|
||||
const {current_user, page_params} = require("./lib/zpage_params");
|
||||
const {page_params} = require("./lib/zpage_params");
|
||||
|
||||
set_global("document", "document-stub");
|
||||
|
||||
current_user.is_admin = false;
|
||||
page_params.realm_users = [];
|
||||
|
||||
// We use this with override.
|
||||
|
|
|
@ -56,9 +56,9 @@ const me = {
|
|||
people.add_active_user(me);
|
||||
people.initialize_current_user(me.user_id);
|
||||
|
||||
run_test("create_item", () => {
|
||||
current_user.user_id = me.user_id;
|
||||
current_user.is_admin = true;
|
||||
run_test("create_item", ({override}) => {
|
||||
override(current_user, "user_id", me.user_id);
|
||||
override(current_user, "is_admin", true);
|
||||
function test_create_item(
|
||||
stream_name,
|
||||
current_items,
|
||||
|
|
|
@ -151,7 +151,7 @@ run_test("reply_message_stream", ({override}) => {
|
|||
send_message_args = data;
|
||||
});
|
||||
|
||||
current_user.user_id = 44;
|
||||
override(current_user, "user_id", 44);
|
||||
server_events.queue_id = 66;
|
||||
sent_messages.get_new_local_id = () => "99";
|
||||
|
||||
|
@ -192,7 +192,7 @@ run_test("reply_message_private", ({override}) => {
|
|||
send_message_args = data;
|
||||
});
|
||||
|
||||
current_user.user_id = 155;
|
||||
override(current_user, "user_id", 155);
|
||||
server_events.queue_id = 177;
|
||||
sent_messages.get_new_local_id = () => "199";
|
||||
|
||||
|
|
|
@ -178,7 +178,7 @@ function test(label, f) {
|
|||
recent_senders.clear_for_testing();
|
||||
peer_data.clear_for_testing();
|
||||
people.clear_recipient_counts_for_testing();
|
||||
current_user.is_admin = false;
|
||||
helpers.override(current_user, "is_admin", false);
|
||||
realm.realm_is_zephyr_mirror_realm = false;
|
||||
|
||||
f(helpers);
|
||||
|
|
|
@ -52,8 +52,6 @@ mock_esm("../src/settings_streams", {
|
|||
maybe_disable_widgets() {},
|
||||
});
|
||||
|
||||
current_user.is_admin = true;
|
||||
|
||||
const people = zrequire("people");
|
||||
const settings_config = zrequire("settings_config");
|
||||
const user_events = zrequire("user_events");
|
||||
|
|
Loading…
Reference in New Issue