mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-17 20:16:14 +00:00
Add optional filtered
attribute to notification entities in REST API (#31011)
This commit is contained in:
parent
17117109ad
commit
1dd8262071
|
@ -3,6 +3,8 @@
|
|||
class REST::NotificationSerializer < ActiveModel::Serializer
|
||||
attributes :id, :type, :created_at, :group_key
|
||||
|
||||
attribute :filtered, if: :filtered?
|
||||
|
||||
belongs_to :from_account, key: :account, serializer: REST::AccountSerializer
|
||||
belongs_to :target_status, key: :status, if: :status_type?, serializer: REST::StatusSerializer
|
||||
belongs_to :report, if: :report_type?, serializer: REST::ReportSerializer
|
||||
|
@ -32,4 +34,6 @@ class REST::NotificationSerializer < ActiveModel::Serializer
|
|||
def moderation_warning_event?
|
||||
object.type == :moderation_warning
|
||||
end
|
||||
|
||||
delegate :filtered?, to: :object
|
||||
end
|
||||
|
|
|
@ -20,8 +20,8 @@ RSpec.describe 'Notifications' do
|
|||
before do
|
||||
first_status = PostStatusService.new.call(user.account, text: 'Test')
|
||||
ReblogService.new.call(bob.account, first_status)
|
||||
mentioning_status = PostStatusService.new.call(bob.account, text: 'Hello @alice')
|
||||
mentioning_status.mentions.first
|
||||
PostStatusService.new.call(bob.account, text: 'Hello @alice')
|
||||
PostStatusService.new.call(tom.account, text: 'Hello @alice', visibility: :direct) # Filtered by default
|
||||
FavouriteService.new.call(bob.account, first_status)
|
||||
FavouriteService.new.call(tom.account, first_status)
|
||||
FollowService.new.call(bob.account, user.account)
|
||||
|
@ -34,10 +34,22 @@ RSpec.describe 'Notifications' do
|
|||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_json_types).to include 'reblog'
|
||||
expect(body_json_types).to include 'mention'
|
||||
expect(body_json_types).to include 'favourite'
|
||||
expect(body_json_types).to include 'follow'
|
||||
expect(body_as_json.size).to eq 5
|
||||
expect(body_json_types).to include('reblog', 'mention', 'favourite', 'follow')
|
||||
expect(body_as_json.any? { |x| x[:filtered] }).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'with include_filtered' do
|
||||
let(:params) { { include_filtered: true } }
|
||||
|
||||
it 'returns expected notification types, including filtered notifications' do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json.size).to eq 6
|
||||
expect(body_json_types).to include('reblog', 'mention', 'favourite', 'follow')
|
||||
expect(body_as_json.any? { |x| x[:filtered] }).to be true
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -96,7 +108,7 @@ RSpec.describe 'Notifications' do
|
|||
it 'returns the requested number of notifications paginated', :aggregate_failures do
|
||||
subject
|
||||
|
||||
notifications = user.account.notifications
|
||||
notifications = user.account.notifications.browserable
|
||||
|
||||
expect(body_as_json.size)
|
||||
.to eq(params[:limit])
|
||||
|
|
Loading…
Reference in a new issue