2021-01-03 14:25:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe WhatsNewController do
|
|
|
|
describe 'whats_new_path' do
|
2021-02-22 17:27:13 +05:30
|
|
|
let(:item) { double(:item) }
|
|
|
|
let(:highlights) { double(:highlight, items: [item], map: [item].map, next_page: 2) }
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
context 'with whats_new_drawer feature enabled' do
|
2021-01-03 14:25:43 +05:30
|
|
|
before do
|
|
|
|
stub_feature_flags(whats_new_drawer: true)
|
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
context 'with no page param' do
|
|
|
|
it 'responds with paginated data and headers' do
|
2021-02-22 17:27:13 +05:30
|
|
|
allow(ReleaseHighlight).to receive(:paginated).with(page: 1).and_return(highlights)
|
|
|
|
allow(Gitlab::WhatsNew::ItemPresenter).to receive(:present).with(item).and_return(item)
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
get whats_new_path, xhr: true
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
expect(response.body).to eq(highlights.items.to_json)
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(response.headers['X-Next-Page']).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with page param' do
|
2021-02-22 17:27:13 +05:30
|
|
|
it 'passes the page parameter' do
|
|
|
|
expect(ReleaseHighlight).to receive(:paginated).with(page: 2).and_call_original
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
get whats_new_path(page: 2), xhr: true
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a 404 if page param is negative' do
|
|
|
|
get whats_new_path(page: -1), xhr: true
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
|
|
|
end
|
2021-02-22 17:27:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'with version param' do
|
|
|
|
it 'returns items without pagination headers' do
|
|
|
|
allow(ReleaseHighlight).to receive(:for_version).with(version: '42').and_return(highlights)
|
|
|
|
allow(Gitlab::WhatsNew::ItemPresenter).to receive(:present).with(item).and_return(item)
|
|
|
|
|
|
|
|
get whats_new_path(version: 42), xhr: true
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
expect(response.body).to eq(highlights.items.to_json)
|
|
|
|
expect(response.headers['X-Next-Page']).to be_nil
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with whats_new_drawer feature disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(whats_new_drawer: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a 404' do
|
|
|
|
get whats_new_path, xhr: true
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|