2020-10-14 14:08:47 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2021-02-15 19:09:01 -05:00
|
|
|
RSpec.describe WhatsNewController, :clean_gitlab_redis_cache do
|
|
|
|
after do
|
|
|
|
ReleaseHighlight.instance_variable_set(:@file_paths, nil)
|
|
|
|
end
|
|
|
|
|
2021-04-27 11:09:52 -04:00
|
|
|
describe 'GET #index' do
|
2020-12-10 10:10:12 -05:00
|
|
|
let(:item) { double(:item) }
|
|
|
|
let(:highlights) { double(:highlight, items: [item], map: [item].map, next_page: 2) }
|
|
|
|
|
2021-01-21 04:08:52 -05:00
|
|
|
context 'with no page param' do
|
|
|
|
it 'responds with paginated data and headers' do
|
|
|
|
allow(ReleaseHighlight).to receive(:paginated).with(page: 1).and_return(highlights)
|
2020-11-24 13:09:14 -05:00
|
|
|
|
2021-01-21 04:08:52 -05:00
|
|
|
get whats_new_path, xhr: true
|
2020-11-02 04:08:35 -05:00
|
|
|
|
2021-01-21 04:08:52 -05:00
|
|
|
expect(response.body).to eq(highlights.items.to_json)
|
|
|
|
expect(response.headers['X-Next-Page']).to eq(2)
|
2020-11-02 04:08:35 -05:00
|
|
|
end
|
2021-01-21 04:08:52 -05:00
|
|
|
end
|
2020-11-02 04:08:35 -05:00
|
|
|
|
2021-01-21 04:08:52 -05:00
|
|
|
context 'with page param' do
|
|
|
|
it 'passes the page parameter' do
|
|
|
|
expect(ReleaseHighlight).to receive(:paginated).with(page: 2).and_call_original
|
2020-11-02 04:08:35 -05:00
|
|
|
|
2021-01-21 04:08:52 -05:00
|
|
|
get whats_new_path(page: 2), xhr: true
|
2020-10-14 14:08:47 -04:00
|
|
|
end
|
2020-12-10 10:10:12 -05:00
|
|
|
|
2021-01-21 04:08:52 -05:00
|
|
|
it 'returns a 404 if page param is negative' do
|
|
|
|
get whats_new_path(page: -1), xhr: true
|
2020-12-10 10:10:12 -05:00
|
|
|
|
2021-01-21 04:08:52 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2020-12-10 10:10:12 -05:00
|
|
|
end
|
2020-10-14 14:08:47 -04:00
|
|
|
end
|
2021-04-27 11:09:52 -04:00
|
|
|
|
|
|
|
context 'with whats_new_variant = disabled' do
|
|
|
|
before do
|
|
|
|
Gitlab::CurrentSettings.current_application_settings.whats_new_variant_disabled!
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a 404' do
|
|
|
|
get whats_new_path, xhr: true
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
|
|
|
end
|
|
|
|
end
|
2020-10-14 14:08:47 -04:00
|
|
|
end
|
|
|
|
end
|