about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-02-12 00:48:53 +0100
committerEugen Rochko <eugen@zeonfederated.com>2017-02-12 01:19:14 +0100
commit0518492158af247f3b99a8f27f4498d1bcc91117 (patch)
tree4e82d1e73bd9a8ac1096d788b684283c8f8c93dd /spec
parent94d21827174c52a6b70ba2e45f098223f5d904fa (diff)
Stop trying to shoehorn all Salmon updates into the poor database-connected
StreamEntry model. Simply render Salmon slaps as they are needed
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/tag_manager_spec.rb32
-rw-r--r--spec/models/favourite_spec.rb36
-rw-r--r--spec/models/follow_spec.rb30
-rw-r--r--spec/models/stream_entry_spec.rb14
-rw-r--r--spec/services/process_interaction_service_spec.rb96
5 files changed, 87 insertions, 121 deletions
diff --git a/spec/lib/tag_manager_spec.rb b/spec/lib/tag_manager_spec.rb
index b60584253..cbb427a8c 100644
--- a/spec/lib/tag_manager_spec.rb
+++ b/spec/lib/tag_manager_spec.rb
@@ -47,22 +47,6 @@ RSpec.describe TagManager do
         expect(subject).to be_a String
       end
     end
-
-    context 'Follow' do
-      let(:target) { Fabricate(:follow, account: alice, target_account: bob) }
-
-      it 'returns a string' do
-        expect(subject).to be_a String
-      end
-    end
-
-    context 'Favourite' do
-      let(:target) { Fabricate(:favourite, account: bob, status: status) }
-
-      it 'returns a string' do
-        expect(subject).to be_a String
-      end
-    end
   end
 
   describe '#url_for' do
@@ -87,21 +71,5 @@ RSpec.describe TagManager do
         expect(subject).to be_a String
       end
     end
-
-    context 'Follow' do
-      let(:target) { Fabricate(:follow, account: alice, target_account: bob) }
-
-      it 'returns a URL' do
-        expect(subject).to be_a String
-      end
-    end
-
-    context 'Favourite' do
-      let(:target) { Fabricate(:favourite, account: bob, status: status) }
-
-      it 'returns a URL' do
-        expect(subject).to be_a String
-      end
-    end
   end
 end
diff --git a/spec/models/favourite_spec.rb b/spec/models/favourite_spec.rb
index cc3d604d6..5b7126506 100644
--- a/spec/models/favourite_spec.rb
+++ b/spec/models/favourite_spec.rb
@@ -6,40 +6,4 @@ RSpec.describe Favourite, type: :model do
   let(:status) { Fabricate(:status, account: bob) }
 
   subject { Favourite.new(account: alice, status: status) }
-
-  describe '#verb' do
-    it 'is always favorite' do
-      expect(subject.verb).to be :favorite
-    end
-  end
-
-  describe '#title' do
-    it 'describes the favourite' do
-      expect(subject.title).to eql 'alice favourited a status by bob'
-    end
-  end
-
-  describe '#content' do
-    it 'equals the title' do
-      expect(subject.content).to eq subject.title
-    end
-  end
-
-  describe '#object_type' do
-    it 'is an activity' do
-      expect(subject.object_type).to be :activity
-    end
-  end
-
-  describe '#target' do
-    it 'is the status that was favourited' do
-      expect(subject.target).to eq status
-    end
-  end
-
-  describe '#thread' do
-    it 'equals the target' do
-      expect(subject.thread).to eq subject.target
-    end
-  end
 end
diff --git a/spec/models/follow_spec.rb b/spec/models/follow_spec.rb
index bc887b60d..eb21f3e18 100644
--- a/spec/models/follow_spec.rb
+++ b/spec/models/follow_spec.rb
@@ -5,34 +5,4 @@ RSpec.describe Follow, type: :model do
   let(:bob)   { Fabricate(:account, username: 'bob') }
 
   subject { Follow.new(account: alice, target_account: bob) }
-
-  describe '#verb' do
-    it 'is follow' do
-      expect(subject.verb).to be :follow
-    end
-  end
-
-  describe '#title' do
-    it 'describes the follow' do
-      expect(subject.title).to eql 'alice started following bob'
-    end
-  end
-
-  describe '#content' do
-    it 'is the same as the title' do
-      expect(subject.content).to eql subject.title
-    end
-  end
-
-  describe '#object_type' do
-    it 'is an activity' do
-      expect(subject.object_type).to be :activity
-    end
-  end
-
-  describe '#target' do
-    it 'is the person being followed' do
-      expect(subject.target).to eq bob
-    end
-  end
 end
diff --git a/spec/models/stream_entry_spec.rb b/spec/models/stream_entry_spec.rb
index 9ecf6412a..45bf26899 100644
--- a/spec/models/stream_entry_spec.rb
+++ b/spec/models/stream_entry_spec.rb
@@ -3,21 +3,11 @@ require 'rails_helper'
 RSpec.describe StreamEntry, type: :model do
   let(:alice)     { Fabricate(:account, username: 'alice') }
   let(:bob)       { Fabricate(:account, username: 'bob') }
