mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-08-21 14:33:46 +09:00
20ab5b1bc6
Adds a new endpoint that allows bots to add emoji reactions (boosts) to messages: POST /rooms/:room_id/:bot_key/messages/:message_id/boosts This enables bots to acknowledge messages with reactions like 👀 (eyes) when mentioned, providing immediate feedback to users before generating a full response. The endpoint: - Validates the bot is a member of the room - Validates the message exists in the room - Broadcasts the boost to connected clients via Turbo Streams - Returns 201 Created on success, 404 if room/message not found Co-authored-by: openhands <openhands@all-hands.dev>
77 lines
2.5 KiB
Ruby
77 lines
2.5 KiB
Ruby
require "test_helper"
|
|
|
|
class Messages::Boosts::ByBotsControllerTest < ActionDispatch::IntegrationTest
|
|
setup do
|
|
@room = rooms(:watercooler)
|
|
@message = messages(:fourth) # Message in watercooler room where bender bot is a member
|
|
@bot = users(:bender)
|
|
end
|
|
|
|
test "create adds a boost to the message" do
|
|
assert_difference -> { @message.boosts.count }, +1 do
|
|
post room_bot_message_boosts_url(@room, @bot.bot_key, @message), params: +"👀"
|
|
assert_response :created
|
|
end
|
|
|
|
assert_equal "👀", @message.boosts.last.content
|
|
end
|
|
|
|
test "create with emoji reaction" do
|
|
assert_difference -> { Boost.count }, +1 do
|
|
post room_bot_message_boosts_url(@room, @bot.bot_key, @message), params: +"🎉"
|
|
assert_response :created
|
|
end
|
|
end
|
|
|
|
test "create with text reaction" do
|
|
assert_difference -> { Boost.count }, +1 do
|
|
post room_bot_message_boosts_url(@room, @bot.bot_key, @message), params: +"Nice!"
|
|
assert_response :created
|
|
end
|
|
|
|
assert_equal "Nice!", @message.boosts.last.content
|
|
end
|
|
|
|
test "create broadcasts the boost" do
|
|
assert_turbo_stream_broadcasts [ @message.room, :messages ], count: 1 do
|
|
post room_bot_message_boosts_url(@room, @bot.bot_key, @message), params: +"👍"
|
|
end
|
|
end
|
|
|
|
test "create requires valid bot key" do
|
|
assert_no_difference -> { Boost.count } do
|
|
post room_bot_message_boosts_url(@room, "invalid-bot-key", @message), params: +"👀"
|
|
end
|
|
assert_response :redirect # Redirects to login
|
|
end
|
|
|
|
test "create returns not_found for room bot is not a member of" do
|
|
room_without_bot = rooms(:designers)
|
|
message_in_other_room = messages(:first) # Message in designers room
|
|
|
|
assert_no_difference -> { Boost.count } do
|
|
post room_bot_message_boosts_url(room_without_bot, @bot.bot_key, message_in_other_room), params: +"👀"
|
|
end
|
|
assert_response :not_found
|
|
end
|
|
|
|
test "create returns not_found for message not in the room" do
|
|
message_in_other_room = messages(:first) # Message in designers room, not watercooler
|
|
|
|
assert_no_difference -> { Boost.count } do
|
|
post room_bot_message_boosts_url(@room, @bot.bot_key, message_in_other_room), params: +"👀"
|
|
end
|
|
assert_response :not_found
|
|
end
|
|
|
|
test "create can't be abused to post boosts as regular user" do
|
|
user = users(:kevin)
|
|
bot_key = "#{user.id}-"
|
|
|
|
assert_no_difference -> { Boost.count } do
|
|
post room_bot_message_boosts_url(@room, bot_key, @message), params: +"👀"
|
|
end
|
|
assert_response :redirect
|
|
end
|
|
end
|