summaryrefslogtreecommitdiff
path: root/spec/lib/api
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-10-21 07:08:36 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-10-21 07:08:36 +0000
commit48aff82709769b098321c738f3444b9bdaa694c6 (patch)
treee00c7c43e2d9b603a5a6af576b1685e400410dee /spec/lib/api
parent879f5329ee916a948223f8f43d77fba4da6cd028 (diff)
downloadgitlab-ce-48aff82709769b098321c738f3444b9bdaa694c6.tar.gz
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'spec/lib/api')
-rw-r--r--spec/lib/api/entities/snippet_spec.rb26
-rw-r--r--spec/lib/api/github/entities_spec.rb31
-rw-r--r--spec/lib/api/helpers/packages/dependency_proxy_helpers_spec.rb2
-rw-r--r--spec/lib/api/helpers_spec.rb19
4 files changed, 46 insertions, 32 deletions
diff --git a/spec/lib/api/entities/snippet_spec.rb b/spec/lib/api/entities/snippet_spec.rb
index 068851f7f6c..090f09c9b61 100644
--- a/spec/lib/api/entities/snippet_spec.rb
+++ b/spec/lib/api/entities/snippet_spec.rb
@@ -21,16 +21,6 @@ RSpec.describe ::API::Entities::Snippet do
it { expect(subject[:visibility]).to eq snippet.visibility }
it { expect(subject).to include(:author) }
- context 'with snippet_multiple_files feature disabled' do
- before do
- stub_feature_flags(snippet_multiple_files: false)
- end
-
- it 'does not return files' do
- expect(subject).not_to include(:files)
- end
- end
-
describe 'file_name' do
it 'returns attribute from repository' do
expect(subject[:file_name]).to eq snippet.blobs.first.path
@@ -77,14 +67,6 @@ RSpec.describe ::API::Entities::Snippet do
let(:blob) { snippet.blobs.first }
let(:ref) { blob.repository.root_ref }
- context 'when repository does not exist' do
- it 'does not include the files attribute' do
- allow(snippet).to receive(:repository_exists?).and_return(false)
-
- expect(subject).not_to include(:files)
- end
- end
-
shared_examples 'snippet files' do
let(:file) { subject[:files].first }
@@ -99,6 +81,14 @@ RSpec.describe ::API::Entities::Snippet do
it 'has the raw url' do
expect(file[:raw_url]).to match(raw_url)
end
+
+ context 'when repository does not exist' do
+ it 'returns empty array' do
+ allow(snippet.repository).to receive(:empty?).and_return(true)
+
+ expect(subject[:files]).to be_empty
+ end
+ end
end
context 'with PersonalSnippet' do
diff --git a/spec/lib/api/github/entities_spec.rb b/spec/lib/api/github/entities_spec.rb
new file mode 100644
index 00000000000..00ea60c5d65
--- /dev/null
+++ b/spec/lib/api/github/entities_spec.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe API::Github::Entities do
+ describe API::Github::Entities::User do
+ let(:user) { create(:user, username: username) }
+ let(:username) { 'name_of_user' }
+ let(:gitlab_protocol_and_host) { "#{Gitlab.config.gitlab.protocol}://#{Gitlab.config.gitlab.host}" }
+ let(:expected_user_url) { "#{gitlab_protocol_and_host}/#{username}" }
+ let(:entity) { described_class.new(user) }
+
+ subject { entity.as_json }
+
+ specify :aggregate_failure do
+ expect(subject[:id]).to eq user.id
+ expect(subject[:login]).to eq 'name_of_user'
+ expect(subject[:url]).to eq expected_user_url
+ expect(subject[:html_url]).to eq expected_user_url
+ expect(subject[:avatar_url]).to include('https://www.gravatar.com/avatar')
+ end
+
+ context 'with avatar' do
+ let(:user) { create(:user, :with_avatar, username: username) }
+
+ specify do
+ expect(subject[:avatar_url]).to include("#{gitlab_protocol_and_host}/uploads/-/system/user/avatar/")
+ end
+ end
+ end
+end
diff --git a/spec/lib/api/helpers/packages/dependency_proxy_helpers_spec.rb b/spec/lib/api/helpers/packages/dependency_proxy_helpers_spec.rb
index ccf96bcbad6..6d06fc3618d 100644
--- a/spec/lib/api/helpers/packages/dependency_proxy_helpers_spec.rb
+++ b/spec/lib/api/helpers/packages/dependency_proxy_helpers_spec.rb
@@ -24,6 +24,7 @@ RSpec.describe API::Helpers::Packages::DependencyProxyHelpers do
shared_examples 'executing redirect' do
it 'redirects to package registry' do
+ expect(helper).to receive(:track_event).with('npm_request_forward').once
expect(helper).to receive(:registry_url).once
expect(helper).to receive(:redirect).once
expect(helper).to receive(:fallback).never
@@ -63,6 +64,7 @@ RSpec.describe API::Helpers::Packages::DependencyProxyHelpers do
let(:package_type) { pkg_type }
it 'raises an error' do
+ allow(helper).to receive(:track_event)
expect { subject }.to raise_error(ArgumentError, "Can't build registry_url for package_type #{package_type}")
end
end
diff --git a/spec/lib/api/helpers_spec.rb b/spec/lib/api/helpers_spec.rb
index 51a45dff6a4..8e738af0fa3 100644
--- a/spec/lib/api/helpers_spec.rb
+++ b/spec/lib/api/helpers_spec.rb
@@ -191,41 +191,32 @@ RSpec.describe API::Helpers do
describe '#increment_unique_values' do
let(:value) { '9f302fea-f828-4ca9-aef4-e10bd723c0b3' }
- let(:event_name) { 'my_event' }
+ let(:event_name) { 'g_compliance_dashboard' }
let(:unknown_event) { 'unknown' }
let(:feature) { "usage_data_#{event_name}" }
+ before do
+ skip_feature_flags_yaml_validation
+ end
+
context 'with feature enabled' do
before do
stub_feature_flags(feature => true)
end
it 'tracks redis hll event' do
- stub_application_setting(usage_ping_enabled: true)
-
expect(Gitlab::UsageDataCounters::HLLRedisCounter).to receive(:track_event).with(value, event_name)
subject.increment_unique_values(event_name, value)
end
- it 'does not track event usage ping is not enabled' do
- stub_application_setting(usage_ping_enabled: false)
- expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event)
-
- subject.increment_unique_values(event_name, value)
- end
-
it 'logs an exception for unknown event' do
- stub_application_setting(usage_ping_enabled: true)
-
expect(Gitlab::AppLogger).to receive(:warn).with("Redis tracking event failed for event: #{unknown_event}, message: Unknown event #{unknown_event}")
subject.increment_unique_values(unknown_event, value)
end
it 'does not track event for nil values' do
- stub_application_setting(usage_ping_enabled: true)
-
expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event)
subject.increment_unique_values(unknown_event, nil)