debian-mirror-gitlab/spec/services/metrics/dashboard/default_embed_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

60 lines
1.6 KiB
Ruby
Raw Normal View History

2019-09-30 21:07:59 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe Metrics::Dashboard::DefaultEmbedService, :use_clean_rails_memory_store_caching,
feature_category: :metrics do
2019-09-30 21:07:59 +05:30
include MetricsDashboardHelpers
2020-03-13 15:44:24 +05:30
let_it_be(:project) { build(:project) }
let_it_be(:user) { create(:user) }
let_it_be(:environment) { create(:environment, project: project) }
2019-09-30 21:07:59 +05:30
before do
2022-06-21 17:19:12 +05:30
project.add_maintainer(user) if user
2019-09-30 21:07:59 +05:30
end
2020-03-13 15:44:24 +05:30
describe '.valid_params?' do
let(:params) { { embedded: true } }
subject { described_class.valid_params?(params) }
it { is_expected.to be_truthy }
context 'missing embedded' do
let(:params) { {} }
it { is_expected.to be_falsey }
end
context 'not embedded' do
2020-04-08 14:13:33 +05:30
let(:params) { { embedded: 'false' } }
2020-03-13 15:44:24 +05:30
it { is_expected.to be_falsey }
end
end
2019-09-30 21:07:59 +05:30
describe '#get_dashboard' do
2019-10-12 21:52:04 +05:30
let(:service_params) { [project, user, { environment: environment }] }
2019-09-30 21:07:59 +05:30
let(:service_call) { described_class.new(*service_params).get_dashboard }
it_behaves_like 'valid embedded dashboard service response'
it_behaves_like 'raises error for users with insufficient permissions'
it 'caches the unprocessed dashboard for subsequent calls' do
2019-10-12 21:52:04 +05:30
system_service = Metrics::Dashboard::SystemDashboardService
expect(system_service).to receive(:new).once.and_call_original
2019-09-30 21:07:59 +05:30
described_class.new(*service_params).get_dashboard
described_class.new(*service_params).get_dashboard
end
context 'when called with a non-system dashboard' do
let(:dashboard_path) { 'garbage/dashboard/path' }
it_behaves_like 'valid embedded dashboard service response'
end
end
end