debian-mirror-gitlab/spec/services/jira_connect/sync_service_spec.rb

60 lines
1.6 KiB
Ruby
Raw Normal View History

2020-11-24 15:15:51 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe JiraConnect::SyncService do
2021-02-22 17:27:13 +05:30
include AfterNextHelpers
2020-11-24 15:15:51 +05:30
describe '#execute' do
let_it_be(:project) { create(:project, :repository) }
2021-09-30 23:02:18 +05:30
2021-02-22 17:27:13 +05:30
let(:client) { Atlassian::JiraConnect::Client }
let(:info) { { a: 'Some', b: 'Info' } }
2020-11-24 15:15:51 +05:30
subject do
2021-02-22 17:27:13 +05:30
described_class.new(project).execute(**info)
2020-11-24 15:15:51 +05:30
end
before do
create(:jira_connect_subscription, namespace: project.namespace)
end
2021-02-22 17:27:13 +05:30
def store_info(return_values = [{ 'status': 'success' }])
receive(:send_info).with(project: project, **info).and_return(return_values)
2020-11-24 15:15:51 +05:30
end
def expect_log(type, message)
expect(Gitlab::ProjectServiceLogger)
.to receive(type).with(
message: 'response from jira dev_info api',
integration: 'JiraConnect',
project_id: project.id,
project_path: project.full_path,
jira_response: message&.to_json
)
end
it 'calls Atlassian::JiraConnect::Client#store_dev_info and logs the response' do
2021-02-22 17:27:13 +05:30
expect_next(client).to store_info
2020-11-24 15:15:51 +05:30
expect_log(:info, { 'status': 'success' })
subject
end
2021-02-22 17:27:13 +05:30
context 'when a request returns an error' do
2020-11-24 15:15:51 +05:30
it 'logs the response as an error' do
2021-02-22 17:27:13 +05:30
expect_next(client).to store_info([
{ 'errorMessages' => ['some error message'] },
2021-03-08 18:12:59 +05:30
{ 'errorMessages' => ['x'] }
2021-02-22 17:27:13 +05:30
])
2020-11-24 15:15:51 +05:30
expect_log(:error, { 'errorMessages' => ['some error message'] })
2021-03-08 18:12:59 +05:30
expect_log(:error, { 'errorMessages' => ['x'] })
2020-11-24 15:15:51 +05:30
subject
end
end
end
end