update_spec.rb 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. require 'rails_helper'
  2. RSpec.describe ActivityPub::Activity::Update do
  3. let!(:sender) { Fabricate(:account) }
  4. before do
  5. sender.update!(uri: ActivityPub::TagManager.instance.uri_for(sender))
  6. end
  7. subject { described_class.new(json, sender) }
  8. describe '#perform' do
  9. context 'with an Actor object' do
  10. let(:modified_sender) do
  11. sender.tap do |modified_sender|
  12. modified_sender.display_name = 'Totally modified now'
  13. end
  14. end
  15. let(:actor_json) do
  16. ActiveModelSerializers::SerializableResource.new(modified_sender, serializer: ActivityPub::ActorSerializer, adapter: ActivityPub::Adapter).as_json
  17. end
  18. let(:json) do
  19. {
  20. '@context': 'https://www.w3.org/ns/activitystreams',
  21. id: 'foo',
  22. type: 'Update',
  23. actor: ActivityPub::TagManager.instance.uri_for(sender),
  24. object: actor_json,
  25. }.with_indifferent_access
  26. end
  27. before do
  28. stub_request(:get, actor_json[:outbox]).to_return(status: 404)
  29. stub_request(:get, actor_json[:followers]).to_return(status: 404)
  30. stub_request(:get, actor_json[:following]).to_return(status: 404)
  31. stub_request(:get, actor_json[:featured]).to_return(status: 404)
  32. subject.perform
  33. end
  34. it 'updates profile' do
  35. expect(sender.reload.display_name).to eq 'Totally modified now'
  36. end
  37. end
  38. context 'with a Question object' do
  39. let!(:at_time) { Time.now.utc }
  40. let!(:status) { Fabricate(:status, account: sender, poll: Poll.new(account: sender, options: %w(Bar Baz), cached_tallies: [0, 0], expires_at: at_time + 5.days)) }
  41. let(:json) do
  42. {
  43. '@context': 'https://www.w3.org/ns/activitystreams',
  44. id: 'foo',
  45. type: 'Update',
  46. actor: ActivityPub::TagManager.instance.uri_for(sender),
  47. object: {
  48. type: 'Question',
  49. id: ActivityPub::TagManager.instance.uri_for(status),
  50. content: 'Foo',
  51. endTime: (at_time + 5.days).iso8601,
  52. oneOf: [
  53. {
  54. type: 'Note',
  55. name: 'Bar',
  56. replies: {
  57. type: 'Collection',
  58. totalItems: 0,
  59. },
  60. },
  61. {
  62. type: 'Note',
  63. name: 'Baz',
  64. replies: {
  65. type: 'Collection',
  66. totalItems: 12,
  67. },
  68. },
  69. ],
  70. },
  71. }.with_indifferent_access
  72. end
  73. before do
  74. status.update!(uri: ActivityPub::TagManager.instance.uri_for(status))
  75. subject.perform
  76. end
  77. it 'updates poll numbers' do
  78. expect(status.preloadable_poll.cached_tallies).to eq [0, 12]
  79. end
  80. it 'does not set status as edited' do
  81. expect(status.edited_at).to be_nil
  82. end
  83. end
  84. end
  85. end