2020-06-03 05:08:47 -04:00
# frozen_string_literal: true
require 'spec_helper'
2020-06-24 02:09:01 -04:00
RSpec . describe ServiceFieldEntity do
2020-06-03 05:08:47 -04:00
let ( :request ) { double ( 'request' ) }
2021-06-18 11:10:16 -04:00
subject { described_class . new ( field , request : request , service : integration ) . as_json }
2020-06-03 05:08:47 -04:00
before do
2021-06-18 11:10:16 -04:00
allow ( request ) . to receive ( :service ) . and_return ( integration )
2020-06-03 05:08:47 -04:00
end
describe '#as_json' do
context 'Jira Service' do
2021-06-18 11:10:16 -04:00
let ( :integration ) { create ( :jira_integration ) }
2020-06-03 05:08:47 -04:00
context 'field with type text' do
2021-06-18 11:10:16 -04:00
let ( :field ) { integration_field ( 'username' ) }
2020-06-03 05:08:47 -04:00
it 'exposes correct attributes' do
expected_hash = {
type : 'text' ,
name : 'username' ,
title : 'Username or Email' ,
2021-04-08 17:09:13 -04:00
placeholder : nil ,
help : 'Use a username for server version and an email for cloud version.' ,
2020-06-03 05:08:47 -04:00
required : true ,
choices : nil ,
2021-10-20 14:12:31 -04:00
value : 'jira_username' ,
checkbox_label : nil
2020-06-03 05:08:47 -04:00
}
is_expected . to eq ( expected_hash )
end
end
context 'field with type password' do
2021-06-18 11:10:16 -04:00
let ( :field ) { integration_field ( 'password' ) }
2020-06-03 05:08:47 -04:00
it 'exposes correct attributes but hides password' do
expected_hash = {
type : 'password' ,
name : 'password' ,
2021-03-25 08:09:19 -04:00
title : 'Enter new password or API token' ,
2021-04-08 17:09:13 -04:00
placeholder : nil ,
help : 'Leave blank to use your current password or API token.' ,
2020-06-03 05:08:47 -04:00
required : true ,
choices : nil ,
2021-10-20 14:12:31 -04:00
value : 'true' ,
checkbox_label : nil
2020-06-03 05:08:47 -04:00
}
is_expected . to eq ( expected_hash )
end
end
end
context 'EmailsOnPush Service' do
2021-06-16 14:10:35 -04:00
let ( :integration ) { create ( :emails_on_push_integration , send_from_committer_email : '1' ) }
2020-06-03 05:08:47 -04:00
context 'field with type checkbox' do
2021-06-18 11:10:16 -04:00
let ( :field ) { integration_field ( 'send_from_committer_email' ) }
2020-06-03 05:08:47 -04:00
2020-07-14 20:09:23 -04:00
it 'exposes correct attributes and casts value to Boolean' do
2020-06-03 05:08:47 -04:00
expected_hash = {
type : 'checkbox' ,
name : 'send_from_committer_email' ,
title : 'Send from committer' ,
placeholder : nil ,
required : nil ,
choices : nil ,
2021-10-20 14:12:31 -04:00
value : 'true' ,
checkbox_label : nil
2020-06-03 05:08:47 -04:00
}
is_expected . to include ( expected_hash )
2021-04-08 14:09:32 -04:00
expect ( subject [ :help ] ) . to include ( " Send notifications from the committer's email address if the domain matches the domain used by your GitLab instance " )
2020-06-03 05:08:47 -04:00
end
end
context 'field with type select' do
2021-06-18 11:10:16 -04:00
let ( :field ) { integration_field ( 'branches_to_be_notified' ) }
2020-06-03 05:08:47 -04:00
it 'exposes correct attributes' do
expected_hash = {
type : 'select' ,
name : 'branches_to_be_notified' ,
2021-10-27 08:09:41 -04:00
title : 'Branches for which notifications are to be sent' ,
2020-06-03 05:08:47 -04:00
placeholder : nil ,
required : nil ,
choices : [ [ 'All branches' , 'all' ] , [ 'Default branch' , 'default' ] , [ 'Protected branches' , 'protected' ] , [ 'Default branch and protected branches' , 'default_and_protected' ] ] ,
help : nil ,
2021-10-20 14:12:31 -04:00
value : nil ,
checkbox_label : nil
2020-06-03 05:08:47 -04:00
}
is_expected . to eq ( expected_hash )
end
end
end
end
2021-06-18 11:10:16 -04:00
def integration_field ( name )
integration . global_fields . find { | f | f [ :name ] == name }
end
2020-06-03 05:08:47 -04:00
end