mirror of
https://github.com/mastodon/mastodon.git
synced 2025-11-27 18:10:58 +00:00
Some checks failed
Check i18n / check-i18n (push) Waiting to run
Chromatic / Run Chromatic (push) Waiting to run
CodeQL / Analyze (actions) (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Crowdin / Upload translations / upload-translations (push) Waiting to run
Check formatting / lint (push) Waiting to run
JavaScript Linting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
JavaScript Testing / test (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Historical data migration test / test (16-alpine) (push) Waiting to run
Historical data migration test / test (17-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / test (3.3) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (.ruby-version) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (3.2) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (3.3) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.3) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Haml Linting / lint (push) Has been cancelled
156 lines
4.9 KiB
Ruby
156 lines
4.9 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
RSpec.describe 'Link' do
|
|
let(:user) { Fabricate(:user) }
|
|
let(:scopes) { 'read:statuses' }
|
|
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 link timeline' do
|
|
it 'returns the expected statuses successfully', :aggregate_failures do
|
|
subject
|
|
|
|
expect(response).to have_http_status(200)
|
|
expect(response.content_type)
|
|
.to start_with('application/json')
|
|
expect(response.parsed_body.pluck(:id)).to match_array(expected_statuses.map { |status| status.id.to_s })
|
|
end
|
|
end
|
|
|
|
describe 'GET /api/v1/timelines/link' do
|
|
subject do
|
|
get '/api/v1/timelines/link', headers: headers, params: params
|
|
end
|
|
|
|
let(:url) { 'https://example.com/' }
|
|
let(:private_status) { Fabricate(:status, visibility: :private) }
|
|
let(:undiscoverable_status) { Fabricate(:status, account: Fabricate.build(:account, domain: nil, discoverable: false)) }
|
|
let(:local_status) { Fabricate(:status, account: Fabricate.build(:account, domain: nil, discoverable: true)) }
|
|
let(:remote_status) { Fabricate(:status, account: Fabricate.build(:account, domain: 'example.com', discoverable: true)) }
|
|
let(:params) { { url: url } }
|
|
let(:expected_statuses) { [local_status, remote_status] }
|
|
let(:preview_card) { Fabricate(:preview_card, url: url) }
|
|
|
|
before do
|
|
if preview_card.present?
|
|
preview_card.create_trend!(allowed: true)
|
|
|
|
[private_status, undiscoverable_status, remote_status, local_status].each do |status|
|
|
PreviewCardsStatus.create(status: status, preview_card: preview_card, url: url)
|
|
end
|
|
end
|
|
end
|
|
|
|
it_behaves_like 'forbidden for wrong scope', 'profile'
|
|
|
|
context 'when there is no preview card' do
|
|
let(:preview_card) { nil }
|
|
|
|
it 'returns http not found' do
|
|
subject
|
|
|
|
expect(response).to have_http_status(404)
|
|
expect(response.content_type)
|
|
.to start_with('application/json')
|
|
end
|
|
end
|
|
|
|
context 'when preview card is not trending' do
|
|
before do
|
|
preview_card.trend.destroy!
|
|
end
|
|
|
|
it 'returns http not found' do
|
|
subject
|
|
|
|
expect(response).to have_http_status(404)
|
|
expect(response.content_type)
|
|
.to start_with('application/json')
|
|
end
|
|
end
|
|
|
|
context 'when preview card is trending but not approved' do
|
|
before do
|
|
preview_card.trend.update(allowed: false)
|
|
end
|
|
|
|
it 'returns http not found' do
|
|
subject
|
|
|
|
expect(response).to have_http_status(404)
|
|
expect(response.content_type)
|
|
.to start_with('application/json')
|
|
end
|
|
end
|
|
|
|
context 'when the instance does not allow public preview' do
|
|
before do
|
|
Form::AdminSettings.new(local_topic_feed_access: 'authenticated', remote_topic_feed_access: 'authenticated').save
|
|
end
|
|
|
|
it_behaves_like 'forbidden for wrong scope', 'profile'
|
|
|
|
context 'without an authentication token' do
|
|
let(:headers) { {} }
|
|
|
|
it 'returns http unprocessable entity' do
|
|
subject
|
|
|
|
expect(response).to have_http_status(422)
|
|
expect(response.content_type)
|
|
.to start_with('application/json')
|
|
end
|
|
end
|
|
|
|
context 'with an application access token, not bound to a user' do
|
|
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: nil, scopes: scopes) }
|
|
|
|
it 'returns http unprocessable entity' do
|
|
subject
|
|
|
|
expect(response).to have_http_status(422)
|
|
expect(response.content_type)
|
|
.to start_with('application/json')
|
|
end
|
|
end
|
|
|
|
context 'when the user is authenticated' do
|
|
it_behaves_like 'a successful request to the link timeline'
|
|
end
|
|
end
|
|
|
|
context 'when the instance allows public preview' do
|
|
context 'with an authorized user' do
|
|
it_behaves_like 'a successful request to the link timeline'
|
|
end
|
|
|
|
context 'with an anonymous user' do
|
|
let(:headers) { {} }
|
|
|
|
it_behaves_like 'a successful request to the link timeline'
|
|
end
|
|
|
|
context 'with limit param' do
|
|
let(:params) { { limit: 1, url: url } }
|
|
|
|
it 'returns only the requested number of statuses with pagination headers', :aggregate_failures do
|
|
subject
|
|
|
|
expect(response).to have_http_status(200)
|
|
expect(response.content_type)
|
|
.to start_with('application/json')
|
|
expect(response.parsed_body.size).to eq(params[:limit])
|
|
|
|
expect(response)
|
|
.to include_pagination_headers(
|
|
prev: api_v1_timelines_link_url(limit: params[:limit], url: url, min_id: local_status.id),
|
|
next: api_v1_timelines_link_url(limit: params[:limit], url: url, max_id: local_status.id)
|
|
)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|