about summary refs log tree commit diff
path: root/spec/lib/activitypub/activity/update_spec.rb
blob: fbfc585cf9736ce991dd4b3c071f7f25c101358d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require 'rails_helper'

RSpec.describe ActivityPub::Activity::Update do
  let!(:sender) { Fabricate(:account) }

  before do
    stub_request(:get, actor_json[:outbox]).to_return(status: 404)
    stub_request(:get, actor_json[:followers]).to_return(status: 404)
    stub_request(:get, actor_json[:following]).to_return(status: 404)
    stub_request(:get, actor_json[:featured]).to_return(status: 404)

    sender.update!(uri: ActivityPub::TagManager.instance.uri_for(sender))
  end

  let(:modified_sender) do
    sender.dup.tap do |modified_sender|
      modified_sender.display_name = 'Totally modified now'
    end
  end

  let(:actor_json) do
    ActiveModelSerializers::SerializableResource.new(modified_sender, serializer: ActivityPub::ActorSerializer, key_transform: :camel_lower).as_json
  end

  let(:json) do
    {
      '@context': 'https://www.w3.org/ns/activitystreams',
      id: 'foo',
      type: 'Update',
      actor: ActivityPub::TagManager.instance.uri_for(sender),
      object: actor_json,
    }.with_indifferent_access
  end

  describe '#perform' do
    subject { described_class.new(json, sender) }

    before do
      subject.perform
    end

    it 'updates profile' do
      expect(sender.reload.display_name).to eq 'Totally modified now'
    end
  end
end