Skip to content

Commit

Permalink
Test webui package requests controller
Browse files Browse the repository at this point in the history
  • Loading branch information
danidoni committed Dec 13, 2024
1 parent cc62f0a commit 590c49f
Showing 1 changed file with 154 additions and 10 deletions.
164 changes: 154 additions & 10 deletions src/api/spec/controllers/webui/packages/bs_requests_controller_spec.rb
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

0 comments on commit 590c49f

Please sign in to comment.