update_spec.rb 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe ActivityPub::Activity::Update do
  4. subject { described_class.new(json, sender) }
  5. let!(:sender) { Fabricate(:account, domain: 'example.com', inbox_url: 'https://example.com/foo/inbox', outbox_url: 'https://example.com/foo/outbox') }
  6. describe '#perform' do
  7. context 'with an Actor object' do
  8. let(:actor_json) do
  9. {
  10. '@context': [
  11. 'https://www.w3.org/ns/activitystreams',
  12. 'https://w3id.org/security/v1',
  13. {
  14. manuallyApprovesFollowers: 'as:manuallyApprovesFollowers',
  15. toot: 'http://joinmastodon.org/ns#',
  16. featured: { '@id': 'toot:featured', '@type': '@id' },
  17. featuredTags: { '@id': 'toot:featuredTags', '@type': '@id' },
  18. },
  19. ],
  20. id: sender.uri,
  21. type: 'Person',
  22. following: 'https://example.com/users/dfsdf/following',
  23. followers: 'https://example.com/users/dfsdf/followers',
  24. inbox: sender.inbox_url,
  25. outbox: sender.outbox_url,
  26. featured: 'https://example.com/users/dfsdf/featured',
  27. featuredTags: 'https://example.com/users/dfsdf/tags',
  28. preferredUsername: sender.username,
  29. name: 'Totally modified now',
  30. publicKey: {
  31. id: "#{sender.uri}#main-key",
  32. owner: sender.uri,
  33. publicKeyPem: sender.public_key,
  34. },
  35. }
  36. end
  37. let(:json) do
  38. {
  39. '@context': 'https://www.w3.org/ns/activitystreams',
  40. id: 'foo',
  41. type: 'Update',
  42. actor: sender.uri,
  43. object: actor_json,
  44. }.with_indifferent_access
  45. end
  46. before do
  47. stub_request(:get, actor_json[:outbox]).to_return(status: 404)
  48. stub_request(:get, actor_json[:followers]).to_return(status: 404)
  49. stub_request(:get, actor_json[:following]).to_return(status: 404)
  50. stub_request(:get, actor_json[:featured]).to_return(status: 404)
  51. stub_request(:get, actor_json[:featuredTags]).to_return(status: 404)
  52. subject.perform
  53. end
  54. it 'updates profile' do
  55. expect(sender.reload.display_name).to eq 'Totally modified now'
  56. end
  57. end
  58. context 'with a Question object' do
  59. let!(:at_time) { Time.now.utc }
  60. let!(:status) { Fabricate(:status, uri: 'https://example.com/statuses/poll', account: sender, poll: Poll.new(account: sender, options: %w(Bar Baz), cached_tallies: [0, 0], expires_at: at_time + 5.days)) }
  61. let(:json) do
  62. {
  63. '@context': 'https://www.w3.org/ns/activitystreams',
  64. id: 'foo',
  65. type: 'Update',
  66. actor: sender.uri,
  67. object: {
  68. type: 'Question',
  69. id: status.uri,
  70. content: 'Foo',
  71. endTime: (at_time + 5.days).iso8601,
  72. oneOf: [
  73. {
  74. type: 'Note',
  75. name: 'Bar',
  76. replies: {
  77. type: 'Collection',
  78. totalItems: 0,
  79. },
  80. },
  81. {
  82. type: 'Note',
  83. name: 'Baz',
  84. replies: {
  85. type: 'Collection',
  86. totalItems: 12,
  87. },
  88. },
  89. ],
  90. },
  91. }.with_indifferent_access
  92. end
  93. before do
  94. status.update!(uri: ActivityPub::TagManager.instance.uri_for(status))
  95. subject.perform
  96. end
  97. it 'updates poll numbers' do
  98. expect(status.preloadable_poll.cached_tallies).to eq [0, 12]
  99. end
  100. it 'does not set status as edited' do
  101. expect(status.edited_at).to be_nil
  102. end
  103. end
  104. end
  105. end