Merge pull request #2398 from basecamp/notifications-tray-api
Add JSON response support for `notifications/tray`
This commit is contained in:
@@ -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
|
||||
|
||||
Vendored
+3
@@ -5,6 +5,7 @@ logo_assignment_kevin:
|
||||
card: logo_uuid
|
||||
unread_count: 2
|
||||
created_at: <%= 1.week.ago %>
|
||||
updated_at: <%= 1.week.ago + 1.second %>
|
||||
creator: david_uuid
|
||||
account: 37s_uuid
|
||||
|
||||
@@ -15,6 +16,7 @@ layout_commented_kevin:
|
||||
card: layout_uuid
|
||||
unread_count: 1
|
||||
created_at: <%= 1.week.ago %>
|
||||
updated_at: <%= 1.week.ago + 2.seconds %>
|
||||
creator: david_uuid
|
||||
account: 37s_uuid
|
||||
|
||||
@@ -25,5 +27,6 @@ logo_mentioned_david:
|
||||
card: logo_uuid
|
||||
unread_count: 2
|
||||
created_at: <%= 1.week.ago %>
|
||||
updated_at: <%= 1.week.ago + 3.seconds %>
|
||||
creator: david_uuid
|
||||
account: 37s_uuid
|
||||
|
||||
Reference in New Issue
Block a user