Merge pull request #2398 from basecamp/notifications-tray-api

Add JSON response support for `notifications/tray`
This commit is contained in:
Alp Keser
2026-02-18 13:19:59 +03:00
committed by GitHub
10 changed files with 68 additions and 4 deletions
@@ -176,6 +176,7 @@ class CardsControllerTest < ActionDispatch::IntegrationTest
assert_equal card.title, @response.parsed_body["title"]
assert_equal card.closed?, @response.parsed_body["closed"]
assert_equal card.postponed?, @response.parsed_body["postponed"]
assert_equal 2, @response.parsed_body["steps"].size
assert_equal card_comments_url(card), @response.parsed_body["comments_url"]
assert_equal card_reactions_url(card), @response.parsed_body["reactions_url"]
@@ -11,4 +11,24 @@ class Notifications::TraysControllerTest < ActionDispatch::IntegrationTest
assert_response :success
assert_select "div", text: /Layout is broken/
end
test "show as JSON" do
expected_ids = users(:kevin).notifications.unread.ordered.limit(100).pluck(:id)
get tray_notifications_path(format: :json)
assert_response :success
assert_equal expected_ids, @response.parsed_body.map { |s| s["id"] }
end
test "show as JSON with include_read includes read notifications" do
notifications = users(:kevin).notifications
expected_ids = notifications.unread.ordered.limit(100).pluck(:id) +
notifications.read.ordered.limit(100).pluck(:id)
get tray_notifications_path(format: :json, include_read: true)
assert_response :success
assert_equal expected_ids, @response.parsed_body.map { |s| s["id"] }
end
end
@@ -22,5 +22,13 @@ class NotificationsControllerTest < ActionDispatch::IntegrationTest
assert_not_nil notification["card"]
assert_not_nil notification["creator"]
assert_not_nil notification["unread_count"]
assert_not_nil notification.dig("creator", "avatar_url")
assert_not_nil notification.dig("card", "number")
assert_not_nil notification.dig("card", "board_name")
assert_not_nil notification.dig("card", "column")
card = notifications(:logo_assignment_kevin).card
assert_equal card.closed?, notification.dig("card", "closed")
assert_equal card.postponed?, notification.dig("card", "postponed")
end
end