Skip to content
Snippets Groups Projects
Unverified Commit e718b930 authored by Ahmed Hemdan's avatar Ahmed Hemdan
Browse files

Define states parameter in environments api interface

Changelog: changed
parent 5c2b54ff
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -22,16 +22,15 @@ class Environments < ::API::Base
use :pagination
optional :name, type: String, desc: 'Returns the environment with this name'
optional :search, type: String, desc: 'Returns list of environments matching the search criteria'
optional :states, type: String, values: Environment.valid_states.map(&:to_s), desc: 'List all environments that match a specific state'
mutually_exclusive :name, :search, message: 'cannot be used together'
end
get ':id/environments' do
authorize! :read_environment, user_project
 
environments = ::Environments::EnvironmentsFinder.new(user_project, current_user, params).execute
environments = ::Environments::EnvironmentsFinder.new(user_project, current_user, declared_params(include_missing: false)).execute
 
present paginate(environments), with: Entities::Environment, current_user: current_user
rescue ::Environments::EnvironmentsFinder::InvalidStatesError => exception
bad_request!(exception.message)
end
 
desc 'Creates a new environment' do
Loading
Loading
Loading
Loading
@@ -113,7 +113,7 @@
end
 
context 'when filtering' do
let_it_be(:environment2) { create(:environment, project: project) }
let_it_be(:stopped_environment) { create(:environment, :stopped, project: project) }
 
it 'returns environment by name' do
get api("/projects/#{project.id}/environments?name=#{environment.name}", user)
Loading
Loading
@@ -152,11 +152,32 @@
expect(json_response.size).to eq(0)
end
 
it 'returns a 400 status code with invalid states' do
it 'returns environment by valid state' do
get api("/projects/#{project.id}/environments?states=available", user)
expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.size).to eq(1)
expect(json_response.first['name']).to eq(environment.name)
end
it 'returns all environments when state is not specified' do
get api("/projects/#{project.id}/environments", user)
expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.size).to eq(2)
expect(json_response.first['name']).to eq(environment.name)
expect(json_response.last['name']).to eq(stopped_environment.name)
end
it 'returns a 400 when filtering by invalid state' do
get api("/projects/#{project.id}/environments?states=test", user)
 
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']).to include('Requested states are invalid')
expect(json_response['error']).to eq('states does not have a valid value')
end
end
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment