diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 13:16:36 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 13:16:36 +0000 |
commit | 311b0269b4eb9839fa63f80c8d7a58f32b8138a0 (patch) | |
tree | 07e7870bca8aed6d61fdcc810731c50d2c40af47 /spec/lib/gitlab/zentao/query_spec.rb | |
parent | 27909cef6c4170ed9205afa7426b8d3de47cbb0c (diff) | |
download | gitlab-ce-311b0269b4eb9839fa63f80c8d7a58f32b8138a0.tar.gz |
Add latest changes from gitlab-org/gitlab@14-5-stable-eev14.5.0-rc42
Diffstat (limited to 'spec/lib/gitlab/zentao/query_spec.rb')
-rw-r--r-- | spec/lib/gitlab/zentao/query_spec.rb | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/spec/lib/gitlab/zentao/query_spec.rb b/spec/lib/gitlab/zentao/query_spec.rb new file mode 100644 index 00000000000..f7495e640c3 --- /dev/null +++ b/spec/lib/gitlab/zentao/query_spec.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Zentao::Query do + let(:zentao_integration) { create(:zentao_integration) } + let(:params) { {} } + + subject(:query) { described_class.new(zentao_integration, ActionController::Parameters.new(params)) } + + describe '#issues' do + let(:response) { { 'page' => 1, 'total' => 0, 'limit' => 20, 'issues' => [] } } + + def expect_query_option_include(expected_params) + expect_next_instance_of(Gitlab::Zentao::Client) do |client| + expect(client).to receive(:fetch_issues) + .with(hash_including(expected_params)) + .and_return(response) + end + + query.issues + end + + context 'when params are empty' do + it 'fills default params' do + expect_query_option_include(status: 'opened', order: 'lastEditedDate_desc', labels: '') + end + end + + context 'when params contain valid options' do + let(:params) { { state: 'closed', sort: 'created_asc', labels: %w[Bugs Features] } } + + it 'fills params with standard of ZenTao' do + expect_query_option_include(status: 'closed', order: 'openedDate_asc', labels: 'Bugs,Features') + end + end + + context 'when params contain invalid options' do + let(:params) { { state: 'xxx', sort: 'xxx', labels: %w[xxx] } } + + it 'fills default params with standard of ZenTao' do + expect_query_option_include(status: 'opened', order: 'lastEditedDate_desc', labels: 'xxx') + end + end + end + + describe '#issue' do + let(:response) { { 'issue' => { 'id' => 'story-1' } } } + + before do + expect_next_instance_of(Gitlab::Zentao::Client) do |client| + expect(client).to receive(:fetch_issue) + .and_return(response) + end + end + + it 'returns issue object by client' do + expect(query.issue).to include('id' => 'story-1') + end + end +end |