Commit 2b5f4e40 authored by Justin Ho's avatar Justin Ho

Extract some logic to helpers and refactor specs

As suggested in code review
parent e99efc34
......@@ -98,6 +98,24 @@ module ServicesHelper
end
end
def trigger_events_for_service
return [] unless Feature.enabled?(:integration_form_refactor, @project)
ServiceEventSerializer.new(service: @service).represent(@service.configurable_events).to_json
end
def fields_for_service
return [] unless Feature.enabled?(:integration_form_refactor, @project)
ServiceFieldSerializer.new(service: @service).represent(@service.global_fields).to_json
end
def show_service_trigger_events
return false if @service.is_a?(JiraService) || Feature.enabled?(:integration_form_refactor, @project)
@service.configurable_events.present?
end
extend self
end
......
= form_errors(@service)
- trigger_events = Feature.enabled?(:integration_form_refactor, @project) ? ServiceEventSerializer.new(service: @service).represent(@service.configurable_events).to_json : []
- fields = Feature.enabled?(:integration_form_refactor, @project) ? ServiceFieldSerializer.new(service: @service).represent(@service.global_fields).to_json : []
- if lookup_context.template_exists?('help', "projects/services/#{@service.to_param}", true)
= render "projects/services/#{@service.to_param}/help", subject: @service
......@@ -11,9 +9,9 @@
.service-settings
.js-vue-integration-settings{ data: { show_active: @service.show_active_box?.to_s, activated: (@service.active || @service.new_record?).to_s, type: @service.to_param, merge_request_events: @service.merge_requests_events.to_s,
commit_events: @service.commit_events.to_s, enable_comments: @service.comment_on_event_enabled.to_s, comment_detail: @service.comment_detail, trigger_events: trigger_events, fields: fields } }
commit_events: @service.commit_events.to_s, enable_comments: @service.comment_on_event_enabled.to_s, comment_detail: @service.comment_detail, trigger_events: trigger_events_for_service, fields: fields_for_service } }
- if @service.configurable_events.present? && !@service.is_a?(JiraService) && Feature.disabled?(:integration_form_refactor, @project)
- if show_service_trigger_events
.form-group.row
%label.col-form-label.col-sm-2= _('Trigger')
......
......@@ -17,31 +17,42 @@ describe ServiceFieldEntity do
context 'field with type text' do
let(:field) { service.global_fields.find { |field| field[:name] == 'username' } }
let(:expected_hash) do
{
type: 'text',
name: 'username',
title: 'Username or Email',
placeholder: 'Use a username for server version and an email for cloud version',
required: true,
choices: nil,
help: nil,
value: 'jira_username'
}
end
it 'exposes correct attributes' do
expect(subject[:type]).to eq('text')
expect(subject[:name]).to eq('username')
expect(subject[:title]).to eq('Username or Email')
expect(subject[:placeholder]).to eq('Use a username for server version and an email for cloud version')
expect(subject[:required]).to eq(true)
expect(subject[:choices]).to be_nil
expect(subject[:help]).to be_nil
expect(subject[:value]).to eq('jira_username')
is_expected.to eq(expected_hash)
end
end
context 'field with type password' do
let(:field) { service.global_fields.find { |field| field[:name] == 'password' } }
let(:expected_hash) do
{
type: 'password',
name: 'password',
title: 'Password or API token',
placeholder: 'Use a password for server version and an API token for cloud version',
required: true,
choices: nil,
help: nil,
value: 'true'
}
end
it 'exposes correct attributes but hides password' do
expect(subject[:type]).to eq('password')
expect(subject[:name]).to eq('password')
expect(subject[:title]).to eq('Password or API token')
expect(subject[:placeholder]).to eq('Use a password for server version and an API token for cloud version')
expect(subject[:required]).to eq(true)
expect(subject[:choices]).to be_nil
expect(subject[:help]).to be_nil
expect(subject[:value]).to eq('true')
is_expected.to eq(expected_hash)
end
end
end
......@@ -51,31 +62,41 @@ describe ServiceFieldEntity do
context 'field with type checkbox' do
let(:field) { service.global_fields.find { |field| field[:name] == 'send_from_committer_email' } }
let(:expected_hash) do
{
type: 'checkbox',
name: 'send_from_committer_email',
title: 'Send from committer',
placeholder: nil,
required: nil,
choices: nil,
value: true
}
end
it 'exposes correct attributes' do
expect(subject[:type]).to eq('checkbox')
expect(subject[:name]).to eq('send_from_committer_email')
expect(subject[:title]).to eq('Send from committer')
expect(subject[:placeholder]).to be_nil
expect(subject[:required]).to be_nil
expect(subject[:choices]).to be_nil
is_expected.to include(expected_hash)
expect(subject[:help]).to include("Send notifications from the committer's email address if the domain is part of the domain GitLab is running on")
expect(subject[:value]).to eq(true)
end
end
context 'field with type select' do
let(:field) { service.global_fields.find { |field| field[:name] == 'branches_to_be_notified' } }
let(:expected_hash) do
{
type: 'select',
name: 'branches_to_be_notified',
title: nil,
placeholder: nil,
required: nil,
choices: [['All branches', 'all'], ['Default branch', 'default'], ['Protected branches', 'protected'], ['Default branch and protected branches', 'default_and_protected']],
help: nil,
value: nil
}
end
it 'exposes correct attributes' do
expect(subject[:type]).to eq('select')
expect(subject[:name]).to eq('branches_to_be_notified')
expect(subject[:title]).to be_nil
expect(subject[:placeholder]).to be_nil
expect(subject[:required]).to be_nil
expect(subject[:choices]).to eq([['All branches', 'all'], ['Default branch', 'default'], ['Protected branches', 'protected'], ['Default branch and protected branches', 'default_and_protected']])
expect(subject[:help]).to be_nil
expect(subject[:value]).to be_nil
is_expected.to eq(expected_hash)
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