about summary refs log tree commit diff
path: root/spec/lib/activitypub/activity/announce_spec.rb
blob: 1725c2843bb7ea6dae856349d37bc0b593188edb (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
require 'rails_helper'

RSpec.describe ActivityPub::Activity::Announce do
  let(:sender)    { Fabricate(:account, followers_url: 'http://example.com/followers') }
  let(:recipient) { Fabricate(:account) }
  let(:status)    { Fabricate(:status, account: recipient) }

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

  subject { described_class.new(json, sender) }

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

  describe '#perform' do
    before do
      subject.perform
    end

    context 'a known status' do
      let(:object_json) do
        ActivityPub::TagManager.instance.uri_for(status)
      end

      it 'creates a reblog by sender of status' do
        expect(sender.reblogged?(status)).to be true
      end
    end

    context 'self-boost of a previously unknown status with missing attributedTo' do
      let(:object_json) do
        {
          id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
          type: 'Note',
          content: 'Lorem ipsum',
          to: 'http://example.com/followers',
        }
      end

      it 'creates a reblog by sender of status' do
        expect(sender.reblogged?(sender.statuses.first)).to be true
      end
    end

    context 'self-boost of a previously unknown status with correct attributedTo' do
      let(:object_json) do
        {
          id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
          type: 'Note',
          content: 'Lorem ipsum',
          attributedTo: ActivityPub::TagManager.instance.uri_for(sender),
          to: 'http://example.com/followers',
        }
      end

      it 'creates a reblog by sender of status' do
        expect(sender.reblogged?(sender.statuses.first)).to be true
      end
    end
  end
end