-  let(:follow)    { Fabricate(:follow, account: alice, target_account: bob) }
   let(:status)    { Fabricate(:status, account: alice) }
   let(:reblog)    { Fabricate(:status, account: bob, reblog: status) }
   let(:reply)     { Fabricate(:status, account: bob, thread: status) }
-  let(:favourite) { Fabricate(:favourite, account: alice, status: status) }
 
   describe '#targeted?' do
-    it 'returns true for a follow' do
-      expect(follow.stream_entry.targeted?).to be true
-    end
-
-    it 'returns true for a favourite' do
-      expect(favourite.stream_entry.targeted?).to be true
-    end
-
     it 'returns true for a reblog' do
       expect(reblog.stream_entry.targeted?).to be true
     end
@@ -28,10 +18,6 @@ RSpec.describe StreamEntry, type: :model do
   end
 
   describe '#threaded?' do
-    it 'returns true for a favourite' do
-      expect(favourite.stream_entry.threaded?).to be true
-    end
-
     it 'returns true for a reply' do
       expect(reply.stream_entry.threaded?).to be true
     end
diff --git a/spec/services/process_interaction_service_spec.rb b/spec/services/process_interaction_service_spec.rb
index 931815dc2..0845e09ed 100644
--- a/spec/services/process_interaction_service_spec.rb
+++ b/spec/services/process_interaction_service_spec.rb
@@ -1,15 +1,93 @@
 require 'rails_helper'
 
 RSpec.describe ProcessInteractionService do
+  let(:receiver) { Fabricate(:user, email: 'alice@example.com', account: Fabricate(:account, username: 'alice')).account }
+  let(:sender)   { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
+
   subject { ProcessInteractionService.new }
 
-  it 'creates account for new remote user'
-  it 'updates account for existing remote user'
-  it 'ignores envelopes that do not address the local user'
-  it 'accepts a status that mentions the local user'
-  it 'accepts a status that is a reply to the local user\'s'
-  it 'accepts a favourite to a status by the local user'
-  it 'accepts a reblog of a status of the local user'
-  it 'accepts a follow of the local user'
-  it 'accepts an unfollow of the local user'
+  describe 'follow request slap' do
+    before do
+      receiver.update(locked: true)
+
+      payload = <<XML
+<entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
+  <author>
+    <name>bob</name>
+    <uri>https://cb6e6126.ngrok.io/users/bob</uri>
+  </author>
+
+  <id>someIdHere</id>
+  <activity:verb>http://activitystrea.ms/schema/1.0/request-friend</activity:verb>
+</entry>
+XML
+
+      envelope = OStatus2::Salmon.new.pack(payload, sender.keypair)
+      subject.call(envelope, receiver)
+    end
+
+    it 'creates a record' do
+      expect(FollowRequest.find_by(account: sender, target_account: receiver)).to_not be_nil
+    end
+  end
+
+  describe 'follow request authorization slap' do
+    before do
+      receiver.update(locked: true)
+      FollowRequest.create(account: sender, target_account: receiver)
+
+      payload = <<XML
+<entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
+  <author>
+    <name>alice</name>
+    <uri>https://cb6e6126.ngrok.io/users/alice</uri>
+  </author>
+
+  <id>someIdHere</id>
+  <activity:verb>http://activitystrea.ms/schema/1.0/authorize</activity:verb>
+</entry>
+XML
+
+      envelope = OStatus2::Salmon.new.pack(payload, receiver.keypair)
+      subject.call(envelope, sender)
+    end
+
+    it 'creates a follow relationship' do
+      expect(Follow.find_by(account: sender, target_account: receiver)).to_not be_nil
+    end
+
+    it 'removes the follow request' do
+      expect(FollowRequest.find_by(account: sender, target_account: receiver)).to be_nil
+    end
+  end
+
+  describe 'follow request rejection slap' do
+    before do
+      receiver.update(locked: true)
+      FollowRequest.create(account: sender, target_account: receiver)
+
+      payload = <<XML
+<entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
+  <author>
+    <name>alice</name>
+    <uri>https://cb6e6126.ngrok.io/users/alice</uri>
+  </author>
+
+  <id>someIdHere</id>
+  <activity:verb>http://activitystrea.ms/schema/1.0/reject</activity:verb>
+</entry>
+XML
+
+      envelope = OStatus2::Salmon.new.pack(payload, receiver.keypair)
+      subject.call(envelope, sender)
+    end
+
+    it 'does not create a follow relationship' do
+      expect(Follow.find_by(account: sender, target_account: receiver)).to be_nil
+    end
+
+    it 'removes the follow request' do
+      expect(FollowRequest.find_by(account: sender, target_account: receiver)).to be_nil
+    end
+  end
 end