diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-02 21:08:32 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-02 21:08:32 +0300 |
commit | f3e7bc80608c100227030030a6a601897f8e4ff9 (patch) | |
tree | 65afc2ae0ee2ccf7cf8d4efbf44077f816cade09 /spec/services/jira | |
parent | eea1fbf9f980fed108601412b63e627d3eebd46d (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/jira')
-rw-r--r-- | spec/services/jira/requests/projects_spec.rb | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/spec/services/jira/requests/projects_spec.rb b/spec/services/jira/requests/projects_spec.rb new file mode 100644 index 00000000000..7725c5693bb --- /dev/null +++ b/spec/services/jira/requests/projects_spec.rb @@ -0,0 +1,95 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Jira::Requests::Projects do + let(:jira_service) { create(:jira_service) } + let(:params) { {} } + + describe '#execute' do + let(:service) { described_class.new(jira_service, params) } + + subject { service.execute } + + context 'without jira_service' do + before do + jira_service.update!(active: false) + end + + it 'returns an error response' do + expect(subject.error?).to be_truthy + expect(subject.message).to eq('Jira service not configured.') + end + end + + context 'when jira_service is nil' do + let(:jira_service) { nil } + + it 'returns an error response' do + expect(subject.error?).to be_truthy + expect(subject.message).to eq('Jira service not configured.') + end + end + + context 'with jira_service' do + context 'when limit is invalid' do + let(:params) { { limit: 0 } } + + it 'returns a paylod with no projects returned' do + expect(subject.payload[:projects]).to be_empty + end + end + + context 'when validations and params are ok' do + let(:client) { double(options: { site: 'https://jira.example.com' }) } + + before do + expect(service).to receive(:client).at_least(:once).and_return(client) + end + + context 'when the request to Jira returns an error' do + before do + expect(client).to receive(:get).and_raise(Timeout::Error) + end + + it 'returns an error response' do + expect(subject.error?).to be_truthy + expect(subject.message).to eq('Timeout::Error') + end + end + + context 'when the request does not return any values' do + before do + expect(client).to receive(:get).and_return({ 'someKey' => 'value' }) + end + + it 'returns a paylod with no projects returned' do + payload = subject.payload + + expect(subject.success?).to be_truthy + expect(payload[:projects]).to be_empty + expect(payload[:is_last]).to be_truthy + end + end + + context 'when the request returns values' do + before do + expect(client).to receive(:get).and_return( + { 'values' => %w(project1 project2), 'isLast' => false } + ) + expect(JIRA::Resource::Project).to receive(:build).with(client, 'project1').and_return('jira_project1') + expect(JIRA::Resource::Project).to receive(:build).with(client, 'project2').and_return('jira_project2') + end + + it 'returns a paylod with jira projets' do + payload = subject.payload + + expect(subject.success?).to be_truthy + expect(payload[:projects]).to eq(%w(jira_project1 jira_project2)) + expect(payload[:is_last]).to be_falsey + end + end + end + end + end +end |