about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEugen <eugen@zeonfederated.com>2017-04-18 22:30:17 +0200
committerGitHub <noreply@github.com>2017-04-18 22:30:17 +0200
commit6bd101923567a7302c2b734317791f941ce53cdf (patch)
tree93a07c78ed4037cafd202e2755b71d1d9c78c5f9
parent0d6c1e9cbae70276b1b0d545b587edb2bdf08562 (diff)
Add more tests for AtomSerializer (#2096)
-rw-r--r--spec/lib/atom_serializer_spec.rb185
-rw-r--r--spec/spec_helper.rb4
2 files changed, 185 insertions, 4 deletions
diff --git a/spec/lib/atom_serializer_spec.rb b/spec/lib/atom_serializer_spec.rb
index 0009e41a9..cfca82a28 100644
--- a/spec/lib/atom_serializer_spec.rb
+++ b/spec/lib/atom_serializer_spec.rb
@@ -1,6 +1,14 @@
 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: '💩')
@@ -18,4 +26,181 @@ RSpec.describe AtomSerializer do
       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
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index aa180a387..2bc462121 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -21,10 +21,6 @@ RSpec.configure do |config|
     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
     FileUtils.rm_rf(Dir["#{Rails.root}/spec/test_files/"])
   end