debian-mirror-gitlab/spec/serializers/review_app_setup_entity_spec.rb

56 lines
1.6 KiB
Ruby
Raw Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe ReviewAppSetupEntity do
2020-03-13 15:44:24 +05:30
let_it_be(:user) { create(:admin) }
2021-04-29 21:17:54 +05:30
2020-03-13 15:44:24 +05:30
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