2023-03-04 17:12:54 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-01-26 18:40:39 +01:00
|
|
|
RSpec.describe 'API V1 Trends Links' do
|
|
|
|
describe 'GET /api/v1/trends/links' do
|
2023-11-13 15:32:36 +01:00
|
|
|
context 'when trends are disabled' do
|
|
|
|
before { Setting.trends = false }
|
|
|
|
|
|
|
|
it 'returns http success' do
|
2024-01-26 18:40:39 +01:00
|
|
|
get '/api/v1/trends/links'
|
2023-11-13 15:32:36 +01:00
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when trends are enabled' do
|
|
|
|
before { Setting.trends = true }
|
|
|
|
|
|
|
|
it 'returns http success' do
|
|
|
|
prepare_trends
|
|
|
|
stub_const('Api::V1::Trends::LinksController::DEFAULT_LINKS_LIMIT', 2)
|
2024-01-26 18:40:39 +01:00
|
|
|
get '/api/v1/trends/links'
|
2023-11-13 15:32:36 +01:00
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(response.headers).to include('Link')
|
|
|
|
end
|
2023-03-04 17:12:54 +01:00
|
|
|
|
2023-11-13 15:32:36 +01:00
|
|
|
def prepare_trends
|
|
|
|
Fabricate.times(3, :preview_card, trendable: true, language: 'en').each do |link|
|
|
|
|
2.times { |i| Trends.links.add(link, i) }
|
|
|
|
end
|
|
|
|
Trends::Links.new(threshold: 1).refresh
|
|
|
|
end
|
2023-03-04 17:12:54 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|