-
Notifications
You must be signed in to change notification settings - Fork 716
feat: Add bot API endpoints for reading messages and adding reactions #190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
d4a5678
5340f3d
057d565
c82a8d3
e8c1349
20ab5b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,8 +51,78 @@ class Messages::ByBotsControlleTest < ActionDispatch::IntegrationTest | |
| assert_response :redirect | ||
| end | ||
|
|
||
| test "denied index" do | ||
| get room_messages_url(@room, bot_key: users(:bender).bot_key, format: :json) | ||
| test "index returns messages as JSON" do | ||
| get room_bot_messages_index_url(@room, users(:bender).bot_key) | ||
| assert_response :success | ||
|
|
||
| json = JSON.parse(response.body) | ||
| assert json["room"]["id"].present? | ||
| assert json["room"]["name"].present? | ||
| assert json["messages"].is_a?(Array) | ||
| assert json["pagination"].present? | ||
| end | ||
|
|
||
| test "index includes message details" do | ||
| # Create a message in the room first | ||
| post room_bot_messages_url(@room, users(:bender).bot_key), params: +"Test message for index" | ||
|
|
||
| get room_bot_messages_index_url(@room, users(:bender).bot_key) | ||
| assert_response :success | ||
|
|
||
| json = JSON.parse(response.body) | ||
| message = json["messages"].find { |m| m["body"]["plain"] == "Test message for index" } | ||
| assert message.present?, "Expected to find the test message" | ||
| assert message["id"].present? | ||
| assert message["created_at"].present? | ||
| assert message["creator"]["id"].present? | ||
| assert message["creator"]["name"].present? | ||
| end | ||
|
|
||
| test "index supports pagination with before parameter" do | ||
| # Use a message from the watercooler room (where bender is a member) | ||
| message_in_room = messages(:thirteenth) # Latest message in watercooler | ||
| get room_bot_messages_index_url(@room, users(:bender).bot_key, before: message_in_room.id) | ||
| assert_response :success | ||
| end | ||
|
|
||
| test "index supports pagination with after parameter" do | ||
| # Use a message from the watercooler room (where bender is a member) | ||
| message_in_room = messages(:fourth) # First message in watercooler | ||
| get room_bot_messages_index_url(@room, users(:bender).bot_key, after: message_in_room.id) | ||
| assert_response :success | ||
| end | ||
|
Comment on lines
+88
to
+93
|
||
|
|
||
| test "index requires valid bot key" do | ||
| get room_bot_messages_index_url(@room, "invalid-bot-key") | ||
| assert_response :redirect # Redirects to login | ||
| end | ||
|
|
||
| test "index returns not_found for room bot is not a member of" do | ||
| # bender bot is NOT a member of the designers room | ||
| room_without_bot = rooms(:designers) | ||
| get room_bot_messages_index_url(room_without_bot, users(:bender).bot_key) | ||
| assert_response :not_found | ||
| end | ||
|
|
||
| test "index works for room bot IS a member of" do | ||
| # bender bot IS a member of watercooler | ||
| room_with_bot = rooms(:watercooler) | ||
| get room_bot_messages_index_url(room_with_bot, users(:bender).bot_key) | ||
| assert_response :success | ||
| end | ||
|
|
||
| test "create returns not_found for room bot is not a member of" do | ||
| # bender bot is NOT a member of the designers room - verify create matches index behavior | ||
| room_without_bot = rooms(:designers) | ||
| assert_no_difference -> { Message.count } do | ||
| post room_bot_messages_url(room_without_bot, users(:bender).bot_key), params: +"Hello!" | ||
| end | ||
| assert_response :not_found | ||
| end | ||
|
|
||
| test "regular messages index still denied for bots" do | ||
| # The standard messages endpoint (not the bot-specific one) should still be forbidden | ||
| get room_messages_url(@room, bot_key: users(:bender).bot_key) | ||
| assert_response :forbidden | ||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the enum predicate method
bot?instead of comparing to the string "bot". This is consistent with how the codebase checks enum values elsewhere (e.g.,administrator?in User::Role) and is the idiomatic Rails pattern for enum checks.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in e8c1349 - now using message.creator.bot? which is the idiomatic Rails enum predicate pattern.