summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel M Brasil <danielmbrasil@protonmail.com>2023-10-13 09:43:50 -0300
committerGitHub <noreply@github.com>2023-10-13 14:43:50 +0200
commitbc6cd27d9edc473da3403c9af7970db8114b2135 (patch)
tree8cba9519d8bfe6370b6f7ec3ec1e61e78c5a2cea
parentfd9dea21d0da9d5c4184efca8f66cc2ffc5435f6 (diff)
Migrate to request specs in `/api/v1/followed_tags` (#25472)
-rw-r--r--.rubocop_todo.yml1
-rw-r--r--spec/controllers/api/v1/followed_tags_controller_spec.rb25
-rw-r--r--spec/requests/api/v1/followed_tags_spec.rb65
3 files changed, 65 insertions, 26 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index 19cfcff7f73..d58bee4ba80 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -180,7 +180,6 @@ RSpec/LetSetup:
- 'spec/controllers/api/v1/accounts/statuses_controller_spec.rb'
- 'spec/controllers/api/v1/admin/accounts_controller_spec.rb'
- 'spec/controllers/api/v1/filters_controller_spec.rb'
- - 'spec/controllers/api/v1/followed_tags_controller_spec.rb'
- 'spec/controllers/api/v2/admin/accounts_controller_spec.rb'
- 'spec/controllers/api/v2/filters/keywords_controller_spec.rb'
- 'spec/controllers/api/v2/filters/statuses_controller_spec.rb'
diff --git a/spec/controllers/api/v1/followed_tags_controller_spec.rb b/spec/controllers/api/v1/followed_tags_controller_spec.rb
deleted file mode 100644
index c1a366d4e37..00000000000
--- a/spec/controllers/api/v1/followed_tags_controller_spec.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-# frozen_string_literal: true
-
-require 'rails_helper'
-
-RSpec.describe Api::V1::FollowedTagsController do
- render_views
-
- let(:user) { Fabricate(:user) }
- let(:scopes) { 'read:follows' }
- let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
-
- before { allow(controller).to receive(:doorkeeper_token) { token } }
-
- describe 'GET #index' do
- let!(:tag_follows) { Fabricate.times(5, :tag_follow, account: user.account) }
-
- before do
- get :index, params: { limit: 1 }
- end
-
- it 'returns http success' do
- expect(response).to have_http_status(:success)
- end
- end
-end
diff --git a/spec/requests/api/v1/followed_tags_spec.rb b/spec/requests/api/v1/followed_tags_spec.rb
new file mode 100644
index 00000000000..9391c7bdc8b
--- /dev/null
+++ b/spec/requests/api/v1/followed_tags_spec.rb
@@ -0,0 +1,65 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe 'Followed tags' do
+ let(:user) { Fabricate(:user) }
+ let(:scopes) { 'read:follows' }
+ let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
+ let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
+
+ describe 'GET /api/v1/followed_tags' do
+ subject do
+ get '/api/v1/followed_tags', headers: headers, params: params
+ end
+
+ let!(:tag_follows) { Fabricate.times(5, :tag_follow, account: user.account) }
+ let(:params) { {} }
+
+ let(:expected_response) do
+ tag_follows.map do |tag_follow|
+ a_hash_including(name: tag_follow.tag.name, following: true)
+ end
+ end
+
+ before do
+ Fabricate(:tag_follow)
+ end
+
+ it_behaves_like 'forbidden for wrong scope', 'write write:follows'
+
+ it 'returns http success' do
+ subject
+
+ expect(response).to have_http_status(:success)
+ end
+
+ it 'returns the followed tags correctly' do
+ subject
+
+ expect(body_as_json).to match_array(expected_response)
+ end
+
+ context 'with limit param' do
+ let(:params) { { limit: 3 } }
+
+ it 'returns only the requested number of follow tags' do
+ subject
+
+ expect(body_as_json.size).to eq(params[:limit])
+ end
+
+ it 'sets the correct pagination header for the prev path' do
+ subject
+
+ expect(response.headers['Link'].find_link(%w(rel prev)).href).to eq(api_v1_followed_tags_url(limit: params[:limit], since_id: tag_follows.last.id))
+ end
+
+ it 'sets the correct pagination header for the next path' do
+ subject
+
+ expect(response.headers['Link'].find_link(%w(rel next)).href).to eq(api_v1_followed_tags_url(limit: params[:limit], max_id: tag_follows[2].id))
+ end
+ end
+ end
+end