summaryrefslogtreecommitdiff
path: root/spec/controllers/jira_connect
diff options
context:
space:
mode:
Diffstat (limited to 'spec/controllers/jira_connect')
-rw-r--r--spec/controllers/jira_connect/app_descriptor_controller_spec.rb81
-rw-r--r--spec/controllers/jira_connect/branches_controller_spec.rb47
-rw-r--r--spec/controllers/jira_connect/subscriptions_controller_spec.rb48
3 files changed, 168 insertions, 8 deletions
diff --git a/spec/controllers/jira_connect/app_descriptor_controller_spec.rb b/spec/controllers/jira_connect/app_descriptor_controller_spec.rb
index 55bafa938a7..98f4db13a1d 100644
--- a/spec/controllers/jira_connect/app_descriptor_controller_spec.rb
+++ b/spec/controllers/jira_connect/app_descriptor_controller_spec.rb
@@ -4,20 +4,87 @@ require 'spec_helper'
RSpec.describe JiraConnect::AppDescriptorController do
describe '#show' do
+ let(:descriptor) do
+ json_response.deep_symbolize_keys
+ end
+
+ let(:logo_url) { %r{\Ahttp://test\.host/assets/gitlab_logo-\h+\.png\z} }
+
+ let(:common_module_properties) do
+ {
+ homeUrl: 'https://gitlab.com',
+ logoUrl: logo_url,
+ documentationUrl: 'https://docs.gitlab.com/ee/integration/jira/'
+ }
+ end
+
it 'returns JSON app descriptor' do
get :show
expect(response).to have_gitlab_http_status(:ok)
- expect(json_response).to include(
- 'baseUrl' => 'https://test.host/-/jira_connect',
- 'lifecycle' => {
- 'installed' => '/events/installed',
- 'uninstalled' => '/events/uninstalled'
+
+ expect(descriptor).to include(
+ name: Atlassian::JiraConnect.app_name,
+ description: kind_of(String),
+ key: Atlassian::JiraConnect.app_key,
+ baseUrl: 'https://test.host/-/jira_connect',
+ lifecycle: {
+ installed: '/events/installed',
+ uninstalled: '/events/uninstalled'
+ },
+ vendor: {
+ name: 'GitLab',
+ url: 'https://gitlab.com'
},
- 'links' => {
- 'documentation' => 'http://test.host/help/integration/jira_development_panel#gitlabcom-1'
+ links: {
+ documentation: 'http://test.host/help/integration/jira_development_panel#gitlabcom-1'
+ },
+ authentication: {
+ type: 'jwt'
+ },
+ scopes: %w(READ WRITE DELETE),
+ apiVersion: 1,
+ apiMigrations: {
+ 'context-qsh': true,
+ gdpr: true
}
)
+
+ expect(descriptor[:modules]).to include(
+ postInstallPage: {
+ key: 'gitlab-configuration',
+ name: { value: 'GitLab Configuration' },
+ url: '/subscriptions'
+ },
+ jiraDevelopmentTool: {
+ actions: {
+ createBranch: {
+ templateUrl: 'http://test.host/-/jira_connect/branches/new?issue_key={issue.key}&issue_summary={issue.summary}'
+ }
+ },
+ key: 'gitlab-development-tool',
+ application: { value: 'GitLab' },
+ name: { value: 'GitLab' },
+ url: 'https://gitlab.com',
+ logoUrl: logo_url,
+ capabilities: %w(branch commit pull_request)
+ },
+ jiraBuildInfoProvider: common_module_properties.merge(
+ actions: {},
+ name: { value: 'GitLab CI' },
+ key: 'gitlab-ci'
+ ),
+ jiraDeploymentInfoProvider: common_module_properties.merge(
+ actions: {},
+ name: { value: 'GitLab Deployments' },
+ key: 'gitlab-deployments'
+ ),
+ jiraFeatureFlagInfoProvider: common_module_properties.merge(
+ actions: {},
+ name: { value: 'GitLab Feature Flags' },
+ key: 'gitlab-feature-flags'
+ )
+ )
end
end
end
diff --git a/spec/controllers/jira_connect/branches_controller_spec.rb b/spec/controllers/jira_connect/branches_controller_spec.rb
new file mode 100644
index 00000000000..45daf3b5309
--- /dev/null
+++ b/spec/controllers/jira_connect/branches_controller_spec.rb
@@ -0,0 +1,47 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe JiraConnect::BranchesController do
+ describe '#new' do
+ context 'when logged in' do
+ let_it_be(:user) { create(:user) }
+
+ before do
+ sign_in(user)
+ end
+
+ it 'assigns the suggested branch name' do
+ get :new, params: { issue_key: 'ACME-123', issue_summary: 'My Issue !@#$%' }
+
+ expect(response).to be_successful
+ expect(assigns(:new_branch_data)).to include(
+ initial_branch_name: 'ACME-123-my-issue',
+ success_state_svg_path: start_with('/assets/illustrations/merge_requests-')
+ )
+ end
+
+ it 'ignores missing summary' do
+ get :new, params: { issue_key: 'ACME-123' }
+
+ expect(response).to be_successful
+ expect(assigns(:new_branch_data)).to include(initial_branch_name: 'ACME-123')
+ end
+
+ it 'does not set a branch name if key is not passed' do
+ get :new, params: { issue_summary: 'My issue' }
+
+ expect(response).to be_successful
+ expect(assigns(:new_branch_data)).to include('initial_branch_name': nil)
+ end
+ end
+
+ context 'when not logged in' do
+ it 'redirects to the login page' do
+ get :new
+
+ expect(response).to redirect_to(new_user_session_path)
+ end
+ end
+ end
+end
diff --git a/spec/controllers/jira_connect/subscriptions_controller_spec.rb b/spec/controllers/jira_connect/subscriptions_controller_spec.rb
index 95b359a989a..e32915d55a1 100644
--- a/spec/controllers/jira_connect/subscriptions_controller_spec.rb
+++ b/spec/controllers/jira_connect/subscriptions_controller_spec.rb
@@ -7,9 +7,13 @@ RSpec.describe JiraConnect::SubscriptionsController do
describe '#index' do
before do
+ request.headers['Accept'] = content_type
+
get :index, params: { jwt: jwt }
end
+ let(:content_type) { 'text/html' }
+
context 'without JWT' do
let(:jwt) { nil }
@@ -29,13 +33,55 @@ RSpec.describe JiraConnect::SubscriptionsController do
it 'removes X-Frame-Options to allow rendering in iframe' do
expect(response.headers['X-Frame-Options']).to be_nil
end
+
+ context 'with JSON format' do
+ let_it_be(:subscription) { create(:jira_connect_subscription, installation: installation) }
+
+ let(:content_type) { 'application/json' }
+
+ it 'renders the relevant data as JSON', :aggregate_failures do
+ expect(json_response).to include('groups_path' => api_v4_groups_path(params: { min_access_level: Gitlab::Access::MAINTAINER, skip_groups: [subscription.namespace_id] }))
+ expect(json_response).to include(
+ 'subscriptions' => [
+ 'group' => {
+ 'name' => subscription.namespace.name,
+ 'avatar_url' => subscription.namespace.avatar_url,
+ 'full_name' => subscription.namespace.full_name,
+ 'description' => subscription.namespace.description
+ },
+ 'created_at' => subscription.created_at.iso8601(3),
+ 'unlink_path' => jira_connect_subscription_path(subscription)
+ ]
+ )
+ expect(json_response).to include('subscriptions_path' => jira_connect_subscriptions_path)
+ end
+
+ context 'when not signed in to GitLab' do
+ it 'contains a login path' do
+ expect(json_response).to include('login_path' => jira_connect_users_path)
+ end
+ end
+
+ context 'when signed in to GitLab' do
+ let(:user) { create(:user) }
+
+ before do
+ sign_in(user)
+
+ get :index, params: { jwt: jwt }
+ end
+
+ it 'does not contain a login path' do
+ expect(json_response).to include('login_path' => nil)
+ end
+ end
+ end
end
end
describe '#create' do
let(:group) { create(:group) }
let(:user) { create(:user) }
- let(:current_user) { user }
before do
group.add_maintainer(user)