about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2022-03-15 04:11:29 +0100
committerGitHub <noreply@github.com>2022-03-15 04:11:29 +0100
commite6ffbfb5e7684880e9252f72f9cb00b151c28d10 (patch)
tree82ccc383bc0a9614c95d682b76da6bb8d6435c38 /spec
parenteebafe24a8000ac77bb54660170f5b47bfc5b3a3 (diff)
Add `types` param to `GET /api/v1/notifications` in REST API (#17767)
* Add `types` param to `GET /api/v1/notifications` in REST API

* Improve tests
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/api/v1/notifications_controller_spec.rb79
1 files changed, 23 insertions, 56 deletions
diff --git a/spec/controllers/api/v1/notifications_controller_spec.rb b/spec/controllers/api/v1/notifications_controller_spec.rb
index f8df6589f..46e177c0e 100644
--- a/spec/controllers/api/v1/notifications_controller_spec.rb
+++ b/spec/controllers/api/v1/notifications_controller_spec.rb
@@ -70,23 +70,23 @@ RSpec.describe Api::V1::NotificationsController, type: :controller do
       end
 
       it 'includes reblog' do
-        expect(assigns(:notifications).map(&:activity)).to include(@reblog_of_first_status)
+        expect(body_as_json.map { |x| x[:type] }).to include 'reblog'
       end
 
       it 'includes mention' do
-        expect(assigns(:notifications).map(&:activity)).to include(@mention_from_status)
+        expect(body_as_json.map { |x| x[:type] }).to include 'mention'
       end
 
       it 'includes favourite' do
-        expect(assigns(:notifications).map(&:activity)).to include(@favourite)
+        expect(body_as_json.map { |x| x[:type] }).to include 'favourite'
       end
 
       it 'includes follow' do
-        expect(assigns(:notifications).map(&:activity)).to include(@follow)
+        expect(body_as_json.map { |x| x[:type] }).to include 'follow'
       end
     end
 
-    describe 'from specified user' do
+    describe 'with account_id param' do
       before do
         get :index, params: { account_id: third.account.id }
       end
@@ -95,28 +95,12 @@ RSpec.describe Api::V1::NotificationsController, type: :controller do
         expect(response).to have_http_status(200)
       end
 
-      it 'includes favourite' do
-        expect(assigns(:notifications).map(&:activity)).to include(@second_favourite)
-      end
-
-      it 'excludes favourite' do
-        expect(assigns(:notifications).map(&:activity)).to_not include(@favourite)
-      end
-
-      it 'excludes mention' do
-        expect(assigns(:notifications).map(&:activity)).to_not include(@mention_from_status)
-      end
-
-      it 'excludes reblog' do
-        expect(assigns(:notifications).map(&:activity)).to_not include(@reblog_of_first_status)
-      end
-
-      it 'excludes follow' do
-        expect(assigns(:notifications).map(&:activity)).to_not include(@follow)
+      it 'returns only notifications from specified user' do
+        expect(body_as_json.map { |x| x[:account][:id] }.uniq).to eq [third.account.id.to_s]
       end
     end
 
-    describe 'from nonexistent user' do
+    describe 'with invalid account_id param' do
       before do
         get :index, params: { account_id: 'foo' }
       end
@@ -125,54 +109,37 @@ RSpec.describe Api::V1::NotificationsController, type: :controller do
         expect(response).to have_http_status(200)
       end
 
-      it 'excludes favourite' do
-        expect(assigns(:notifications).map(&:activity)).to_not include(@favourite)
-      end
-
-      it 'excludes second favourite' do
-        expect(assigns(:notifications).map(&:activity)).to_not include(@second_favourite)
-      end
-
-      it 'excludes mention' do
-        expect(assigns(:notifications).map(&:activity)).to_not include(@mention_from_status)
-      end
-
-      it 'excludes reblog' do
-        expect(assigns(:notifications).map(&:activity)).to_not include(@reblog_of_first_status)
-      end
-
-      it 'excludes follow' do
-        expect(assigns(:notifications).map(&:activity)).to_not include(@follow)
+      it 'returns nothing' do
+        expect(body_as_json.size).to eq 0
       end
     end
 
-    describe 'with excluded mentions' do
+    describe 'with excluded_types param' do
       before do
-        get :index, params: { exclude_types: ['mention'] }
+        get :index, params: { exclude_types: %w(mention) }
       end
 
       it 'returns http success' do
         expect(response).to have_http_status(200)
       end
 
-      it 'includes reblog' do
-        expect(assigns(:notifications).map(&:activity)).to include(@reblog_of_first_status)
-      end
-
-      it 'excludes mention' do
-        expect(assigns(:notifications).map(&:activity)).to_not include(@mention_from_status)
+      it 'returns everything but excluded type' do
+        expect(body_as_json.size).to_not eq 0
+        expect(body_as_json.map { |x| x[:type] }.uniq).to_not include 'mention'
       end
+    end
 
-      it 'includes favourite' do
-        expect(assigns(:notifications).map(&:activity)).to include(@favourite)
+    describe 'with types param' do
+      before do
+        get :index, params: { types: %w(mention) }
       end
 
-      it 'includes third favourite' do
-        expect(assigns(:notifications).map(&:activity)).to include(@second_favourite)
+      it 'returns http success' do
+        expect(response).to have_http_status(200)
       end
 
-      it 'includes follow' do
-        expect(assigns(:notifications).map(&:activity)).to include(@follow)
+      it 'returns only requested type' do
+        expect(body_as_json.map { |x| x[:type] }.uniq).to eq ['mention']
       end
     end
   end