diff options
author | Z.J. van de Weg <zegerjan@gitlab.com> | 2016-07-26 09:37:02 +0200 |
---|---|---|
committer | Z.J. van de Weg <zegerjan@gitlab.com> | 2016-07-29 13:54:45 +0200 |
commit | 84cd2120952e7ee4095cb4b5d7c959f2c11610c5 (patch) | |
tree | 3f4f3498543311c4291f88285778c9d71c9cc21e /spec | |
parent | be9aa7f19474424991923f128053e2523fa166d8 (diff) | |
download | gitlab-ce-84cd2120952e7ee4095cb4b5d7c959f2c11610c5.tar.gz |
Add API support for environments
Diffstat (limited to 'spec')
-rw-r--r-- | spec/requests/api/environments_spec.rb | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/spec/requests/api/environments_spec.rb b/spec/requests/api/environments_spec.rb new file mode 100644 index 00000000000..822139dbf3b --- /dev/null +++ b/spec/requests/api/environments_spec.rb @@ -0,0 +1,103 @@ +require 'spec_helper' + +describe API::API, api: true do + include ApiHelpers + + let(:user) { create(:user) } + let(:non_member) { create(:user) } + let(:project) { create(:project, :private, creator_id: user.id, namespace: user.namespace) } + let!(:environment) { create(:environment, project: project) } + + before do + project.team << [user, :master] + end + + describe 'GET /projects/:id/environments' do + context 'as member of the project' do + it 'should return project labels' do + get api("/projects/#{project.id}/environments", user) + + expect(response).to have_http_status(200) + expect(json_response).to be_an Array + expect(json_response.size).to eq(1) + expect(json_response.first['name']).to eq(environment.name) + expect(json_response.first['external_url']).to eq(environment.external_url) + end + end + + context 'as non member' do + it 'should return a 404 status code' do + get api("/projects/#{project.id}/environments", non_member) + + expect(response).to have_http_status(404) + end + end + end + + describe 'POST /projects/:id/labels' do + context 'as a member' do + it 'creates a environment with valid params' do + post api("/projects/#{project.id}/environments", user), name: "mepmep" + + expect(response).to have_http_status(201) + expect(json_response['name']).to eq('mepmep') + expect(json_response['external']).to be nil + end + + it 'requires name to be passed' do + post api("/projects/#{project.id}/environments", user), external_url: 'test.gitlab.com' + + expect(response).to have_http_status(400) + end + + it 'should return 409 if environment already exists' do + post api("/projects/#{project.id}/environments", user), name: environment.name + + expect(response).to have_http_status(409) + expect(json_response['message']).to eq('Environment already exists') + end + end + + context 'a non member' do + it 'rejects the request' do + post api("/projects/#{project.id}/environments", non_member) + + expect(response).to have_http_status(404) + end + end + end + + describe 'DELETE /projects/:id/environments/:environment_id' do + context 'as a master' do + it 'should return 200 for an existing environment' do + delete api("/projects/#{project.id}/environments/#{environment.id}", user) + + expect(response).to have_http_status(200) + end + + it 'should return 404 for non existing id' do + delete api("/projects/#{project.id}/environments/12345", user) + + expect(response).to have_http_status(404) + expect(json_response['message']).to eq('404 Not found') + end + end + end + + describe 'PUT /projects/:id/environments/:environment_id' do + it 'should return 200 if name and external_url are changed' do + put api("/projects/#{project.id}/environments/#{environment.id}", user), + name: 'Mepmep', external_url: 'mepmep.whatever.ninja' + + expect(response).to have_http_status(200) + expect(json_response['name']).to eq('Mepmep') + expect(json_response['external_url']).to eq('mepmep.whatever.ninja') + end + + it 'should return 404 if the environment does not exist' do + put api("/projects/#{project.id}/environments/12345", user) + + expect(response).to have_http_status(404) + end + end +end |