Skip to content

Commit fd856e8

Browse files
committed
fix: adjust threshold comparison and update unit tests
- Updated threshold comparison to use `>=` instead of `>` in chat rules. - Enhanced unit tests to cover cases for the adjusted threshold logic.
1 parent ae2b6e1 commit fd856e8

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

backend/core/src/core/services/chat/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def get_all_paginated(
290290
exists().where(TelegramChatRuleGroup.chat_id == TelegramChat.id)
291291
)
292292
query = query.having(
293-
MANAGED_USERS_COUNT_QUERY > DEFAULT_MANAGED_USERS_PUBLIC_THRESHOLD
293+
MANAGED_USERS_COUNT_QUERY >= DEFAULT_MANAGED_USERS_PUBLIC_THRESHOLD
294294
)
295295

296296
# First, apply any custom rules provided

backend/tests/unit/core/actions/chat/test_telegram_chat_action.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
from tests.factories.rule.group import TelegramChatRuleGroupFactory
1313
from tests.utils.misc import AsyncIterator
1414
from core.actions.chat import TelegramChatAction
15-
from core.constants import REQUIRED_BOT_PRIVILEGES
15+
from core.constants import (
16+
REQUIRED_BOT_PRIVILEGES,
17+
DEFAULT_MANAGED_USERS_PUBLIC_THRESHOLD,
18+
)
1619
from core.dtos.chat import (
1720
TelegramChatDTO,
1821
TelegramChatOrderingRuleDTO,
@@ -66,6 +69,9 @@ def test_get_all__success(db_session: Session) -> None:
6669
# For get_all it's mandatory that chat has at least one rule group to be treated as active
6770
for chat in chats:
6871
TelegramChatRuleGroupFactory.with_session(db_session).create(chat=chat)
72+
TelegramChatUserFactory.with_session(db_session).create_batch(
73+
DEFAULT_MANAGED_USERS_PUBLIC_THRESHOLD, chat=chat
74+
)
6975
# The default ordering is by users-count -> ID
7076
ordered_chats = (
7177
db_session.query(TelegramChat)
@@ -125,8 +131,11 @@ def test_get_all__pagination__success(
125131
# For get_all it's mandatory that chat has at least one rule group to be treated as active
126132
for chat in chats:
127133
TelegramChatRuleGroupFactory.with_session(db_session).create(chat=chat)
134+
TelegramChatUserFactory.with_session(db_session).create_batch(
135+
DEFAULT_MANAGED_USERS_PUBLIC_THRESHOLD, chat=chat
136+
)
128137

129-
ordered_chats = sorted(chats, key=lambda chat: chat.id)
138+
ordered_chats = sorted(chats, key=lambda _chat: _chat.id)
130139

131140
# Act
132141
action = TelegramChatAction(db_session)
@@ -172,6 +181,9 @@ def test_get_all__sorting__success(db_session: Session, is_ascending: bool) -> N
172181
# For get_all it's mandatory that chat has at least one rule group to be treated as active
173182
for _chat in chats:
174183
TelegramChatRuleGroupFactory.with_session(db_session).create(chat=_chat)
184+
TelegramChatUserFactory.with_session(db_session).create_batch(
185+
DEFAULT_MANAGED_USERS_PUBLIC_THRESHOLD, chat=_chat
186+
)
175187

176188
# Assign user to one chat only to ensure it doesn't impact results
177189
TelegramChatUserFactory.with_session(db_session).create(

0 commit comments

Comments
 (0)