Welcome to mirror list, hosted at ThFree Co, Russian Federation.

zentao_spec.rb « integrations « models « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1a32453819d64dc752802a83a422b1578c29a4e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Integrations::Zentao do
  let(:url) { 'https://jihudemo.zentao.net' }
  let(:api_url) { 'https://jihudemo.zentao.net' }
  let(:api_token) { 'ZENTAO_TOKEN' }
  let(:zentao_product_xid) { '3' }
  let(:zentao_integration) { create(:zentao_integration) }

  it_behaves_like Integrations::ResetSecretFields do
    let(:integration) { zentao_integration }
  end

  describe 'set_default_data' do
    let(:project) { create(:project, :repository) }

    context 'when gitlab.yml was initialized' do
      it 'is prepopulated with the settings' do
        settings = {
          'zentao' => {
            'url' => 'http://zentao.sample/projects/project_a',
            'api_url' => 'http://zentao.sample/api'
          }
        }
        allow(Gitlab.config).to receive(:issues_tracker).and_return(settings)

        integration = project.create_zentao_integration(active: true)

        expect(integration.url).to eq('http://zentao.sample/projects/project_a')
        expect(integration.api_url).to eq('http://zentao.sample/api')
      end
    end
  end

  describe '#create' do
    let(:project) { create(:project, :repository) }
    let(:params) do
      {
        project: project,
        url: url,
        api_url: api_url,
        api_token: api_token,
        zentao_product_xid: zentao_product_xid
      }
    end

    it 'stores data in data_fields correctly' do
      tracker_data = described_class.create!(params).zentao_tracker_data

      expect(tracker_data.url).to eq(url)
      expect(tracker_data.api_url).to eq(api_url)
      expect(tracker_data.api_token).to eq(api_token)
      expect(tracker_data.zentao_product_xid).to eq(zentao_product_xid)
    end
  end

  describe '#fields' do
    it 'returns custom fields' do
      expect(zentao_integration.fields.pluck(:name)).to eq(%w[url api_url api_token zentao_product_xid])
    end
  end

  describe '#test' do
    let(:test_response) { { success: true } }

    before do
      allow_next_instance_of(Gitlab::Zentao::Client) do |client|
        allow(client).to receive(:ping).and_return(test_response)
      end
    end

    it 'gets response from Gitlab::Zentao::Client#ping' do
      expect(zentao_integration.test).to eq(test_response)
    end
  end

  describe '#help' do
    it 'renders prompt information' do
      expect(zentao_integration.help).not_to be_empty
    end
  end

  describe '#client_url' do
    subject(:integration) { build(:zentao_integration, api_url: api_url, url: 'url').client_url }

    context 'when api_url is set' do
      let(:api_url) { 'api_url' }

      it 'returns the api_url' do
        is_expected.to eq(api_url)
      end
    end

    context 'when api_url is not set' do
      let(:api_url) { '' }

      it 'returns the url' do
        is_expected.to eq('url')
      end
    end
  end
end