about summary refs log tree commit diff
path: root/spec/controllers
diff options
context:
space:
mode:
authorStarfall <us@starfall.systems>2022-03-22 11:16:06 -0500
committerStarfall <us@starfall.systems>2022-03-22 11:16:06 -0500
commitf37056e6c351a08d09c3986586cc7d27bdea85ab (patch)
treec28aaff7e0b70ba0fea07d4335777e6676bff60e /spec/controllers
parent239d67fc2c0ec82617de50a9831bc1a9efc30ecc (diff)
parent9ff119eecd1079e52a8a41d7b8d61520c4303c2f (diff)
Merge remote-tracking branch 'glitch/main'
Diffstat (limited to 'spec/controllers')
-rw-r--r--spec/controllers/admin/domain_blocks_controller_spec.rb9
-rw-r--r--spec/controllers/api/v1/emails/confirmations_controller_spec.rb64
-rw-r--r--spec/controllers/api/v1/notifications_controller_spec.rb79
3 files changed, 87 insertions, 65 deletions
diff --git a/spec/controllers/admin/domain_blocks_controller_spec.rb b/spec/controllers/admin/domain_blocks_controller_spec.rb
index fb23658c0..ecc79292b 100644
--- a/spec/controllers/admin/domain_blocks_controller_spec.rb
+++ b/spec/controllers/admin/domain_blocks_controller_spec.rb
@@ -16,15 +16,6 @@ RSpec.describe Admin::DomainBlocksController, type: :controller do
     end
   end
 
-  describe 'GET #show' do
-    it 'returns http success' do
-      domain_block = Fabricate(:domain_block)
-      get :show, params: { id: domain_block.id }
-
-      expect(response).to have_http_status(200)
-    end
-  end
-
   describe 'POST #create' do
     it 'blocks the domain when succeeded to save' do
       allow(DomainBlockWorker).to receive(:perform_async).and_return(true)
diff --git a/spec/controllers/api/v1/emails/confirmations_controller_spec.rb b/spec/controllers/api/v1/emails/confirmations_controller_spec.rb
new file mode 100644
index 000000000..15ac31cbc
--- /dev/null
+++ b/spec/controllers/api/v1/emails/confirmations_controller_spec.rb
@@ -0,0 +1,64 @@
+require 'rails_helper'
+
+RSpec.describe Api::V1::Emails::ConfirmationsController, type: :controller do
+  let(:confirmed_at) { nil }
+  let(:user)         { Fabricate(:user, confirmed_at: confirmed_at) }
+  let(:app)          { Fabricate(:application) }
+  let(:token)        { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes, application: app) }
+  let(:scopes)       { 'write' }
+
+  describe '#create' do
+    context 'with an oauth token' do
+      before do
+        allow(controller).to receive(:doorkeeper_token) { token }
+      end
+
+      context 'from a random app' do
+        it 'returns http forbidden' do
+          post :create
+          expect(response).to have_http_status(:forbidden)
+        end
+      end
+
+      context 'from an app that created the account' do
+        before do
+          user.update(created_by_application: token.application)
+        end
+
+        context 'when the account is already confirmed' do
+          let(:confirmed_at) { Time.now.utc }
+
+          it 'returns http forbidden' do
+            post :create
+            expect(response).to have_http_status(:forbidden)
+          end
+
+          context 'but user changed e-mail and has not confirmed it' do
+            before do
+              user.update(email: 'foo@bar.com')
+            end
+
+            it 'returns http success' do
+              post :create
+              expect(response).to have_http_status(:success)
+            end
+          end
+        end
+
+        context 'when the account is unconfirmed' do
+          it 'returns http success' do
+            post :create
+            expect(response).to have_http_status(:success)
+          end
+        end
+      end
+    end
+
+    context 'without an oauth token' do
+      it 'returns http unauthorized' do
+        post :create
+        expect(response).to have_http_status(:unauthorized)
+      end
+    end
+  end
+end
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