debian-mirror-gitlab/spec/serializers/integrations/field_entity_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

150 lines
4.4 KiB
Ruby
Raw Normal View History

2020-06-23 00:09:42 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-04-23 21:23:45 +05:30
RSpec.describe Integrations::FieldEntity, feature_category: :integrations do
2022-07-23 23:45:48 +05:30
let(:request) { EntityRequest.new(integration: integration) }
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
subject { described_class.new(field, request: request, integration: integration).as_json }
2020-06-23 00:09:42 +05:30
before do
2022-07-23 23:45:48 +05:30
allow(request).to receive(:integration).and_return(integration)
2020-06-23 00:09:42 +05:30
end
describe '#as_json' do
2022-07-23 23:45:48 +05:30
context 'with Jira integration' do
2023-01-13 00:05:48 +05:30
let(:integration) { build(:jira_integration) }
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
context 'with field with type text' do
2021-09-30 23:02:18 +05:30
let(:field) { integration_field('username') }
2020-06-23 00:09:42 +05:30
it 'exposes correct attributes' do
expected_hash = {
2022-05-07 20:08:51 +05:30
section: 'connection',
2020-06-23 00:09:42 +05:30
type: 'text',
name: 'username',
2023-04-23 21:23:45 +05:30
title: 'Username or email',
2021-04-29 21:17:54 +05:30
placeholder: nil,
2023-04-23 21:23:45 +05:30
help: 'Username for the server version or an email for the cloud version',
2020-06-23 00:09:42 +05:30
required: true,
choices: nil,
2021-12-11 22:18:48 +05:30
value: 'jira_username',
checkbox_label: nil
2020-06-23 00:09:42 +05:30
}
is_expected.to eq(expected_hash)
end
end
2022-07-23 23:45:48 +05:30
context 'with field with type password' do
2021-09-30 23:02:18 +05:30
let(:field) { integration_field('password') }
2020-06-23 00:09:42 +05:30
it 'exposes correct attributes but hides password' do
expected_hash = {
2022-05-07 20:08:51 +05:30
section: 'connection',
2020-06-23 00:09:42 +05:30
type: 'password',
name: 'password',
2021-04-29 21:17:54 +05:30
title: 'Enter new password or API token',
placeholder: nil,
help: 'Leave blank to use your current password or API token.',
2020-06-23 00:09:42 +05:30
required: true,
choices: nil,
2021-12-11 22:18:48 +05:30
value: 'true',
checkbox_label: nil
2020-06-23 00:09:42 +05:30
}
is_expected.to eq(expected_hash)
end
end
end
2022-07-23 23:45:48 +05:30
context 'with EmailsOnPush integration' do
2023-01-13 00:05:48 +05:30
let(:integration) { build(:emails_on_push_integration, send_from_committer_email: '1') }
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
context 'with field with type checkbox' do
2021-09-30 23:02:18 +05:30
let(:field) { integration_field('send_from_committer_email') }
2020-06-23 00:09:42 +05:30
2020-07-28 23:09:34 +05:30
it 'exposes correct attributes and casts value to Boolean' do
2020-06-23 00:09:42 +05:30
expected_hash = {
2022-05-07 20:08:51 +05:30
section: nil,
2020-06-23 00:09:42 +05:30
type: 'checkbox',
name: 'send_from_committer_email',
title: 'Send from committer',
placeholder: nil,
required: nil,
choices: nil,
2021-12-11 22:18:48 +05:30
value: 'true',
checkbox_label: nil
2020-06-23 00:09:42 +05:30
}
is_expected.to include(expected_hash)
2022-07-23 23:45:48 +05:30
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-23 00:09:42 +05:30
end
end
2022-07-23 23:45:48 +05:30
context 'with field with type select' do
2021-09-30 23:02:18 +05:30
let(:field) { integration_field('branches_to_be_notified') }
2020-06-23 00:09:42 +05:30
it 'exposes correct attributes' do
expected_hash = {
2022-05-07 20:08:51 +05:30
section: nil,
2020-06-23 00:09:42 +05:30
type: 'select',
name: 'branches_to_be_notified',
2021-12-11 22:18:48 +05:30
title: 'Branches for which notifications are to be sent',
2020-06-23 00:09:42 +05:30
placeholder: nil,
required: nil,
2022-07-23 23:45:48 +05:30
choices: [
['All branches', 'all'],
['Default branch', 'default'],
['Protected branches', 'protected'],
['Default branch and protected branches', 'default_and_protected']
],
2020-06-23 00:09:42 +05:30
help: nil,
2021-12-11 22:18:48 +05:30
value: nil,
checkbox_label: nil
2020-06-23 00:09:42 +05:30
}
is_expected.to eq(expected_hash)
end
end
end
2023-01-13 00:05:48 +05:30
context 'with chat integration' do
let(:integration) { build(:mattermost_integration) }
let(:field) { integration_field('webhook') }
it 'exposes correct attributes but masks webhook' do
expected_hash = {
section: nil,
type: 'text',
name: 'webhook',
title: nil,
placeholder: nil,
help: 'http://mattermost.example.com/hooks/',
required: true,
choices: nil,
value: '************',
checkbox_label: nil
}
is_expected.to eq(expected_hash)
end
context 'when webhook was not set' do
let(:integration) { build(:mattermost_integration, webhook: nil) }
it 'does not show the masked webhook' do
expect(subject[:value]).to be_nil
end
end
end
2020-06-23 00:09:42 +05:30
end
2021-09-30 23:02:18 +05:30
def integration_field(name)
2022-08-13 15:12:31 +05:30
integration.form_fields.find { |f| f[:name] == name }
2021-09-30 23:02:18 +05:30
end
2020-06-23 00:09:42 +05:30
end