status_parser_spec.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe ActivityPub::Parser::StatusParser do
  4. subject { described_class.new(json) }
  5. let(:sender) { Fabricate(:account, followers_url: 'http://example.com/followers', domain: 'example.com', uri: 'https://example.com/actor') }
  6. let(:follower) { Fabricate(:account, username: 'bob') }
  7. let(:json) do
  8. {
  9. '@context': 'https://www.w3.org/ns/activitystreams',
  10. id: [ActivityPub::TagManager.instance.uri_for(sender), '#foo'].join,
  11. type: 'Create',
  12. actor: ActivityPub::TagManager.instance.uri_for(sender),
  13. object: object_json,
  14. }.with_indifferent_access
  15. end
  16. let(:object_json) do
  17. {
  18. id: [ActivityPub::TagManager.instance.uri_for(sender), 'post1'].join('/'),
  19. type: 'Note',
  20. to: [
  21. 'https://www.w3.org/ns/activitystreams#Public',
  22. ActivityPub::TagManager.instance.uri_for(follower),
  23. ],
  24. content: '@bob lorem ipsum',
  25. contentMap: {
  26. EN: '@bob lorem ipsum',
  27. },
  28. published: 1.hour.ago.utc.iso8601,
  29. updated: 1.hour.ago.utc.iso8601,
  30. tag: {
  31. type: 'Mention',
  32. href: ActivityPub::TagManager.instance.uri_for(follower),
  33. },
  34. }
  35. end
  36. it 'correctly parses status' do
  37. expect(subject).to have_attributes(
  38. text: '@bob lorem ipsum',
  39. uri: [ActivityPub::TagManager.instance.uri_for(sender), 'post1'].join('/'),
  40. reply: false,
  41. language: :en
  42. )
  43. end
  44. end