2020-11-24 15:15:51 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
RSpec.describe JiraConnectInstallation, feature_category: :integrations do
|
2020-11-24 15:15:51 +05:30
|
|
|
describe 'associations' do
|
|
|
|
it { is_expected.to have_many(:subscriptions).class_name('JiraConnectSubscription') }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'validations' do
|
|
|
|
it { is_expected.to validate_presence_of(:client_key) }
|
|
|
|
it { is_expected.to validate_uniqueness_of(:client_key) }
|
|
|
|
it { is_expected.to validate_presence_of(:shared_secret) }
|
|
|
|
it { is_expected.to validate_presence_of(:base_url) }
|
|
|
|
|
|
|
|
it { is_expected.to allow_value('https://test.atlassian.net').for(:base_url) }
|
|
|
|
it { is_expected.not_to allow_value('not/a/url').for(:base_url) }
|
2021-10-27 15:23:28 +05:30
|
|
|
|
|
|
|
it { is_expected.to allow_value('https://test.atlassian.net').for(:instance_url) }
|
|
|
|
it { is_expected.not_to allow_value('not/a/url').for(:instance_url) }
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
describe 'scopes' do
|
|
|
|
let_it_be(:jira_connect_subscription) { create(:jira_connect_subscription) }
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
describe '.for_project' do
|
|
|
|
let_it_be(:other_group) { create(:group) }
|
|
|
|
let_it_be(:parent_group) { create(:group) }
|
|
|
|
let_it_be(:group) { create(:group, parent: parent_group) }
|
|
|
|
let_it_be(:project) { create(:project, group: group) }
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
subject { described_class.for_project(project) }
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
it 'returns installations with subscriptions for project' do
|
|
|
|
sub_on_project_namespace = create(:jira_connect_subscription, namespace: group)
|
|
|
|
sub_on_ancestor_namespace = create(:jira_connect_subscription, namespace: parent_group)
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
# Subscription on other group that shouldn't be returned
|
|
|
|
create(:jira_connect_subscription, namespace: other_group)
|
|
|
|
|
|
|
|
expect(subject).to contain_exactly(
|
|
|
|
sub_on_project_namespace.installation, sub_on_ancestor_namespace.installation
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns distinct installations' do
|
|
|
|
subscription = create(:jira_connect_subscription, namespace: group)
|
|
|
|
create(:jira_connect_subscription, namespace: parent_group, installation: subscription.installation)
|
|
|
|
|
|
|
|
expect(subject).to contain_exactly(subscription.installation)
|
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
describe '.direct_installations' do
|
|
|
|
subject { described_class.direct_installations }
|
|
|
|
|
|
|
|
it { is_expected.to contain_exactly(jira_connect_subscription.installation) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.proxy_installations' do
|
|
|
|
subject { described_class.proxy_installations }
|
|
|
|
|
|
|
|
it { is_expected.to be_empty }
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
context 'with an installation on a self-managed instance' do
|
|
|
|
let_it_be(:installation) { create(:jira_connect_installation, instance_url: 'http://self-managed-gitlab.com') }
|
|
|
|
|
|
|
|
it { is_expected.to contain_exactly(installation) }
|
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
end
|
2022-10-11 01:57:18 +05:30
|
|
|
|
|
|
|
describe '#oauth_authorization_url' do
|
2023-01-13 00:05:48 +05:30
|
|
|
let(:installation) { build(:jira_connect_installation) }
|
2022-10-11 01:57:18 +05:30
|
|
|
|
|
|
|
subject { installation.oauth_authorization_url }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(Gitlab).to receive_message_chain('config.gitlab.url') { 'http://test.host' }
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq('http://test.host') }
|
|
|
|
|
|
|
|
context 'with instance_url' do
|
2023-01-13 00:05:48 +05:30
|
|
|
let(:installation) { build(:jira_connect_installation, instance_url: 'https://gitlab.example.com') }
|
2022-10-11 01:57:18 +05:30
|
|
|
|
|
|
|
it { is_expected.to eq('https://gitlab.example.com') }
|
|
|
|
|
|
|
|
context 'and jira_connect_oauth_self_managed feature is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(jira_connect_oauth_self_managed: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq('http://test.host') }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-11-25 23:54:43 +05:30
|
|
|
|
|
|
|
describe 'audience_url' do
|
2023-01-13 00:05:48 +05:30
|
|
|
let(:installation) { build(:jira_connect_installation) }
|
2022-11-25 23:54:43 +05:30
|
|
|
|
|
|
|
subject(:audience) { installation.audience_url }
|
|
|
|
|
|
|
|
it { is_expected.to eq(nil) }
|
|
|
|
|
|
|
|
context 'when proxy installation' do
|
2023-01-13 00:05:48 +05:30
|
|
|
let(:installation) { build(:jira_connect_installation, instance_url: 'https://example.com') }
|
2022-11-25 23:54:43 +05:30
|
|
|
|
|
|
|
it { is_expected.to eq('https://example.com/-/jira_connect') }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'audience_installed_event_url' do
|
2023-01-13 00:05:48 +05:30
|
|
|
let(:installation) { build(:jira_connect_installation) }
|
2022-11-25 23:54:43 +05:30
|
|
|
|
|
|
|
subject(:audience) { installation.audience_installed_event_url }
|
|
|
|
|
|
|
|
it { is_expected.to eq(nil) }
|
|
|
|
|
|
|
|
context 'when proxy installation' do
|
2023-01-13 00:05:48 +05:30
|
|
|
let(:installation) { build(:jira_connect_installation, instance_url: 'https://example.com') }
|
2022-11-25 23:54:43 +05:30
|
|
|
|
|
|
|
it { is_expected.to eq('https://example.com/-/jira_connect/events/installed') }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
describe 'audience_uninstalled_event_url' do
|
|
|
|
let(:installation) { build(:jira_connect_installation) }
|
|
|
|
|
|
|
|
subject(:audience) { installation.audience_uninstalled_event_url }
|
|
|
|
|
|
|
|
it { is_expected.to eq(nil) }
|
|
|
|
|
|
|
|
context 'when proxy installation' do
|
|
|
|
let(:installation) { build(:jira_connect_installation, instance_url: 'https://example.com') }
|
|
|
|
|
|
|
|
it { is_expected.to eq('https://example.com/-/jira_connect/events/uninstalled') }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
describe 'proxy?' do
|
2023-01-13 00:05:48 +05:30
|
|
|
let(:installation) { build(:jira_connect_installation) }
|
2022-11-25 23:54:43 +05:30
|
|
|
|
|
|
|
subject { installation.proxy? }
|
|
|
|
|
|
|
|
it { is_expected.to eq(false) }
|
|
|
|
|
|
|
|
context 'when instance_url is present' do
|
2023-01-13 00:05:48 +05:30
|
|
|
let(:installation) { build(:jira_connect_installation, instance_url: 'https://example.com') }
|
2022-11-25 23:54:43 +05:30
|
|
|
|
|
|
|
it { is_expected.to eq(true) }
|
|
|
|
end
|
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|