2019-07-25 01:24:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-08-25 21:42:46 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
describe 'Triggers', :js do
|
2017-03-07 08:02:56 -05:00
|
|
|
let(:trigger_title) { 'trigger desc' }
|
2015-09-29 04:37:31 -04:00
|
|
|
let(:user) { create(:user) }
|
2017-03-07 08:02:56 -05:00
|
|
|
let(:user2) { create(:user) }
|
|
|
|
let(:guest_user) { create(:user) }
|
2017-06-14 14:18:56 -04:00
|
|
|
|
|
|
|
before do
|
2017-06-19 22:06:13 -04:00
|
|
|
sign_in(user)
|
2015-09-15 15:22:51 -04:00
|
|
|
|
2017-08-02 15:55:11 -04:00
|
|
|
@project = create(:project)
|
2018-07-11 10:36:08 -04:00
|
|
|
@project.add_maintainer(user)
|
|
|
|
@project.add_maintainer(user2)
|
2017-12-22 03:18:28 -05:00
|
|
|
@project.add_guest(guest_user)
|
2017-06-05 14:44:29 -04:00
|
|
|
|
2017-06-29 13:06:35 -04:00
|
|
|
visit project_settings_ci_cd_path(@project)
|
2015-08-25 21:42:46 -04:00
|
|
|
end
|
|
|
|
|
2017-03-07 08:02:56 -05:00
|
|
|
describe 'create trigger workflow' do
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'prevents adding new trigger with no description' do
|
2017-03-07 08:02:56 -05:00
|
|
|
fill_in 'trigger_description', with: ''
|
|
|
|
click_button 'Add trigger'
|
|
|
|
|
|
|
|
# See if input has error due to empty value
|
2018-04-20 16:15:04 -04:00
|
|
|
expect(page.find('form.gl-show-field-errors .gl-field-error')).to be_visible
|
2017-03-07 08:02:56 -05:00
|
|
|
end
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'adds new trigger with description' do
|
2017-03-07 08:02:56 -05:00
|
|
|
fill_in 'trigger_description', with: 'trigger desc'
|
|
|
|
click_button 'Add trigger'
|
|
|
|
|
|
|
|
# See if "trigger creation successful" message displayed and description and owner are correct
|
|
|
|
expect(page.find('.flash-notice')).to have_content 'Trigger was created successfully.'
|
|
|
|
expect(page.find('.triggers-list')).to have_content 'trigger desc'
|
2017-06-19 22:06:13 -04:00
|
|
|
expect(page.find('.triggers-list .trigger-owner')).to have_content user.name
|
2017-03-07 08:02:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'edit trigger workflow' do
|
|
|
|
let(:new_trigger_title) { 'new trigger' }
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'click on edit trigger opens edit trigger page' do
|
2017-03-07 08:02:56 -05:00
|
|
|
create(:ci_trigger, owner: user, project: @project, description: trigger_title)
|
2017-06-29 13:06:35 -04:00
|
|
|
visit project_settings_ci_cd_path(@project)
|
2017-03-07 08:02:56 -05:00
|
|
|
|
|
|
|
# See if edit page has correct descrption
|
2017-09-29 14:07:04 -04:00
|
|
|
find('a[title="Edit"]').send_keys(:return)
|
2017-03-07 08:02:56 -05:00
|
|
|
expect(page.find('#trigger_description').value).to have_content 'trigger desc'
|
|
|
|
end
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'edit trigger and save' do
|
2017-03-07 08:02:56 -05:00
|
|
|
create(:ci_trigger, owner: user, project: @project, description: trigger_title)
|
2017-06-29 13:06:35 -04:00
|
|
|
visit project_settings_ci_cd_path(@project)
|
2017-03-07 08:02:56 -05:00
|
|
|
|
|
|
|
# See if edit page opens, then fill in new description and save
|
2017-09-29 14:07:04 -04:00
|
|
|
find('a[title="Edit"]').send_keys(:return)
|
2017-03-07 08:02:56 -05:00
|
|
|
fill_in 'trigger_description', with: new_trigger_title
|
|
|
|
click_button 'Save trigger'
|
|
|
|
|
|
|
|
# See if "trigger updated successfully" message displayed and description and owner are correct
|
|
|
|
expect(page.find('.flash-notice')).to have_content 'Trigger was successfully updated.'
|
|
|
|
expect(page.find('.triggers-list')).to have_content new_trigger_title
|
2017-06-19 22:06:13 -04:00
|
|
|
expect(page.find('.triggers-list .trigger-owner')).to have_content user.name
|
2017-03-07 08:02:56 -05:00
|
|
|
end
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'edit "legacy" trigger and save' do
|
2017-03-07 08:02:56 -05:00
|
|
|
# Create new trigger without owner association, i.e. Legacy trigger
|
2019-06-25 07:41:11 -04:00
|
|
|
create(:ci_trigger, owner: user, project: @project).update_attribute(:owner, nil)
|
2017-06-29 13:06:35 -04:00
|
|
|
visit project_settings_ci_cd_path(@project)
|
2017-03-07 08:02:56 -05:00
|
|
|
|
|
|
|
# See if the trigger can be edited and description is blank
|
2017-09-29 14:07:04 -04:00
|
|
|
find('a[title="Edit"]').send_keys(:return)
|
2017-03-07 08:02:56 -05:00
|
|
|
expect(page.find('#trigger_description').value).to have_content ''
|
|
|
|
|
|
|
|
# See if trigger can be updated with description and saved successfully
|
|
|
|
fill_in 'trigger_description', with: new_trigger_title
|
|
|
|
click_button 'Save trigger'
|
|
|
|
expect(page.find('.flash-notice')).to have_content 'Trigger was successfully updated.'
|
|
|
|
expect(page.find('.triggers-list')).to have_content new_trigger_title
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'trigger "Revoke" workflow' do
|
2017-08-10 18:31:42 -04:00
|
|
|
before do
|
2017-03-07 08:02:56 -05:00
|
|
|
create(:ci_trigger, owner: user2, project: @project, description: trigger_title)
|
2017-06-29 13:06:35 -04:00
|
|
|
visit project_settings_ci_cd_path(@project)
|
2017-03-07 08:02:56 -05:00
|
|
|
end
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'button "Revoke" has correct alert' do
|
2017-03-07 08:02:56 -05:00
|
|
|
expected_alert = 'By revoking a trigger you will break any processes making use of it. Are you sure?'
|
|
|
|
expect(page.find('a.btn-trigger-revoke')['data-confirm']).to eq expected_alert
|
|
|
|
end
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'revoke trigger' do
|
2017-03-07 08:02:56 -05:00
|
|
|
# See if "Revoke" on trigger works post trigger creation
|
|
|
|
page.accept_confirm do
|
2017-09-29 14:07:04 -04:00
|
|
|
find('a.btn-trigger-revoke').send_keys(:return)
|
2017-03-07 08:02:56 -05:00
|
|
|
end
|
2017-09-29 14:07:04 -04:00
|
|
|
|
|
|
|
expect(page.find('.flash-notice')).to have_content 'Trigger removed'
|
|
|
|
expect(page).to have_selector('p.settings-message.text-center.append-bottom-default')
|
2017-03-07 08:02:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'show triggers workflow' do
|
2019-06-25 07:41:11 -04:00
|
|
|
before do
|
|
|
|
stub_feature_flags(use_legacy_pipeline_triggers: false)
|
|
|
|
end
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'contains trigger description placeholder' do
|
2017-03-07 08:02:56 -05:00
|
|
|
expect(page.find('#trigger_description')['placeholder']).to eq 'Trigger description'
|
|
|
|
end
|
|
|
|
|
2019-06-25 07:41:11 -04:00
|
|
|
it 'show "invalid" badge for legacy trigger' do
|
|
|
|
create(:ci_trigger, owner: user, project: @project).update_attribute(:owner, nil)
|
2017-06-29 13:06:35 -04:00
|
|
|
visit project_settings_ci_cd_path(@project)
|
2017-03-07 08:02:56 -05:00
|
|
|
|
2019-06-25 07:41:11 -04:00
|
|
|
expect(page.find('.triggers-list')).to have_content 'invalid'
|
2017-03-07 08:02:56 -05:00
|
|
|
end
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'show "invalid" badge for trigger with owner having insufficient permissions' do
|
2017-03-07 08:02:56 -05:00
|
|
|
create(:ci_trigger, owner: guest_user, project: @project, description: trigger_title)
|
2017-06-29 13:06:35 -04:00
|
|
|
visit project_settings_ci_cd_path(@project)
|
2017-03-07 08:02:56 -05:00
|
|
|
|
|
|
|
# See if trigger without owner (i.e. legacy) shows "legacy" badge and is non-editable
|
|
|
|
expect(page.find('.triggers-list')).to have_content 'invalid'
|
|
|
|
expect(page.find('.triggers-list')).not_to have_selector('a[title="Edit"]')
|
|
|
|
end
|
|
|
|
|
2019-06-25 07:41:11 -04:00
|
|
|
it 'do not show "Edit" or full token for legacy trigger' do
|
|
|
|
create(:ci_trigger, owner: user, project: @project, description: trigger_title)
|
|
|
|
.update_attribute(:owner, nil)
|
|
|
|
visit project_settings_ci_cd_path(@project)
|
|
|
|
|
|
|
|
# See if trigger not owned shows only first few token chars and doesn't have copy-to-clipboard button
|
|
|
|
expect(page.find('.triggers-list')).to have_content(@project.triggers.first.token[0..3])
|
|
|
|
expect(page.find('.triggers-list')).not_to have_selector('button.btn-clipboard')
|
|
|
|
|
|
|
|
# See if trigger is non-editable
|
|
|
|
expect(page.find('.triggers-list')).not_to have_selector('a[title="Edit"]')
|
|
|
|
end
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'do not show "Edit" or full token for not owned trigger' do
|
2017-03-07 08:02:56 -05:00
|
|
|
# Create trigger with user different from current_user
|
|
|
|
create(:ci_trigger, owner: user2, project: @project, description: trigger_title)
|
2017-06-29 13:06:35 -04:00
|
|
|
visit project_settings_ci_cd_path(@project)
|
2017-03-07 08:02:56 -05:00
|
|
|
|
|
|
|
# See if trigger not owned by current_user shows only first few token chars and doesn't have copy-to-clipboard button
|
|
|
|
expect(page.find('.triggers-list')).to have_content(@project.triggers.first.token[0..3])
|
|
|
|
expect(page.find('.triggers-list')).not_to have_selector('button.btn-clipboard')
|
|
|
|
|
|
|
|
# See if trigger owner name doesn't match with current_user and trigger is non-editable
|
2017-06-19 22:06:13 -04:00
|
|
|
expect(page.find('.triggers-list .trigger-owner')).not_to have_content user.name
|
2017-03-07 08:02:56 -05:00
|
|
|
expect(page.find('.triggers-list')).not_to have_selector('a[title="Edit"]')
|
|
|
|
end
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'show "Edit" and full token for owned trigger' do
|
2017-03-07 08:02:56 -05:00
|
|
|
create(:ci_trigger, owner: user, project: @project, description: trigger_title)
|
2017-06-29 13:06:35 -04:00
|
|
|
visit project_settings_ci_cd_path(@project)
|
2017-03-07 08:02:56 -05:00
|
|
|
|
|
|
|
# See if trigger shows full token and has copy-to-clipboard button
|
|
|
|
expect(page.find('.triggers-list')).to have_content @project.triggers.first.token
|
|
|
|
expect(page.find('.triggers-list')).to have_selector('button.btn-clipboard')
|
2015-08-25 21:42:46 -04:00
|
|
|
|
2017-03-07 08:02:56 -05:00
|
|
|
# See if trigger owner name matches with current_user and is editable
|
2017-06-19 22:06:13 -04:00
|
|
|
expect(page.find('.triggers-list .trigger-owner')).to have_content user.name
|
2017-03-07 08:02:56 -05:00
|
|
|
expect(page.find('.triggers-list')).to have_selector('a[title="Edit"]')
|
2015-08-25 21:42:46 -04:00
|
|
|
end
|
2019-06-25 07:41:11 -04:00
|
|
|
|
|
|
|
context 'when :use_legacy_pipeline_triggers feature flag is enabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(use_legacy_pipeline_triggers: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'show "legacy" badge for legacy trigger' do
|
|
|
|
create(:ci_trigger, owner: nil, project: @project)
|
|
|
|
visit project_settings_ci_cd_path(@project)
|
|
|
|
|
|
|
|
# See if trigger without owner (i.e. legacy) shows "legacy" badge and is editable
|
|
|
|
expect(page.find('.triggers-list')).to have_content 'legacy'
|
|
|
|
expect(page.find('.triggers-list')).to have_selector('a[title="Edit"]')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'show "invalid" badge for trigger with owner having insufficient permissions' do
|
|
|
|
create(:ci_trigger, owner: guest_user, project: @project, description: trigger_title)
|
|
|
|
visit project_settings_ci_cd_path(@project)
|
|
|
|
|
|
|
|
# See if trigger without owner (i.e. legacy) shows "legacy" badge and is non-editable
|
|
|
|
expect(page.find('.triggers-list')).to have_content 'invalid'
|
|
|
|
expect(page.find('.triggers-list')).not_to have_selector('a[title="Edit"]')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'do not show "Edit" or full token for not owned trigger' do
|
|
|
|
# Create trigger with user different from current_user
|
|
|
|
create(:ci_trigger, owner: user2, project: @project, description: trigger_title)
|
|
|
|
visit project_settings_ci_cd_path(@project)
|
|
|
|
|
|
|
|
# See if trigger not owned by current_user shows only first few token chars and doesn't have copy-to-clipboard button
|
|
|
|
expect(page.find('.triggers-list')).to have_content(@project.triggers.first.token[0..3])
|
|
|
|
expect(page.find('.triggers-list')).not_to have_selector('button.btn-clipboard')
|
|
|
|
|
|
|
|
# See if trigger owner name doesn't match with current_user and trigger is non-editable
|
|
|
|
expect(page.find('.triggers-list .trigger-owner')).not_to have_content user.name
|
|
|
|
expect(page.find('.triggers-list')).not_to have_selector('a[title="Edit"]')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'show "Edit" and full token for owned trigger' do
|
|
|
|
create(:ci_trigger, owner: user, project: @project, description: trigger_title)
|
|
|
|
visit project_settings_ci_cd_path(@project)
|
|
|
|
|
|
|
|
# See if trigger shows full token and has copy-to-clipboard button
|
|
|
|
expect(page.find('.triggers-list')).to have_content @project.triggers.first.token
|
|
|
|
expect(page.find('.triggers-list')).to have_selector('button.btn-clipboard')
|
|
|
|
|
|
|
|
# See if trigger owner name matches with current_user and is editable
|
|
|
|
expect(page.find('.triggers-list .trigger-owner')).to have_content user.name
|
|
|
|
expect(page.find('.triggers-list')).to have_selector('a[title="Edit"]')
|
|
|
|
end
|
|
|
|
end
|
2015-08-25 21:42:46 -04:00
|
|
|
end
|
|
|
|
end
|