Skip to content

Commit 32e62f4

Browse files
committed
DEV: Update tests
1 parent ceef8b5 commit 32e62f4

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

app/controllers/discourse_ai/ai_bot/conversations_controller.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ def index
1313
# Step 2: Query for PM topics including current_user and any bot ID
1414
pms =
1515
Topic
16+
.private_messages_for_user(current_user)
1617
.joins(:topic_users)
17-
.private_messages
18-
.where("topic_users.user_id IN (?)", bot_user_ids + [current_user.id])
19-
.group("topics.id") # Group by topic to ensure distinct results
20-
.having("COUNT(topic_users.user_id) > 1") # Ensure multiple participants in the PM
18+
.where(topic_users: { user_id: bot_user_ids })
19+
.distinct
2120

2221
# Step 3: Serialize (empty array if no results)
2322
serialized_pms = serialize_data(pms, BasicTopicSerializer)

spec/system/ai_bot/personal_message_spec.rb

+10-15
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,22 @@
1515
AiPersona.last.update!(user_id: user.id)
1616
user
1717
end
18-
fab!(:llm_model) do
19-
Fabricate(:llm_model, provider: "anthropic", name: "claude-3-opus", enabled_chat_bot: true)
20-
end
18+
fab!(:llm_model) { Fabricate(:llm_model, enabled_chat_bot: true) }
2119

22-
fab!(:pm) do
23-
Fabricate(
24-
:private_message_topic,
25-
title: "AI Conversation Test",
26-
user: user,
27-
topic_allowed_users: [
28-
Fabricate.build(:topic_allowed_user, user: user),
29-
Fabricate.build(:topic_allowed_user, user: bot_user),
30-
],
31-
)
20+
fab!(:pm) { Fabricate(:private_message_topic, title: "AI Conversation Test", user: user) }
21+
fab!(:reply) do
22+
Fabricate(:post, topic: pm, user: user, post_number: 1, raw: "test test test user reply")
23+
end
24+
fab!(:bot_reply) do
25+
Fabricate(:post, topic: pm, user: bot_user, post_number: 2, raw: "test test test bot reply")
3226
end
33-
fab!(:reply) { Fabricate(:post, topic: pm, user: user, raw: "test test test user reply") }
34-
fab!(:bot_reply) { Fabricate(:post, topic: pm, user: bot_user, raw: "test test test bot reply") }
27+
fab!(:topic_user) { Fabricate(:topic_user, topic: pm, user: user) }
28+
fab!(:topic_bot_user) { Fabricate(:topic_user, topic: pm, user: bot_user) }
3529

3630
before do
3731
SiteSetting.ai_enable_experimental_bot_ux = true
3832
SiteSetting.ai_bot_enabled = true
33+
toggle_enabled_bots(bots: [llm_model])
3934
SiteSetting.ai_bot_allowed_groups = group.id.to_s
4035
sign_in(user)
4136

0 commit comments

Comments
 (0)