about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/api/v1/statuses_controller_spec.rb33
-rw-r--r--spec/fabricators/conversation_mute_fabricator.rb2
-rw-r--r--spec/models/conversation_mute_spec.rb5
-rw-r--r--spec/models/status_spec.rb48
-rw-r--r--spec/services/notify_service_spec.rb42
5 files changed, 129 insertions, 1 deletions
diff --git a/spec/controllers/api/v1/statuses_controller_spec.rb b/spec/controllers/api/v1/statuses_controller_spec.rb
index 74faed269..ac3b2dc7d 100644
--- a/spec/controllers/api/v1/statuses_controller_spec.rb
+++ b/spec/controllers/api/v1/statuses_controller_spec.rb
@@ -183,6 +183,39 @@ RSpec.describe Api::V1::StatusesController, type: :controller do
         expect(user.account.favourited?(status)).to be false
       end
     end
+
+    describe 'POST #mute' do
+      let(:status) { Fabricate(:status, account: user.account) }
+
+      before do
+        post :mute, params: { id: status.id }
+      end
+
+      it 'returns http success' do
+        expect(response).to have_http_status(:success)
+      end
+
+      it 'creates a conversation mute' do
+        expect(ConversationMute.find_by(account: user.account, conversation_id: status.conversation_id)).to_not be_nil
+      end
+    end
+
+    describe 'POST #unmute' do
+      let(:status) { Fabricate(:status, account: user.account) }
+
+      before do
+        post :mute,   params: { id: status.id }
+        post :unmute, params: { id: status.id }
+      end
+
+      it 'returns http success' do
+        expect(response).to have_http_status(:success)
+      end
+
+      it 'destroys the conversation mute' do
+        expect(ConversationMute.find_by(account: user.account, conversation_id: status.conversation_id)).to be_nil
+      end
+    end
   end
 
   context 'without an oauth token' do
diff --git a/spec/fabricators/conversation_mute_fabricator.rb b/spec/fabricators/conversation_mute_fabricator.rb
new file mode 100644
index 000000000..84f131c26
--- /dev/null
+++ b/spec/fabricators/conversation_mute_fabricator.rb
@@ -0,0 +1,2 @@
+Fabricator(:conversation_mute) do
+end
diff --git a/spec/models/conversation_mute_spec.rb b/spec/models/conversation_mute_spec.rb
new file mode 100644
index 000000000..b602e80c1
--- /dev/null
+++ b/spec/models/conversation_mute_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe ConversationMute, type: :model do
+
+end
diff --git a/spec/models/status_spec.rb b/spec/models/status_spec.rb
index f9f5c1603..d280525fc 100644
--- a/spec/models/status_spec.rb
+++ b/spec/models/status_spec.rb
@@ -196,6 +196,54 @@ RSpec.describe Status, type: :model do
     pending
   end
 
+  describe '.mutes_map' do
+    let(:status)  { Fabricate(:status) }
+    let(:account) { Fabricate(:account) }
+
+    subject { Status.mutes_map([status.conversation.id], account) }
+
+    it 'returns a hash' do
+      expect(subject).to be_a Hash
+    end
+
+    it 'contains true value' do
+      account.mute_conversation!(status.conversation)
+      expect(subject[status.conversation.id]).to be true
+    end
+  end
+
+  describe '.favourites_map' do
+    let(:status)  { Fabricate(:status) }
+    let(:account) { Fabricate(:account) }
+
+    subject { Status.favourites_map([status], account) }
+
+    it 'returns a hash' do
+      expect(subject).to be_a Hash
+    end
+
+    it 'contains true value' do
+      Fabricate(:favourite, status: status, account: account)
+      expect(subject[status.id]).to be true
+    end
+  end
+
+  describe '.reblogs_map' do
+    let(:status)  { Fabricate(:status) }
+    let(:account) { Fabricate(:account) }
+
+    subject { Status.reblogs_map([status], account) }
+
+    it 'returns a hash' do
+      expect(subject).to be_a Hash
+    end
+
+    it 'contains true value' do
+      Fabricate(:status, account: account, reblog: status)
+      expect(subject[status.id]).to be true
+    end
+  end
+
   describe '.local_only' do
     it 'returns only statuses from local accounts' do
       local_account = Fabricate(:account, domain: nil)
diff --git a/spec/services/notify_service_spec.rb b/spec/services/notify_service_spec.rb
index 86848e1ff..032c37a28 100644
--- a/spec/services/notify_service_spec.rb
+++ b/spec/services/notify_service_spec.rb
@@ -7,10 +7,50 @@ RSpec.describe NotifyService do
 
   let(:user) { Fabricate(:user) }
   let(:recipient) { user.account }
-  let(:activity) { Fabricate(:follow, target_account: recipient) }
+  let(:sender) { Fabricate(:account) }
+  let(:activity) { Fabricate(:follow, account: sender, target_account: recipient) }
 
   it { is_expected.to change(Notification, :count).by(1) }
 
+  it 'does not notify when sender is blocked' do
+    recipient.block!(sender)
+    is_expected.to_not change(Notification, :count)
+  end
+
+  it 'does not notify when sender is silenced and not followed' do
+    sender.update(silenced: true)
+    is_expected.to_not change(Notification, :count)
+  end
+
+  it 'does not notify when recipient is suspended' do
+    recipient.update(suspended: true)
+    is_expected.to_not change(Notification, :count)
+  end
+
+  context do
+    let(:asshole)  { Fabricate(:account, username: 'asshole') }
+    let(:reply_to) { Fabricate(:status, account: asshole) }
+    let(:activity) { Fabricate(:mention, account: recipient, status: Fabricate(:status, account: sender, thread: reply_to)) }
+
+    it 'does not notify when conversation is muted' do
+      recipient.mute_conversation!(activity.status.conversation)
+      is_expected.to_not change(Notification, :count)
+    end
+
+    it 'does not notify when it is a reply to a blocked user' do
+      recipient.block!(asshole)
+      is_expected.to_not change(Notification, :count)
+    end
+  end
+
+  context do
+    let(:sender) { recipient }
+
+    it 'does not notify when recipient is the sender' do
+      is_expected.to_not change(Notification, :count)
+    end
+  end
+
   describe 'email' do
     before do
       ActionMailer::Base.deliveries.clear