2023-03-04 16:12:54 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-01-26 17:40:39 +00:00
|
|
|
RSpec.describe 'API V1 Trends Statuses' do
|
|
|
|
describe 'GET /api/v1/trends/statuses' do
|
2023-11-13 14:32:36 +00:00
|
|
|
context 'when trends are disabled' do
|
|
|
|
before { Setting.trends = false }
|
|
|
|
|
|
|
|
it 'returns http success' do
|
2024-01-26 17:40:39 +00:00
|
|
|
get '/api/v1/trends/statuses'
|
2023-11-13 14:32:36 +00:00
|
|
|
|
2024-09-18 08:22:07 +00:00
|
|
|
expect(response)
|
|
|
|
.to have_http_status(200)
|
|
|
|
.and not_have_http_link_header
|
2024-09-20 13:13:04 +00:00
|
|
|
expect(response.content_type)
|
|
|
|
.to start_with('application/json')
|
2023-11-13 14:32:36 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when trends are enabled' do
|
|
|
|
before { Setting.trends = true }
|
|
|
|
|
|
|
|
it 'returns http success' do
|
|
|
|
prepare_trends
|
|
|
|
stub_const('Api::BaseController::DEFAULT_STATUSES_LIMIT', 2)
|
2024-01-26 17:40:39 +00:00
|
|
|
get '/api/v1/trends/statuses'
|
2023-11-13 14:32:36 +00:00
|
|
|
|
2024-09-18 08:22:07 +00:00
|
|
|
expect(response)
|
|
|
|
.to have_http_status(200)
|
|
|
|
.and have_http_link_header(api_v1_trends_statuses_url(offset: 2)).for(rel: 'next')
|
2024-09-20 13:13:04 +00:00
|
|
|
expect(response.content_type)
|
|
|
|
.to start_with('application/json')
|
2023-11-13 14:32:36 +00:00
|
|
|
end
|
2023-03-04 16:12:54 +00:00
|
|
|
|
2023-11-13 14:32:36 +00:00
|
|
|
def prepare_trends
|
|
|
|
Fabricate.times(3, :status, trendable: true, language: 'en').each do |status|
|
|
|
|
2.times { |i| Trends.statuses.add(status, i) }
|
|
|
|
end
|
|
|
|
Trends::Statuses.new(threshold: 1, decay_threshold: -1).refresh
|
|
|
|
end
|
2023-03-04 16:12:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|