about summary refs log tree commit diff
path: root/spec/services
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/authorize_follow_service_spec.rb49
-rw-r--r--spec/services/block_service_spec.rb34
-rw-r--r--spec/services/favourite_service_spec.rb36
-rw-r--r--spec/services/follow_service_spec.rb72
-rw-r--r--spec/services/reject_follow_service_spec.rb49
-rw-r--r--spec/services/unblock_service_spec.rb36
-rw-r--r--spec/services/unfollow_service_spec.rb37
7 files changed, 308 insertions, 5 deletions
diff --git a/spec/services/authorize_follow_service_spec.rb b/spec/services/authorize_follow_service_spec.rb
new file mode 100644
index 000000000..3f3a2bc56
--- /dev/null
+++ b/spec/services/authorize_follow_service_spec.rb
@@ -0,0 +1,49 @@
+require 'rails_helper'
+
+RSpec.describe AuthorizeFollowService do
+  let(:sender) { Fabricate(:account, username: 'alice') }
+
+  subject { AuthorizeFollowService.new }
+
+  describe 'local' do
+    let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
+
+    before do
+      FollowRequest.create(account: bob, target_account: sender)
+      subject.call(bob, sender)
+    end
+
+    it 'removes follow request' do
+      expect(bob.requested?(sender)).to be false
+    end
+
+    it 'creates follow relation' do
+      expect(bob.following?(sender)).to be true
+    end
+  end
+
+  describe 'remote' do
+    let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', domain: 'example.com', salmon_url: 'http://salmon.example.com')).account }
+
+    before do
+      FollowRequest.create(account: bob, target_account: sender)
+      stub_request(:post, "http://salmon.example.com/").to_return(:status => 200, :body => "", :headers => {})
+      subject.call(bob, sender)
+    end
+
+    it 'removes follow request' do
+      expect(bob.requested?(sender)).to be false
+    end
+
+    it 'creates follow relation' do
+      expect(bob.following?(sender)).to be true
+    end
+
+    it 'sends a follow request authorization salmon slap' do
+      expect(a_request(:post, "http://salmon.example.com/").with { |req|
+        xml = OStatus2::Salmon.new.unpack(req.body)
+        xml.match(TagManager::VERBS[:authorize])
+      }).to have_been_made.once
+    end
+  end
+end
diff --git a/spec/services/block_service_spec.rb b/spec/services/block_service_spec.rb
index f6f07fa20..2a54e032e 100644
--- a/spec/services/block_service_spec.rb
+++ b/spec/services/block_service_spec.rb
@@ -1,5 +1,39 @@
 require 'rails_helper'
 
 RSpec.describe BlockService do
+  let(:sender) { Fabricate(:account, username: 'alice') }
+
   subject { BlockService.new }
+
+  describe 'local' do
+    let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
+
+    before do
+      subject.call(sender, bob)
+    end
+
+    it 'creates a blocking relation' do
+      expect(sender.blocking?(bob)).to be true
+    end
+  end
+
+  describe 'remote' do
+    let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', domain: 'example.com', salmon_url: 'http://salmon.example.com')).account }
+
+    before do
+      stub_request(:post, "http://salmon.example.com/").to_return(:status => 200, :body => "", :headers => {})
+      subject.call(sender, bob)
+    end
+
+    it 'creates a blocking relation' do
+      expect(sender.blocking?(bob)).to be true
+    end
+
+    it 'sends a block salmon slap' do
+      expect(a_request(:post, "http://salmon.example.com/").with { |req|
+        xml = OStatus2::Salmon.new.unpack(req.body)
+        xml.match(TagManager::VERBS[:block])
+      }).to have_been_made.once
+    end
+  end
 end
diff --git a/spec/services/favourite_service_spec.rb b/spec/services/favourite_service_spec.rb
index eb961c28e..36f1b64d4 100644
--- a/spec/services/favourite_service_spec.rb
+++ b/spec/services/favourite_service_spec.rb
@@ -1,5 +1,41 @@
 require 'rails_helper'
 
 RSpec.describe FavouriteService do
+  let(:sender) { Fabricate(:account, username: 'alice') }
+
   subject { FavouriteService.new }
