Adjusts tests per MR feedback

- Updates tests / applies patterns per MR feedback
This commit is contained in:
jhampton 2018-12-06 17:45:55 -05:00
parent 242bead1fb
commit 1bf28d4808
2 changed files with 80 additions and 38 deletions

View file

@ -398,40 +398,61 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do
end
end
context 'with variables' do
context 'with variables and user is a maintainer' do
before do
project.add_maintainer(user)
create(:ci_pipeline_variable, pipeline: pipeline, key: :TRIGGER_KEY_1, value: 'TRIGGER_VALUE_1')
get_show(id: job.id, format: :json)
end
it 'exposes trigger information and variables' do
before(:each) do
@first_variable = json_response['trigger']['variables'].first
end
it 'returns a job_detail' do
expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('job/job_details')
end
it 'exposes trigger information and variables' do
expect(json_response['trigger']['short_token']).to eq 'toke'
expect(json_response['trigger']['variables'].length).to eq 1
expect(json_response['trigger']['variables'].first['key']).to eq "TRIGGER_KEY_1"
expect(json_response['trigger']['variables'].first['value']).to eq "TRIGGER_VALUE_1"
expect(json_response['trigger']['variables'].first['public']).to eq false
end
it 'exposes correct variable properties' do
expect(@first_variable['key']).to eq "TRIGGER_KEY_1"
expect(@first_variable['value']).to eq "TRIGGER_VALUE_1"
expect(@first_variable['public']).to eq false
end
end
context 'with no variable values' do
context 'with variables and user is not a mantainer' do
before do
create(:ci_pipeline_variable, pipeline: pipeline, key: :TRIGGER_KEY_1, value: 'TRIGGER_VALUE_1')
get_show(id: job.id, format: :json)
end
it 'exposes trigger information and variables' do
before(:each) do
@first_variable = json_response['trigger']['variables'].first
end
it 'returns a job_detail' do
expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('job/job_details')
end
it 'exposes trigger information and variables' do
expect(json_response['trigger']['short_token']).to eq 'toke'
expect(json_response['trigger']['variables'].length).to eq 1
expect(json_response['trigger']['variables'].first['key']).to eq "TRIGGER_KEY_1"
expect(json_response['trigger']['variables'].first['value']).to be_nil
expect(json_response['trigger']['variables'].first['public']).to eq false
end
it 'exposes correct variable properties' do
expect(@first_variable['key']).to eq "TRIGGER_KEY_1"
expect(@first_variable['value']).to be_nil
expect(@first_variable['public']).to eq false
end
end
end

View file

@ -344,36 +344,10 @@ describe 'Jobs', :clean_gitlab_redis_shared_state do
end
end
describe 'Variables when user is a maintainer' do
before do
project.add_maintainer(user)
end
let!(:trigger_request) { create(:ci_trigger_request) }
let!(:job) do
create(:ci_build, pipeline: pipeline, trigger_request: trigger_request)
end
shared_examples 'job with outdated deployment' do
it 'shows a link for the job' do
expect(page).to have_content('Token')
expect(page).to have_content('Variables')
click_button 'Reveal values'
expect(page).to have_css('.js-reveal-variables')
expect(page).to have_selector('.js-build-variable', text: 'TRIGGER_KEY_1')
expect(page).to have_selector('.js-build-value', text: 'TRIGGER_VALUE_1')
end
end
end
describe 'Variables' do
describe 'Pipeline trigger variables when user is not a maintainer' do
let(:trigger_request) { create(:ci_trigger_request) }
let(:job) do
create(:ci_build, pipeline: pipeline, trigger_request: trigger_request)
end
let(:job) { create(:ci_build, pipeline: pipeline, trigger_request: trigger_request) }
shared_examples 'expected variables behavior' do
it 'renders a hidden value with no reveal values button', :js do
@ -406,6 +380,53 @@ describe 'Jobs', :clean_gitlab_redis_shared_state do
end
end
describe 'Pipeline trigger variables when user is a maintainer' do
let(:trigger_request) { create(:ci_trigger_request) }
let(:job) { create(:ci_build, pipeline: pipeline, trigger_request: trigger_request) }
shared_examples 'expected variables behavior when maintainer' do
it 'renders a hidden value with a reveal values button', :js do
expect(page).to have_content('Token')
expect(page).to have_content('Variables')
expect(page).to have_css('.js-reveal-variables')
expect(page).to have_selector('.js-build-variable', text: 'TRIGGER_KEY_1')
expect(page).to have_selector('.js-build-value', text: '••••••')
end
it 'reveals values on button click', :js do
click_button 'Reveal values'
expect(page).to have_selector('.js-build-variable', text: 'TRIGGER_KEY_1')
expect(page).to have_selector('.js-build-value', text: 'TRIGGER_VALUE_1')
end
end
context 'when variables are stored in trigger_request' do
before do
project.add_maintainer(user)
trigger_request.update_attribute(:variables, { 'TRIGGER_KEY_1' => 'TRIGGER_VALUE_1' } )
visit project_job_path(project, job)
end
it_behaves_like 'expected variables behavior when maintainer'
end
context 'when variables are stored in pipeline_variables' do
before do
project.add_maintainer(user)
create(:ci_pipeline_variable, pipeline: pipeline, key: 'TRIGGER_KEY_1', value: 'TRIGGER_VALUE_1')
visit project_job_path(project, job)
end
it_behaves_like 'expected variables behavior when maintainer'
end
end
context 'when job starts environment', :js do
let(:environment) { create(:environment, name: 'production', project: project) }