Commit 02fc1846 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Improve specs for jobs API regarding manual actions

parent e5df86f5
require 'spec_helper' require 'spec_helper'
describe API::Jobs, api: true do describe API::Jobs, :api do
include ApiHelpers let!(:project) do
create(:project, :repository, public_builds: false)
end
let!(:pipeline) do
create(:ci_empty_pipeline, project: project,
sha: project.commit.id,
ref: project.default_branch)
end
let!(:build) { create(:ci_build, pipeline: pipeline) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:api_user) { user } let(:api_user) { user }
let!(:project) { create(:project, :repository, creator: user, public_builds: false) } let(:reporter) { create(:project_member, :reporter, project: project).user }
let!(:developer) { create(:project_member, :developer, user: user, project: project) } let(:guest) { create(:project_member, :guest, project: project).user }
let(:reporter) { create(:project_member, :reporter, project: project) }
let(:guest) { create(:project_member, :guest, project: project) } before do
let!(:pipeline) { create(:ci_empty_pipeline, project: project, sha: project.commit.id, ref: project.default_branch) } project.add_developer(user)
let!(:build) { create(:ci_build, pipeline: pipeline) } end
describe 'GET /projects/:id/jobs' do describe 'GET /projects/:id/jobs' do
let(:query) { Hash.new } let(:query) { Hash.new }
...@@ -213,7 +223,7 @@ describe API::Jobs, api: true do ...@@ -213,7 +223,7 @@ describe API::Jobs, api: true do
end end
describe 'GET /projects/:id/artifacts/:ref_name/download?job=name' do describe 'GET /projects/:id/artifacts/:ref_name/download?job=name' do
let(:api_user) { reporter.user } let(:api_user) { reporter }
let(:build) { create(:ci_build, :artifacts, pipeline: pipeline) } let(:build) { create(:ci_build, :artifacts, pipeline: pipeline) }
before do before do
...@@ -237,7 +247,7 @@ describe API::Jobs, api: true do ...@@ -237,7 +247,7 @@ describe API::Jobs, api: true do
end end
context 'when logging as guest' do context 'when logging as guest' do
let(:api_user) { guest.user } let(:api_user) { guest }
before do before do
get_for_ref get_for_ref
...@@ -347,7 +357,7 @@ describe API::Jobs, api: true do ...@@ -347,7 +357,7 @@ describe API::Jobs, api: true do
end end
context 'user without :update_build permission' do context 'user without :update_build permission' do
let(:api_user) { reporter.user } let(:api_user) { reporter }
it 'does not cancel job' do it 'does not cancel job' do
expect(response).to have_http_status(403) expect(response).to have_http_status(403)
...@@ -381,7 +391,7 @@ describe API::Jobs, api: true do ...@@ -381,7 +391,7 @@ describe API::Jobs, api: true do
end end
context 'user without :update_build permission' do context 'user without :update_build permission' do
let(:api_user) { reporter.user } let(:api_user) { reporter }
it 'does not retry job' do it 'does not retry job' do
expect(response).to have_http_status(403) expect(response).to have_http_status(403)
...@@ -457,16 +467,39 @@ describe API::Jobs, api: true do ...@@ -457,16 +467,39 @@ describe API::Jobs, api: true do
describe 'POST /projects/:id/jobs/:job_id/play' do describe 'POST /projects/:id/jobs/:job_id/play' do
before do before do
post api("/projects/#{project.id}/jobs/#{build.id}/play", user) post api("/projects/#{project.id}/jobs/#{build.id}/play", api_user)
end end
context 'on an playable job' do context 'on an playable job' do
let(:build) { create(:ci_build, :manual, project: project, pipeline: pipeline) } let(:build) { create(:ci_build, :manual, project: project, pipeline: pipeline) }
it 'plays the job' do context 'when user is authorized to trigger a manual action' do
expect(response).to have_http_status(200) it 'plays the job' do
expect(json_response['user']['id']).to eq(user.id) expect(response).to have_http_status(200)
expect(json_response['id']).to eq(build.id) expect(json_response['user']['id']).to eq(user.id)
expect(json_response['id']).to eq(build.id)
expect(build.reload).to be_pending
end
end
context 'when user is not authorized to trigger a manual action' do
context 'when user does not have access to the project' do
let(:api_user) { create(:user) }
it 'does not trigger a manual action' do
expect(build.reload).to be_manual
expect(response).to have_http_status(404)
end
end
context 'when user is not allowed to trigger the manual action' do
let(:api_user) { reporter }
it 'does not trigger a manual action' do
expect(build.reload).to be_manual
expect(response).to have_http_status(403)
end
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment