Commit 1bf28d48 authored by jhampton's avatar jhampton

Adjusts tests per MR feedback

- Updates tests / applies patterns per MR feedback
parent 242bead1
......@@ -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
......
......@@ -344,65 +344,86 @@ 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
describe 'Pipeline trigger variables when user is not a maintainer' do
let(:trigger_request) { create(:ci_trigger_request) }
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 'job with outdated deployment' do
it 'shows a link for the job' do
shared_examples 'expected variables behavior' do
it 'renders a hidden value with no reveal values button', :js do
expect(page).to have_content('Token')
expect(page).to have_content('Variables')
expect(page).not_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
end
click_button 'Reveal values'
context 'when variables are stored in trigger_request' do
before do
trigger_request.update_attribute(:variables, { 'TRIGGER_KEY_1' => 'TRIGGER_VALUE_1' } )
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')
visit project_job_path(project, job)
end
it_behaves_like 'expected variables behavior'
end
context 'when variables are stored in pipeline_variables' do
before do
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'
end
end
describe 'Variables' do
describe 'Pipeline trigger variables when user is 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
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).not_to have_css('.js-reveal-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'
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'
it_behaves_like 'expected variables behavior when maintainer'
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