note_serializer_spec.rb 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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, language: 'zh-TW') }
  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 the expected shape' do
  17. expect(subject).to include({
  18. '@context' => include('https://www.w3.org/ns/activitystreams'),
  19. 'type' => 'Note',
  20. 'attributedTo' => ActivityPub::TagManager.instance.uri_for(account),
  21. 'contentMap' => include({
  22. 'zh-TW' => a_kind_of(String),
  23. }),
  24. })
  25. end
  26. it 'has a replies collection' do
  27. expect(subject['replies']['type']).to eql('Collection')
  28. end
  29. it 'has a replies collection with a first Page' do
  30. expect(subject['replies']['first']['type']).to eql('CollectionPage')
  31. end
  32. it 'includes public self-replies in its replies collection' do
  33. expect(subject['replies']['first']['items']).to include(reply_by_account_first.uri, reply_by_account_next.uri, reply_by_account_third.uri)
  34. end
  35. it 'does not include replies from others in its replies collection' do
  36. expect(subject['replies']['first']['items']).to_not include(reply_by_other_first.uri)
  37. end
  38. it 'does not include replies with direct visibility in its replies collection' do
  39. expect(subject['replies']['first']['items']).to_not include(reply_by_account_visibility_direct.uri)
  40. end
  41. end