diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/services/metrics/dashboard/grafana_metric_embed_service_spec.rb | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/services/metrics/dashboard/grafana_metric_embed_service_spec.rb')
-rw-r--r-- | spec/services/metrics/dashboard/grafana_metric_embed_service_spec.rb | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/spec/services/metrics/dashboard/grafana_metric_embed_service_spec.rb b/spec/services/metrics/dashboard/grafana_metric_embed_service_spec.rb index ee3c55cb642..5263fd40a40 100644 --- a/spec/services/metrics/dashboard/grafana_metric_embed_service_spec.rb +++ b/spec/services/metrics/dashboard/grafana_metric_embed_service_spec.rb @@ -7,7 +7,7 @@ RSpec.describe Metrics::Dashboard::GrafanaMetricEmbedService do include ReactiveCachingHelpers include GrafanaApiHelpers - let_it_be(:project) { build(:project) } + let_it_be(:project) { create(:project) } let_it_be(:user) { create(:user) } let_it_be(:grafana_integration) { create(:grafana_integration, project: project) } @@ -15,7 +15,7 @@ RSpec.describe Metrics::Dashboard::GrafanaMetricEmbedService do valid_grafana_dashboard_link(grafana_integration.grafana_url) end - before do + before_all do project.add_maintainer(user) end @@ -58,6 +58,31 @@ RSpec.describe Metrics::Dashboard::GrafanaMetricEmbedService do expect(subject.current_user).to eq(user) expect(subject.params[:grafana_url]).to eq(grafana_url) end + + context 'with unknown users' do + let(:params) { [project.id, current_user_id, grafana_url] } + + context 'when anonymous' do + where(:current_user_id) do + [nil, ''] + end + + with_them do + it 'sets current_user as nil' do + expect(subject.current_user).to be_nil + end + end + end + + context 'when invalid' do + let(:current_user_id) { non_existing_record_id } + + it 'raise record not found error' do + expect { subject } + .to raise_error(ActiveRecord::RecordNotFound, /Couldn't find User/) + end + end + end end describe '#get_dashboard', :use_clean_rails_memory_store_caching do @@ -145,7 +170,17 @@ RSpec.describe Metrics::Dashboard::GrafanaMetricEmbedService do stub_datasource_request(grafana_integration.grafana_url) end - it_behaves_like 'valid embedded dashboard service response' + context 'when project is private and user is member' do + it_behaves_like 'valid embedded dashboard service response' + end + + context 'when project is public and user is anonymous' do + let(:project) { create(:project, :public) } + let(:user) { nil } + let(:grafana_integration) { create(:grafana_integration, project: project) } + + it_behaves_like 'valid embedded dashboard service response' + end end end |