note_serializer_spec.rb 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe ActivityPub::NoteSerializer do
  4. subject { serialized_record_json(parent, described_class, adapter: ActivityPub::Adapter) }
  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. it 'has the expected shape and replies collection' do
  14. expect(subject).to include({
  15. '@context' => include('https://www.w3.org/ns/activitystreams'),
  16. 'type' => 'Note',
  17. 'attributedTo' => ActivityPub::TagManager.instance.uri_for(account),
  18. 'contentMap' => include({
  19. 'zh-TW' => a_kind_of(String),
  20. }),
  21. 'replies' => replies_collection_values,
  22. })
  23. end
  24. def replies_collection_values
  25. include(
  26. 'type' => eql('Collection'),
  27. 'first' => include(
  28. 'type' => eql('CollectionPage'),
  29. 'items' => reply_items
  30. )
  31. )
  32. end
  33. def reply_items
  34. include(reply_by_account_first.uri, reply_by_account_next.uri, reply_by_account_third.uri) # Public self replies
  35. .and(not_include(reply_by_other_first.uri)) # Replies from others
  36. .and(not_include(reply_by_account_visibility_direct.uri)) # Replies with direct visibility
  37. end
  38. end