diff options
author | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 13:34:23 -0600 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 13:34:23 -0600 |
commit | 6438df3a1e0fb944485cebf07976160184697d72 (patch) | |
tree | 00b09bfd170e77ae9391b1a2f5a93ef6839f2597 /spec/lib/atlassian/jira_connect/serializers | |
parent | 42bcd54d971da7ef2854b896a7b34f4ef8601067 (diff) | |
download | gitlab-ce-6438df3a1e0fb944485cebf07976160184697d72.tar.gz |
Add latest changes from gitlab-org/gitlab@13-8-stable-eev13.8.0-rc42
Diffstat (limited to 'spec/lib/atlassian/jira_connect/serializers')
3 files changed, 182 insertions, 2 deletions
diff --git a/spec/lib/atlassian/jira_connect/serializers/build_entity_spec.rb b/spec/lib/atlassian/jira_connect/serializers/build_entity_spec.rb index 52e475d20ca..4bbd654655d 100644 --- a/spec/lib/atlassian/jira_connect/serializers/build_entity_spec.rb +++ b/spec/lib/atlassian/jira_connect/serializers/build_entity_spec.rb @@ -23,7 +23,7 @@ RSpec.describe Atlassian::JiraConnect::Serializers::BuildEntity do end it 'is invalid, since it has no issue keys' do - expect(subject.to_json).not_to be_valid_json.according_to_schema(Atlassian::Schemata.build_info) + expect(subject.to_json).not_to match_schema(Atlassian::Schemata.build_info) end end end @@ -43,7 +43,7 @@ RSpec.describe Atlassian::JiraConnect::Serializers::BuildEntity do describe '#to_json' do it 'is valid according to the build info schema' do - expect(subject.to_json).to be_valid_json.according_to_schema(Atlassian::Schemata.build_info) + expect(subject.to_json).to be_valid_json.and match_schema(Atlassian::Schemata.build_info) end end end diff --git a/spec/lib/atlassian/jira_connect/serializers/deployment_entity_spec.rb b/spec/lib/atlassian/jira_connect/serializers/deployment_entity_spec.rb new file mode 100644 index 00000000000..82bcbdc4561 --- /dev/null +++ b/spec/lib/atlassian/jira_connect/serializers/deployment_entity_spec.rb @@ -0,0 +1,95 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Atlassian::JiraConnect::Serializers::DeploymentEntity do + let_it_be(:user) { create_default(:user) } + let_it_be(:project) { create_default(:project, :repository) } + let_it_be(:environment) { create(:environment, name: 'prod', project: project) } + let_it_be_with_reload(:deployment) { create(:deployment, environment: environment) } + + subject { described_class.represent(deployment) } + + context 'when the deployment does not belong to any Jira issue' do + 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.deployment_info) + end + end + end + + context 'this is an external deployment' do + before do + deployment.update!(deployable: nil) + end + + it 'does not raise errors when serializing' do + expect { subject.to_json }.not_to raise_error + end + + it 'returns an empty list of issue keys' do + expect(subject.issue_keys).to be_empty + end + end + + describe 'environment type' do + using RSpec::Parameterized::TableSyntax + + where(:env_name, :env_type) do + 'prod' | 'production' + 'test' | 'testing' + 'staging' | 'staging' + 'dev' | 'development' + 'review/app' | 'development' + 'something-else' | 'unmapped' + end + + with_them do + before do + environment.update!(name: env_name) + end + + let(:exposed_type) { subject.send(:environment_entity).send(:type) } + + it 'has the correct environment type' do + expect(exposed_type).to eq(env_type) + end + end + end + + context 'when the deployment can be linked to a Jira issue' do + let(:pipeline) { create(:ci_pipeline, merge_request: merge_request) } + + before do + subject.deployable.update!(pipeline: pipeline) + end + + %i[jira_branch jira_title].each do |trait| + context "because it belongs to an MR with a #{trait}" do + let(:merge_request) { create(:merge_request, trait) } + + 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 deployment info schema' do + expect(subject.to_json).to be_valid_json.and match_schema(Atlassian::Schemata.deployment_info) + end + end + end + end + end +end diff --git a/spec/lib/atlassian/jira_connect/serializers/feature_flag_entity_spec.rb b/spec/lib/atlassian/jira_connect/serializers/feature_flag_entity_spec.rb new file mode 100644 index 00000000000..964801338cf --- /dev/null +++ b/spec/lib/atlassian/jira_connect/serializers/feature_flag_entity_spec.rb @@ -0,0 +1,85 @@ +# 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) } + + 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, 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', '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 |