From 0a4a73f9a67d5dc80a66d192af2b89cac41563a1 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 23 Oct 2024 02:40:29 -0400 Subject: [PATCH] Add coverage for `api/v1/domain_blocks/preview` endpoint (#32303) --- .../api/v1/domain_blocks/previews_spec.rb | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 spec/requests/api/v1/domain_blocks/previews_spec.rb diff --git a/spec/requests/api/v1/domain_blocks/previews_spec.rb b/spec/requests/api/v1/domain_blocks/previews_spec.rb new file mode 100644 index 0000000000..eb191f436b --- /dev/null +++ b/spec/requests/api/v1/domain_blocks/previews_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Domain Blocks Previews API' do + let(:user) { Fabricate(:user) } + let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) } + let(:scopes) { 'write:blocks' } + let(:headers) { { 'Authorization' => "Bearer #{token.token}" } } + let(:account) { Fabricate(:account, user: user) } + + describe 'GET /api/v1/domain_blocks/preview' do + subject { get '/api/v1/domain_blocks/preview', params: { domain: domain }, headers: headers } + + let(:domain) { 'host.example' } + + before do + Fabricate :follow, account: account, target_account: Fabricate(:account, domain: domain) + Fabricate :follow, target_account: account, account: Fabricate(:account, domain: domain) + end + + it_behaves_like 'forbidden for wrong scope', 'write:statuses' + + it 'returns http success and follower counts' do + subject + + expect(response) + .to have_http_status(200) + expect(response.content_type) + .to start_with('application/json') + expect(response.parsed_body) + .to include(followers_count: 1) + .and include(following_count: 1) + end + end +end