summaryrefslogtreecommitdiff
path: root/spec/serializers
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-09 12:08:03 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-09 12:08:03 +0000
commitcddaddb86bf6d4d277d206c42a9138a2d660ea56 (patch)
tree92da110e04602b7ea62835e41327e552150279f5 /spec/serializers
parent5afd8575506372dd64c238203bd05b4826f3ae2e (diff)
downloadgitlab-ce-cddaddb86bf6d4d277d206c42a9138a2d660ea56.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/serializers')
-rw-r--r--spec/serializers/review_app_setup_entity_spec.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/spec/serializers/review_app_setup_entity_spec.rb b/spec/serializers/review_app_setup_entity_spec.rb
new file mode 100644
index 00000000000..19949fa9282
--- /dev/null
+++ b/spec/serializers/review_app_setup_entity_spec.rb
@@ -0,0 +1,54 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe ReviewAppSetupEntity do
+ let_it_be(:user) { create(:admin) }
+ let(:project) { create(:project) }
+ let(:presenter) { ProjectPresenter.new(project, current_user: user) }
+ let(:entity) { described_class.new(presenter) }
+ let(:request) { double('request') }
+
+ before do
+ allow(request).to receive(:current_user).and_return(user)
+ allow(request).to receive(:project).and_return(project)
+ end
+
+ subject { entity.as_json }
+
+ describe '#as_json' do
+ it 'contains can_setup_review_app' do
+ expect(subject).to include(:can_setup_review_app)
+ end
+
+ context 'when the user can setup a review app' do
+ before do
+ allow(presenter).to receive(:can_setup_review_app?).and_return(true)
+ end
+
+ it 'contains relevant fields' do
+ expect(subject.keys).to include(:all_clusters_empty, :review_snippet)
+ end
+
+ it 'exposes the relevant review snippet' do
+ review_app_snippet = YAML.safe_load(File.read(Rails.root.join('lib', 'gitlab', 'ci', 'snippets', 'review_app_default.yml'))).to_s
+
+ expect(subject[:review_snippet]).to eq(review_app_snippet)
+ end
+
+ it 'exposes whether the project has associated clusters' do
+ expect(subject[:all_clusters_empty]).to be_truthy
+ end
+ end
+
+ context 'when the user cannot setup a review app' do
+ before do
+ allow(presenter).to receive(:can_setup_review_app?).and_return(false)
+ end
+
+ it 'does not expose certain fields' do
+ expect(subject.keys).not_to include(:all_clusters_empty, :review_snippet)
+ end
+ end
+ end
+end