Merge commit 'c9ea91f8683cd5c0cfac14071a17e3956ac6d3b0' into glitch-soc/merge-upstream

Conflicts:
- `spec/requests/api/v1/timelines/tag_spec.rb`:
  Upstream refactored this file, while we had a change to switch a default setting.
  Updated as upstream did.
- `spec/views/statuses/show.html.haml_spec.rb`:
  Upstream refactored this file, while we stubbed different methods.
  Updated as upstream did, and updated the stubs accordingly.
This commit is contained in:
Claire
2024-09-03 21:51:53 +02:00
87 changed files with 851 additions and 477 deletions

View File

@@ -0,0 +1,57 @@
# frozen_string_literal: true
require 'rails_helper'
describe 'API V1 Annual Reports' do
let(:user) { Fabricate(:user) }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
describe 'GET /api/v1/annual_reports' do
context 'when not authorized' do
it 'returns http unauthorized' do
get api_v1_annual_reports_path
expect(response)
.to have_http_status(401)
end
end
context 'with wrong scope' do
before do
get api_v1_annual_reports_path, headers: headers
end
it_behaves_like 'forbidden for wrong scope', 'write write:accounts'
end
context 'with correct scope' do
let(:scopes) { 'read:accounts' }
it 'returns http success' do
get api_v1_annual_reports_path, headers: headers
expect(response)
.to have_http_status(200)
expect(body_as_json)
.to be_present
end
end
end
describe 'POST /api/v1/annual_reports/:id/read' do
context 'with correct scope' do
let(:scopes) { 'write:accounts' }
it 'returns success and marks the report as read' do
annual_report = Fabricate :generated_annual_report, account: user.account
expect { post read_api_v1_annual_report_path(id: annual_report.year), headers: headers }
.to change { annual_report.reload.viewed? }.to(true)
expect(response)
.to have_http_status(200)
end
end
end
end

View File

@@ -10,12 +10,11 @@ describe 'API V1 Streaming' do
Rails.configuration.x.streaming_api_base_url = before
end
let(:headers) { { 'Host' => Rails.configuration.x.web_domain } }
context 'with streaming api on same host' do
describe 'GET /api/v1/streaming' do
it 'raises ActiveRecord::RecordNotFound' do
get '/api/v1/streaming', headers: headers
integration_session.https!(false)
get '/api/v1/streaming'
expect(response).to have_http_status(404)
end

View File

@@ -8,15 +8,6 @@ RSpec.describe 'Tag' do
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
shared_examples 'a successful request to the tag timeline' do
it 'returns the expected statuses', :aggregate_failures do
subject
expect(response).to have_http_status(200)
expect(body_as_json.pluck(:id)).to match_array(expected_statuses.map { |status| status.id.to_s })
end
end
describe 'GET /api/v1/timelines/tag/:hashtag' do
subject do
get "/api/v1/timelines/tag/#{hashtag}", headers: headers, params: params
@@ -26,8 +17,20 @@ RSpec.describe 'Tag' do
Setting.timeline_preview = true
end
shared_examples 'a successful request to the tag timeline' do
it 'returns the expected statuses', :aggregate_failures do
subject
expect(response)
.to have_http_status(200)
expect(body_as_json.pluck(:id))
.to match_array(expected_statuses.map { |status| status.id.to_s })
.and not_include(private_status.id)
end
end
let(:account) { Fabricate(:account) }
let!(:private_status) { PostStatusService.new.call(account, visibility: :private, text: '#life could be a dream') } # rubocop:disable RSpec/LetSetup
let!(:private_status) { PostStatusService.new.call(account, visibility: :private, text: '#life could be a dream') }
let!(:life_status) { PostStatusService.new.call(account, text: 'tell me what is my #life without your #love') }
let!(:war_status) { PostStatusService.new.call(user.account, text: '#war, war never changes') }
let!(:love_status) { PostStatusService.new.call(account, text: 'what is #love?') }