+
+  describe 'local' do
+    let(:bob)    { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
+    let(:status) { Fabricate(:status, account: bob) }
+
+    before do
+      subject.call(sender, status)
+    end
+
+    it 'creates a favourite' do
+      expect(status.favourites.first).to_not be_nil
+    end
+  end
+
+  describe 'remote' do
+    let(:bob)    { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', domain: 'example.com', salmon_url: 'http://salmon.example.com')).account }
+    let(:status) { Fabricate(:status, account: bob, uri: 'tag:example.com:blahblah') }
+
+    before do
+      stub_request(:post, "http://salmon.example.com/").to_return(:status => 200, :body => "", :headers => {})
+      subject.call(sender, status)
+    end
+
+    it 'creates a favourite' do
+      expect(status.favourites.first).to_not be_nil
+    end
+
+    it 'sends a salmon slap' do
+      expect(a_request(:post, "http://salmon.example.com/").with { |req|
+        xml = OStatus2::Salmon.new.unpack(req.body)
+        xml.match(TagManager::VERBS[:favorite])
+      }).to have_been_made.once
+    end
+  end
 end
diff --git a/spec/services/follow_service_spec.rb b/spec/services/follow_service_spec.rb
index 304e0cf71..2ce0fa464 100644
--- a/spec/services/follow_service_spec.rb
+++ b/spec/services/follow_service_spec.rb
@@ -1,9 +1,75 @@
 require 'rails_helper'
 
 RSpec.describe FollowService do
+  let(:sender) { Fabricate(:account, username: 'alice') }
+
   subject { FollowService.new }
 
-  it 'creates a following relation'
-  it 'creates local account for remote user'
-  it 'sends follow to the remote user'
+  context 'local account' do
+    describe 'locked account' do
+      let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, locked: true, username: 'bob')).account }
+
+      before do
+        subject.call(sender, bob.acct)
+      end
+
+      it 'creates a follow request' do
+        expect(FollowRequest.find_by(account: sender, target_account: bob)).to_not be_nil
+      end
+    end
+
+    describe 'unlocked account' do
+      let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
+
+      before do
+        subject.call(sender, bob.acct)
+      end
+
+      it 'creates a following relation' do
+        expect(sender.following?(bob)).to be true
+      end
+    end
+  end
+
+  context 'remote account' do
+    describe 'locked account' do
+      let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, locked: true, username: 'bob', domain: 'example.com', salmon_url: 'http://salmon.example.com')).account }
+
+      before do
+        stub_request(:post, "http://salmon.example.com/").to_return(:status => 200, :body => "", :headers => {})
+        subject.call(sender, bob.acct)
+      end
+
+      it 'creates a follow request' do
+        expect(FollowRequest.find_by(account: sender, target_account: bob)).to_not be_nil
+      end
+
+      it 'sends a follow request salmon slap' do
+        expect(a_request(:post, "http://salmon.example.com/").with { |req|
+          xml = OStatus2::Salmon.new.unpack(req.body)
+          xml.match(TagManager::VERBS[:request_friend])
+        }).to have_been_made.once
+      end
+    end
+
+    describe 'unlocked account' do
+      let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', domain: 'example.com', salmon_url: 'http://salmon.example.com')).account }
+
+      before do
+        stub_request(:post, "http://salmon.example.com/").to_return(:status => 200, :body => "", :headers => {})
+        subject.call(sender, bob.acct)
+      end
+
+      it 'creates a following relation' do
+        expect(sender.following?(bob)).to be true
+      end
+
+      it 'sends a follow salmon slap' do
+        expect(a_request(:post, "http://salmon.example.com/").with { |req|
+          xml = OStatus2::Salmon.new.unpack(req.body)
+          xml.match(TagManager::VERBS[:follow])
+        }).to have_been_made.once
+      end
+    end
+  end
 end
