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

request_params_examples.rb « cycle_analytics « analytics « shared_examples « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ef9830fbce8ffd9dc9a8271fa6d12a4ca4df28a9 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# frozen_string_literal: true

RSpec.shared_examples 'unlicensed cycle analytics request params' do
  let(:params) do
    {
      created_after: '2019-01-01',
      created_before: '2019-03-01',
      project_ids: [2, 3],
      namespace: namespace,
      current_user: user
    }
  end

  subject { described_class.new(params) }

  before do
    root_group.add_owner(user)
  end

  describe 'validations' do
    it 'is valid' do
      expect(subject).to be_valid
    end

    context 'when `created_before` is missing' do
      before do
        params[:created_before] = nil
      end

      it 'is valid', time_travel_to: '2019-03-01' do
        expect(subject).to be_valid
      end
    end

    context 'when `created_before` is earlier than `created_after`' do
      before do
        params[:created_before] = '2015-01-01'
      end

      it 'is invalid' do
        expect(subject).not_to be_valid
        expect(subject.errors.messages[:created_before]).not_to be_empty
      end
    end

    context 'when the date range exceeds 180 days' do
      before do
        params[:created_before] = '2019-07-15'
      end

      it 'is invalid' do
        expect(subject).not_to be_valid
        message = s_('CycleAnalytics|The given date range is larger than 180 days')
        expect(subject.errors.messages[:created_after]).to include(message)
      end
    end
  end

  it 'casts `created_after` to `Time`' do
    expect(subject.created_after).to be_a_kind_of(Time)
  end

  it 'casts `created_before` to `Time`' do
    expect(subject.created_before).to be_a_kind_of(Time)
  end

  describe 'optional `value_stream`' do
    context 'when `value_stream` is not empty' do
      let(:value_stream) { instance_double('Analytics::CycleAnalytics::ValueStream') }

      before do
        params[:value_stream] = value_stream
      end

      it { expect(subject.value_stream).to eq(value_stream) }
    end

    context 'when `value_stream` is nil' do
      before do
        params[:value_stream] = nil
      end

      it { expect(subject.value_stream).to eq(nil) }
    end
  end

  describe 'sorting params' do
    before do
      params.merge!(sort: 'duration', direction: 'asc')
    end

    it 'converts sorting params to symbol when passing it to data collector' do
      data_collector_params = subject.to_data_collector_params

      expect(data_collector_params[:sort]).to eq(:duration)
      expect(data_collector_params[:direction]).to eq(:asc)
    end

    it 'adds sorting params to data attributes' do
      data_attributes = subject.to_data_attributes

      expect(data_attributes[:sort]).to eq('duration')
      expect(data_attributes[:direction]).to eq('asc')
    end
  end

  describe 'aggregation params' do
    context 'when not licensed' do
      it 'returns nil' do
        data_collector_params = subject.to_data_attributes
        expect(data_collector_params[:aggregation]).to eq(nil)
      end
    end
  end

  describe 'use_aggregated_data_collector param' do
    subject(:value) { described_class.new(params).to_data_collector_params[:use_aggregated_data_collector] }

    it { is_expected.to eq(false) }
  end

  describe 'feature availablity data attributes' do
    subject(:value) { described_class.new(params).to_data_attributes }

    it 'disables all paid features' do
      is_expected.to match(a_hash_including(enable_tasks_by_type_chart: 'false',
        enable_customizable_stages: 'false',
        enable_projects_filter: 'false'))
    end
  end
end