note_serializer_spec.rb 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe ActivityPub::NoteSerializer do
  4. subject { JSON.parse(@serialization.to_json) }
  5. let!(:account) { Fabricate(:account) }
  6. let!(:other) { Fabricate(:account) }
  7. let!(:parent) { Fabricate(:status, account: account, visibility: :public) }
  8. let!(:reply_by_account_first) { Fabricate(:status, account: account, thread: parent, visibility: :public) }
  9. let!(:reply_by_account_next) { Fabricate(:status, account: account, thread: parent, visibility: :public) }
  10. let!(:reply_by_other_first) { Fabricate(:status, account: other, thread: parent, visibility: :public) }
  11. let!(:reply_by_account_third) { Fabricate(:status, account: account, thread: parent, visibility: :public) }
  12. let!(:reply_by_account_visibility_direct) { Fabricate(:status, account: account, thread: parent, visibility: :direct) }
  13. before(:each) do
  14. @serialization = ActiveModelSerializers::SerializableResource.new(parent, serializer: described_class, adapter: ActivityPub::Adapter)
  15. end
  16. it 'has a Note type' do
  17. expect(subject['type']).to eql('Note')
  18. end
  19. it 'has a replies collection' do
  20. expect(subject['replies']['type']).to eql('Collection')
  21. end
  22. it 'has a replies collection with a first Page' do
  23. expect(subject['replies']['first']['type']).to eql('CollectionPage')
  24. end
  25. it 'includes public self-replies in its replies collection' do
  26. expect(subject['replies']['first']['items']).to include(reply_by_account_first.uri, reply_by_account_next.uri, reply_by_account_third.uri)
  27. end
  28. it 'does not include replies from others in its replies collection' do
  29. expect(subject['replies']['first']['items']).to_not include(reply_by_other_first.uri)
  30. end
  31. it 'does not include replies with direct visibility in its replies collection' do
  32. expect(subject['replies']['first']['items']).to_not include(reply_by_account_visibility_direct.uri)
  33. end
  34. end