forked from openSUSE/open-build-service
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test webui package requests controller
- Loading branch information
Showing
1 changed file
with
154 additions
and
10 deletions.
There are no files selected for viewing
164 changes: 154 additions & 10 deletions
164
src/api/spec/controllers/webui/packages/bs_requests_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,163 @@ | ||
RSpec.describe Webui::Packages::BsRequestsController do | ||
describe 'GET #index' do | ||
include_context 'a set of bs requests' | ||
context 'when the user has the request_index feature flag disabled' do | ||
include_context 'a set of bs requests' | ||
|
||
let(:base_params) { { project: source_project, package: source_package, format: :json } } | ||
let(:context_params) { {} } | ||
let(:params) { base_params.merge(context_params) } | ||
let(:base_params) { { project: source_project, package: source_package, format: :json } } | ||
let(:context_params) { {} } | ||
let(:params) { base_params.merge(context_params) } | ||
|
||
before do | ||
get :index, params: params | ||
before do | ||
get :index, params: params | ||
end | ||
|
||
it { expect(response).to have_http_status(:success) } | ||
it { expect(subject).to render_template(:index) } | ||
|
||
it_behaves_like 'a bs requests data table controller' | ||
it_behaves_like 'a bs requests data table controller with state and type options' | ||
end | ||
end | ||
|
||
context 'when the user has the request_index feature flag enabled' do | ||
let!(:user) { create(:confirmed_user, login: 'king') } | ||
|
||
context 'when looking at the target_package requests' do | ||
let(:target_project) { create(:project_with_package) } | ||
let(:target_package) { target_project.packages.first } | ||
let!(:incoming_request) do | ||
create(:bs_request_with_submit_action, | ||
creator: user, | ||
priority: 'critical', | ||
source_package: create(:project), | ||
target_package: target_package) | ||
end | ||
let!(:outgoing_request) do | ||
create(:bs_request_with_submit_action, | ||
creator: user, | ||
priority: 'critical', | ||
source_package: target_package, | ||
target_package: create(:project)) | ||
end | ||
|
||
context 'and the direction parameters is "incoming"' do | ||
let(:base_params) { { project: target_project, package: target_package, format: :json } } | ||
let(:context_params) { { direction: 'incoming' } } | ||
let(:params) { base_params.merge(context_params) } | ||
|
||
before do | ||
login user | ||
Flipper.enable(:request_index, user) | ||
get :index, params: params, format: :html | ||
end | ||
|
||
it { expect(assigns[:bs_requests]).to include(incoming_request) } | ||
it { expect(assigns[:bs_requests]).not_to include(outgoing_request) } | ||
end | ||
|
||
context 'and the direction parameters is "outgoing"' do | ||
let(:base_params) { { project: target_project, package: target_package, format: :json } } | ||
let(:context_params) { { direction: 'outgoing' } } | ||
let(:params) { base_params.merge(context_params) } | ||
|
||
before do | ||
login user | ||
Flipper.enable(:request_index, user) | ||
get :index, params: params, format: :html | ||
end | ||
|
||
it { expect(response).to have_http_status(:success) } | ||
it { expect(subject).to render_template(:index) } | ||
it { expect(assigns[:bs_requests]).not_to include(incoming_request) } | ||
it { expect(assigns[:bs_requests]).to include(outgoing_request) } | ||
end | ||
|
||
context 'and the direction parameters is "all"' do | ||
let(:base_params) { { project: target_project, package: target_package, format: :json } } | ||
let(:context_params) { { direction: 'all' } } | ||
let(:params) { base_params.merge(context_params) } | ||
|
||
before do | ||
login user | ||
Flipper.enable(:request_index, user) | ||
get :index, params: params, format: :html | ||
end | ||
|
||
it { expect(response).to have_http_status(:success) } | ||
it { expect(subject).to render_template(:index) } | ||
it { expect(assigns[:bs_requests]).to include(incoming_request) } | ||
it { expect(assigns[:bs_requests]).to include(outgoing_request) } | ||
end | ||
end | ||
|
||
it { expect(response).to have_http_status(:success) } | ||
it { expect(subject).to render_template(:index) } | ||
context 'when looking at the source_package requests' do | ||
let(:source_project) { create(:project_with_package) } | ||
let(:source_package) { source_project.packages.first } | ||
let!(:incoming_request) do | ||
create(:bs_request_with_submit_action, | ||
creator: user, | ||
priority: 'critical', | ||
source_package: create(:project), | ||
target_package: source_package) | ||
end | ||
let!(:outgoing_request) do | ||
create(:bs_request_with_submit_action, | ||
creator: user, | ||
priority: 'critical', | ||
source_package: source_package, | ||
target_package: create(:project)) | ||
end | ||
|
||
context 'and the direction parameters is "incoming"' do | ||
let(:base_params) { { project: source_project, package: source_package, format: :json } } | ||
let(:context_params) { { direction: 'incoming' } } | ||
let(:params) { base_params.merge(context_params) } | ||
|
||
before do | ||
login user | ||
Flipper.enable(:request_index, user) | ||
get :index, params: params, format: :html | ||
end | ||
|
||
it { expect(response).to have_http_status(:success) } | ||
it { expect(subject).to render_template(:index) } | ||
it { expect(assigns[:bs_requests]).not_to include(outgoing_request) } | ||
it { expect(assigns[:bs_requests]).to include(incoming_request) } | ||
end | ||
|
||
it_behaves_like 'a bs requests data table controller' | ||
it_behaves_like 'a bs requests data table controller with state and type options' | ||
context 'and the direction parameters is "outgoing"' do | ||
let(:base_params) { { project: source_project, package: source_package, format: :json } } | ||
let(:context_params) { { direction: 'outgoing' } } | ||
let(:params) { base_params.merge(context_params) } | ||
|
||
before do | ||
login user | ||
Flipper.enable(:request_index, user) | ||
get :index, params: params, format: :html | ||
end | ||
|
||
it { expect(response).to have_http_status(:success) } | ||
it { expect(subject).to render_template(:index) } | ||
it { expect(assigns[:bs_requests]).not_to include(incoming_request) } | ||
it { expect(assigns[:bs_requests]).to include(outgoing_request) } | ||
end | ||
|
||
context 'and the direction parameters is "all"' do | ||
let(:base_params) { { project: source_project, package: source_package, format: :json } } | ||
let(:context_params) { { direction: 'all' } } | ||
let(:params) { base_params.merge(context_params) } | ||
|
||
before do | ||
login user | ||
Flipper.enable(:request_index, user) | ||
get :index, params: params, format: :html | ||
end | ||
|
||
it { expect(response).to have_http_status(:success) } | ||
it { expect(subject).to render_template(:index) } | ||
it { expect(assigns[:bs_requests]).to include(incoming_request) } | ||
it { expect(assigns[:bs_requests]).to include(outgoing_request) } | ||
end | ||
end | ||
end | ||
end |