mirror of
https://github.com/kikobar/mastodon.git
synced 2024-11-17 04:32:22 +00:00
Add more tests for AtomSerializer (#2096)
This commit is contained in:
parent
0d6c1e9cba
commit
6bd1019235
|
@ -1,6 +1,14 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe AtomSerializer do
|
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
|
describe '#author' do
|
||||||
it 'returns dumpable XML with emojis' do
|
it 'returns dumpable XML with emojis' do
|
||||||
account = Fabricate(:account, display_name: '💩')
|
account = Fabricate(:account, display_name: '💩')
|
||||||
|
@ -18,4 +26,181 @@ RSpec.describe AtomSerializer do
|
||||||
expect(xml).to match(/<poco:displayName>im l33t haxor<\/poco:displayName>/)
|
expect(xml).to match(/<poco:displayName>im l33t haxor<\/poco:displayName>/)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
@ -21,10 +21,6 @@ RSpec.configure do |config|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
config.before :each do
|
|
||||||
stub_request(:post, 'https://fcm.googleapis.com/fcm/send').to_return(status: 200, body: '')
|
|
||||||
end
|
|
||||||
|
|
||||||
config.after :suite do
|
config.after :suite do
|
||||||
FileUtils.rm_rf(Dir["#{Rails.root}/spec/test_files/"])
|
FileUtils.rm_rf(Dir["#{Rails.root}/spec/test_files/"])
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue