about summary refs log tree commit diff
path: root/spec/lib/atom_serializer_spec.rb
blob: cfca82a284411a4609afc015e8bc55afb81807c2 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
require 'rails_helper'

RSpec.describe AtomSerializer do
  let(:author)   { Fabricate(:account, username: 'Sombra', display_name: '1337 haxxor') }
  let(:receiver) { Fabricate(:account, username: 'Symmetra') }

  before do
    stub_request(:get, "https://cb6e6126.ngrok.io/avatars/original/missing.png").to_return(status: 404)
    stub_request(:get, "https://cb6e6126.ngrok.io/headers/original/missing.png").to_return(status: 404)
  end

  describe '#author' do
    it 'returns dumpable XML with emojis' do
      account = Fabricate(:account, display_name: '💩')
      xml     = AtomSerializer.render(AtomSerializer.new.author(account))

      expect(xml).to be_a String
      expect(xml).to match(/<poco:displayName>💩<\/poco:displayName>/)
    end

    it 'returns dumpable XML with invalid characters like \b and \v' do
      account = Fabricate(:account, display_name: "im l33t\b haxo\b\vr")
      xml     = AtomSerializer.render(AtomSerializer.new.author(account))

      expect(xml).to be_a String
      expect(xml).to match(/<poco:displayName>im l33t haxor<\/poco:displayName>/)
    end
  end

  describe '#entry' do
    describe 'with deleted status' do
      let(:entry) do
        status = Fabricate(:status, account: author, text: 'boop')
        entry  = status.stream_entry
        status.destroy
        entry
      end

      it 'returns dumpable XML' do
        xml = AtomSerializer.render(AtomSerializer.new.entry(entry, true))
        expect(xml).to be_a String
        expect(xml).to match(/<id>#{TagManager.instance.unique_tag(entry.created_at, entry.activity_id, 'Status')}<\/id>/)
      end

      it 'triggers delete when processed' do
        status  = double(id: entry.activity_id)
        service = double

        allow(Status).to receive(:find_by).and_return(status)
        allow(RemoveStatusService).to receive(:new).and_return(service)
        allow(service).to receive(:call)

        xml = AtomSerializer.render(AtomSerializer.new.entry(entry, true))
        ProcessFeedService.new.call(xml, author)

        expect(service).to have_received(:call).with(status)
      end
    end

    describe 'with reblog of local user' do
      it 'returns dumpable XML'
      it 'creates a reblog'
    end

    describe 'with reblog of 3rd party user' do
      it 'returns dumpable XML'
      it 'creates a reblog with correct author'
    end
  end

  describe '#follow_salmon' do
    let(:xml) do
      follow = Fabricate(:follow, account: author, target_account: receiver)
      xml    = AtomSerializer.render(AtomSerializer.new.follow_salmon(follow))
      follow.destroy
      xml
    end

    it 'returns dumpable XML' do
      expect(xml).to be_a String
    end

    it 'triggers follow when processed' do
      envelope = OStatus2::Salmon.new.pack(xml, author.keypair)
      ProcessInteractionService.new.call(envelope, receiver)
      expect(author.following?(receiver)).to be true
    end
  end

  describe '#unfollow_salmon' do
    let(:xml) do
      follow = Fabricate(:follow, account: author, target_account: receiver)
      follow.destroy
      xml = AtomSerializer.render(AtomSerializer.new.unfollow_salmon(follow))
      author.follow!(receiver)
      xml
    end

    it 'returns dumpable XML' do
      expect(xml).to be_a String
    end

    it 'triggers unfollow when processed' do
      envelope = OStatus2::Salmon.new.pack(xml, author.keypair)
      ProcessInteractionService.new.call(envelope, receiver)
      expect(author.following?(receiver)).to be false
    end
  end

  describe '#favourite_salmon' do
    let(:status) { Fabricate(:status, account: receiver, text: 'Everything by design.') }

    let(:xml) do
      favourite = Fabricate(:favourite, account: author, status: status)
      xml       = AtomSerializer.render(AtomSerializer.new.favourite_salmon(favourite))
      favourite.destroy
      xml
    end

    it 'returns dumpable XML' do
      expect(xml).to be_a String
    end

    it 'triggers favourite when processed' do
      envelope = OStatus2::Salmon.new.pack(xml, author.keypair)
      ProcessInteractionService.new.call(envelope, receiver)
      expect(author.favourited?(status)).to be true
    end
  end

  describe '#unfavourite_salmon' do
    let(:status) { Fabricate(:status, account: receiver, text: 'Perfect harmony.') }

    let(:xml) do
      favourite = Fabricate(:favourite, account: author, status: status)
      favourite.destroy
      xml = AtomSerializer.render(AtomSerializer.new.unfavourite_salmon(favourite))
      Fabricate(:favourite, account: author, status: status)
      xml
    end

    it 'returns dumpable XML' do
      expect(xml).to be_a String
    end

    it 'triggers unfavourite when processed' do
      envelope = OStatus2::Salmon.new.pack(xml, author.keypair)
      ProcessInteractionService.new.call(envelope, receiver)
      expect(author.favourited?(status)).to be false
    end
  end

  describe '#block_salmon' do
    let(:xml) do
      block = Fabricate(:block, account: author, target_account: receiver)
      xml   = AtomSerializer.render(AtomSerializer.new.block_salmon(block))
      block.destroy
      xml
    end

    it 'returns dumpable XML' do
      expect(xml).to be_a String
    end

    it 'triggers block when processed' do
      envelope = OStatus2::Salmon.new.pack(xml, author.keypair)
      ProcessInteractionService.new.call(envelope, receiver)
      expect(author.blocking?(receiver)).to be true
    end
  end

  describe '#unblock_salmon' do
    let(:xml) do
      block = Fabricate(:block, account: author, target_account: receiver)
      block.destroy
      xml = AtomSerializer.render(AtomSerializer.new.unblock_salmon(block))
      author.block!(receiver)
      xml
    end

    it 'returns dumpable XML' do
      expect(xml).to be_a String
    end

    it 'triggers unblock when processed' do
      envelope = OStatus2::Salmon.new.pack(xml, author.keypair)
      ProcessInteractionService.new.call(envelope, receiver)
      expect(author.blocking?(receiver)).to be false
    end
  end

  describe '#follow_request_salmon' do
    it 'returns dumpable XML'
    it 'triggers follow request when processed'
  end

  describe '#authorize_follow_request_salmon' do
    it 'returns dumpable XML'
    it 'creates follow from follow request when processed'
  end

  describe '#reject_follow_request_salmon' do
    it 'returns dumpable XML'
    it 'deletes follow request when processed'
  end
end