Fix AutoJoinChannelBatch tests

This commit is contained in:
Jan Cernik 2023-02-08 23:32:21 -03:00
parent f06eda6131
commit 0ccedf7009
No known key found for this signature in database
2 changed files with 8 additions and 4 deletions

View File

@ -30,6 +30,7 @@ module Jobs
last_seen_at: 3.months.ago,
channel_category: channel.chatable_id,
mode: UserChatChannelMembership.join_modes[:automatic],
permission_type: CategoryGroup.permission_types[:create_post],
}
new_member_ids = DB.query_single(create_memberships_query(category), query_args)
@ -58,7 +59,8 @@ module Jobs
query += <<~SQL if category.read_restricted?
INNER JOIN group_users gu ON gu.user_id = users.id
LEFT OUTER JOIN category_groups cg ON cg.group_id = gu.group_id
LEFT OUTER JOIN category_groups cg ON cg.group_id = gu.group_id AND
cg.permission_type <= :permission_type
SQL
query += <<~SQL
@ -66,7 +68,7 @@ module Jobs
users.staged IS FALSE AND users.active AND
NOT EXISTS(SELECT 1 FROM anonymous_users a WHERE a.user_id = users.id) AND
(suspended_till IS NULL OR suspended_till <= :suspended_until) AND
(last_seen_at > :last_seen_at) AND
(last_seen_at IS NULL OR last_seen_at > :last_seen_at) AND
uo.chat_enabled AND
uccm.id IS NULL
SQL

View File

@ -177,12 +177,14 @@ describe Jobs::AutoJoinChannelBatch do
end
it "doesn't join users with read-only access to the category" do
restricted_category = Fabricate(:category, read_restricted: true)
another_user = Fabricate(:user, last_seen_at: 15.minutes.ago)
non_chatters_group = Fabricate(:group)
readonly_channel = Fabricate(:category_channel, chatable: category, auto_join_users: true)
readonly_channel =
Fabricate(:category_channel, chatable: restricted_category, auto_join_users: true)
Fabricate(
:category_group,
category: category,
category: restricted_category,
group: non_chatters_group,
permission_type: CategoryGroup.permission_types[:readonly],
)