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

feature_flag_entity_spec.rb « serializers « jira_connect « atlassian « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2d12cd1ed0a1e36e029f0aa8757080c4b5f4eb97 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Atlassian::JiraConnect::Serializers::FeatureFlagEntity do
  let_it_be(:user) { create_default(:user) }
  let_it_be(:project) { create_default(:project) }

  subject { described_class.represent(feature_flag) }

  context 'when the feature flag does not belong to any Jira issue' do
    let_it_be(:feature_flag) { create(:operations_feature_flag, project: project) }

    describe '#issue_keys' do
      it 'is empty' do
        expect(subject.issue_keys).to be_empty
      end
    end

    describe '#to_json' do
      it 'can encode the object' do
        expect(subject.to_json).to be_valid_json
      end

      it 'is invalid, since it has no issue keys' do
        expect(subject.to_json).not_to match_schema(Atlassian::Schemata.feature_flag_info)
      end
    end
  end

  context 'when the feature flag does belong to a Jira issue' do
    let(:feature_flag) do
      create(:operations_feature_flag, project: project, description: 'THING-123')
    end

    describe '#issue_keys' do
      it 'is not empty' do
        expect(subject.issue_keys).not_to be_empty
      end
    end

    describe '#to_json' do
      it 'is valid according to the feature flag info schema' do
        expect(subject.to_json).to be_valid_json.and match_schema(Atlassian::Schemata.feature_flag_info)
      end
    end

    context 'it has a percentage strategy' do
      let!(:scopes) do
        strat = create(:operations_strategy,
               feature_flag: feature_flag,
               name: ::Operations::FeatureFlags::Strategy::STRATEGY_GRADUALROLLOUTUSERID,
               parameters: { 'percentage' => '50', 'groupId' => 'abcde' })

        [
          create(:operations_scope, strategy: strat, environment_scope: 'production in live'),
          create(:operations_scope, strategy: strat, environment_scope: 'staging'),
          create(:operations_scope, strategy: strat)
        ]
      end

      let(:entity) { Gitlab::Json.parse(subject.to_json) }

      it 'is valid according to the feature flag info schema' do
        expect(subject.to_json).to be_valid_json.and match_schema(Atlassian::Schemata.feature_flag_info)
      end

      it 'has the correct summary' do
        expect(entity.dig('summary', 'url')).to eq "http://localhost/#{project.full_path}/-/feature_flags/#{feature_flag.iid}/edit"
        expect(entity.dig('summary', 'status')).to eq(
          'enabled' => true,
          'defaultValue' => '',
          'rollout' => { 'percentage' => 50.0, 'text' => 'Percent of users' }
        )
      end

      it 'includes the correct environments' do
        expect(entity['details']).to contain_exactly(
          include('environment' => { 'name' => 'production in live', 'type' => 'production' }),
          include('environment' => { 'name' => 'staging', 'type' => 'staging' }),
          include('environment' => { 'name' => scopes.last.environment_scope })
        )
      end
    end
  end
end