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

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

65 lines
1.7 KiB
Ruby
Raw Normal View History

2020-11-24 15:15:51 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe JiraConnect::SyncService, feature_category: :integrations 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)
2022-07-16 23:28:13 +05:30
expect(Gitlab::IntegrationsLogger)
2020-11-24 15:15:51 +05:30
.to receive(type).with(
2022-07-16 23:28:13 +05:30
{
message: 'response from jira dev_info api',
integration: 'JiraConnect',
project_id: project.id,
project_path: project.full_path,
jira_response: message&.to_json
}
2020-11-24 15:15:51 +05:30
)
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
2023-07-09 08:55:56 +05:30
context 'when a request returns errors' do
it 'logs each response as an error' do
2022-11-25 23:54:43 +05:30
expect_next(client).to store_info(
[
{ 'errorMessages' => ['some error message'] },
2023-07-09 08:55:56 +05:30
{ 'errorMessage' => 'a single error message' },
{ 'errorMessages' => [] },
{ 'errorMessage' => '' }
2022-11-25 23:54:43 +05:30
])
2020-11-24 15:15:51 +05:30
expect_log(:error, { 'errorMessages' => ['some error message'] })
2023-07-09 08:55:56 +05:30
expect_log(:error, { 'errorMessage' => 'a single error message' })
2020-11-24 15:15:51 +05:30
subject
end
end
end
end