From ec66f1b5ca20764abe21524792480755b614dbc7 Mon Sep 17 00:00:00 2001 From: Lee Tickett Date: Mon, 24 Jun 2019 12:18:40 +0000 Subject: Add name & search parameters to project environments API --- spec/requests/api/environments_spec.rb | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'spec/requests/api/environments_spec.rb') diff --git a/spec/requests/api/environments_spec.rb b/spec/requests/api/environments_spec.rb index 8fc7fdc8632..745f3c55ac8 100644 --- a/spec/requests/api/environments_spec.rb +++ b/spec/requests/api/environments_spec.rb @@ -34,6 +34,47 @@ describe API::Environments do expect(json_response.first['project'].keys).to contain_exactly(*project_data_keys) expect(json_response.first).not_to have_key("last_deployment") end + + context 'when filtering' do + let!(:environment2) { create(:environment, project: project) } + + it 'returns environment by name' do + get api("/projects/#{project.id}/environments?name=#{environment.name}", user) + + expect(response).to have_gitlab_http_status(200) + 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 no environment by non-existent name' do + get api("/projects/#{project.id}/environments?name=test", user) + + expect(response).to have_gitlab_http_status(200) + expect(response).to include_pagination_headers + expect(json_response).to be_an Array + expect(json_response.size).to eq(0) + end + + it 'returns environments by name_like' do + get api("/projects/#{project.id}/environments?search=envir", user) + + expect(response).to have_gitlab_http_status(200) + expect(response).to include_pagination_headers + expect(json_response).to be_an Array + expect(json_response.size).to eq(2) + end + + it 'returns no environment by non-existent name_like' do + get api("/projects/#{project.id}/environments?search=test", user) + + expect(response).to have_gitlab_http_status(200) + expect(response).to include_pagination_headers + expect(json_response).to be_an Array + expect(json_response.size).to eq(0) + end + end end context 'as non member' do -- cgit v1.2.1