diff --git a/spec/services/reject_follow_service_spec.rb b/spec/services/reject_follow_service_spec.rb
new file mode 100644
index 000000000..50749b633
--- /dev/null
+++ b/spec/services/reject_follow_service_spec.rb
@@ -0,0 +1,49 @@
+require 'rails_helper'
+
+RSpec.describe RejectFollowService do
+  let(:sender) { Fabricate(:account, username: 'alice') }
+
+  subject { RejectFollowService.new }
+
+  describe 'local' do
+    let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
+
+    before do
+      FollowRequest.create(account: bob, target_account: sender)
+      subject.call(bob, sender)
+    end
+
+    it 'removes follow request' do
+      expect(bob.requested?(sender)).to be false
+    end
+
+    it 'does not create follow relation' do
+      expect(bob.following?(sender)).to be false
+    end
+  end
+
+  describe 'remote' do
+    let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', domain: 'example.com', salmon_url: 'http://salmon.example.com')).account }
+
+    before do
+      FollowRequest.create(account: bob, target_account: sender)
+      stub_request(:post, "http://salmon.example.com/").to_return(:status => 200, :body => "", :headers => {})
+      subject.call(bob, sender)
+    end
+
+    it 'removes follow request' do
+      expect(bob.requested?(sender)).to be false
+    end
+
+    it 'does not create follow relation' do
+      expect(bob.following?(sender)).to be false
+    end
+
+    it 'sends a follow request rejection salmon slap' do
+      expect(a_request(:post, "http://salmon.example.com/").with { |req|
+        xml = OStatus2::Salmon.new.unpack(req.body)
+        xml.match(TagManager::VERBS[:reject])
+      }).to have_been_made.once
+    end
+  end
+end
diff --git a/spec/services/unblock_service_spec.rb b/spec/services/unblock_service_spec.rb
index 126f70ff1..1b9ae1239 100644
--- a/spec/services/unblock_service_spec.rb
+++ b/spec/services/unblock_service_spec.rb
@@ -1,5 +1,41 @@
 require 'rails_helper'
 
 RSpec.describe UnblockService do
+  let(:sender) { Fabricate(:account, username: 'alice') }
+
   subject { UnblockService.new }
+
+  describe 'local' do
+    let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
+
+    before do
+      sender.block!(bob)
+      subject.call(sender, bob)
+    end
+
+    it 'destroys the blocking relation' do
+      expect(sender.blocking?(bob)).to be false
+    end
+  end
+
+  describe 'remote' do
+    let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', domain: 'example.com', salmon_url: 'http://salmon.example.com')).account }
+
+    before do
+      sender.block!(bob)
+      stub_request(:post, "http://salmon.example.com/").to_return(:status => 200, :body => "", :headers => {})
+      subject.call(sender, bob)
+    end
+
+    it 'destroys the blocking relation' do
+      expect(sender.following?(bob)).to be false
+    end
+
+    it 'sends an unblock salmon slap' do
+      expect(a_request(:post, "http://salmon.example.com/").with { |req|
+        xml = OStatus2::Salmon.new.unpack(req.body)
+        xml.match(TagManager::VERBS[:unblock])
+      }).to have_been_made.once
+    end
+  end
 end
diff --git a/spec/services/unfollow_service_spec.rb b/spec/services/unfollow_service_spec.rb
index 6541415d0..8ec2148a1 100644
--- a/spec/services/unfollow_service_spec.rb
+++ b/spec/services/unfollow_service_spec.rb
@@ -1,8 +1,41 @@
 require 'rails_helper'
 
 RSpec.describe UnfollowService do
+  let(:sender) { Fabricate(:account, username: 'alice') }
+
   subject { UnfollowService.new }
 
-  it 'destroys the following relation'
-  it 'sends remote interaction for remote user'
+  describe 'local' do
+    let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
+
+    before do
+      sender.follow!(bob)
+      subject.call(sender, bob)
+    end
+
+    it 'destroys the following relation' do
+      expect(sender.following?(bob)).to be false
+    end
+  end
+
+  describe 'remote' do
+    let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', domain: 'example.com', salmon_url: 'http://salmon.example.com')).account }
+
+    before do
+      sender.follow!(bob)
+      stub_request(:post, "http://salmon.example.com/").to_return(:status => 200, :body => "", :headers => {})
+      subject.call(sender, bob)
+    end
+
+    it 'destroys the following relation' do
+      expect(sender.following?(bob)).to be false
+    end
+
+    it 'sends an unfollow salmon slap' do
+      expect(a_request(:post, "http://salmon.example.com/").with { |req|
+        xml = OStatus2::Salmon.new.unpack(req.body)
+        xml.match(TagManager::VERBS[:unfollow])
+      }).to have_been_made.once
+    end
+  end
 end