summaryrefslogtreecommitdiff
path: root/spec/lib/api
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-20 18:38:24 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-20 18:38:24 +0000
commit983a0bba5d2a042c4a3bbb22432ec192c7501d82 (patch)
treeb153cd387c14ba23bd5a07514c7c01fddf6a78a0 /spec/lib/api
parenta2bddee2cdb38673df0e004d5b32d9f77797de64 (diff)
downloadgitlab-ce-983a0bba5d2a042c4a3bbb22432ec192c7501d82.tar.gz
Add latest changes from gitlab-org/gitlab@12-10-stable-ee
Diffstat (limited to 'spec/lib/api')
-rw-r--r--spec/lib/api/entities/project_import_failed_relation_spec.rb23
-rw-r--r--spec/lib/api/entities/project_import_status_spec.rb49
-rw-r--r--spec/lib/api/entities/user_spec.rb26
-rw-r--r--spec/lib/api/validations/validators/limit_spec.rb25
4 files changed, 123 insertions, 0 deletions
diff --git a/spec/lib/api/entities/project_import_failed_relation_spec.rb b/spec/lib/api/entities/project_import_failed_relation_spec.rb
new file mode 100644
index 00000000000..f8330713480
--- /dev/null
+++ b/spec/lib/api/entities/project_import_failed_relation_spec.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe API::Entities::ProjectImportFailedRelation do
+ describe '#as_json' do
+ subject { entity.as_json }
+
+ let(:import_failure) { build(:import_failure) }
+ let(:entity) { described_class.new(import_failure) }
+
+ it 'includes basic fields', :aggregate_failures do
+ expect(subject).to eq(
+ id: import_failure.id,
+ created_at: import_failure.created_at,
+ exception_class: import_failure.exception_class,
+ exception_message: import_failure.exception_message,
+ relation_name: import_failure.relation_key,
+ source: import_failure.source
+ )
+ end
+ end
+end
diff --git a/spec/lib/api/entities/project_import_status_spec.rb b/spec/lib/api/entities/project_import_status_spec.rb
new file mode 100644
index 00000000000..650f9c156a3
--- /dev/null
+++ b/spec/lib/api/entities/project_import_status_spec.rb
@@ -0,0 +1,49 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe API::Entities::ProjectImportStatus do
+ describe '#as_json' do
+ subject { entity.as_json }
+
+ let(:correlation_id) { 'cid' }
+
+ context 'when import has not finished yet' do
+ let(:project) { create(:project, :import_scheduled, import_correlation_id: correlation_id) }
+ let(:entity) { described_class.new(project) }
+
+ it 'includes basic fields and no failures', :aggregate_failures do
+ expect(subject[:import_status]).to eq('scheduled')
+ expect(subject[:correlation_id]).to eq(correlation_id)
+ expect(subject[:import_error]).to be_nil
+ expect(subject[:failed_relations]).to eq([])
+ end
+ end
+
+ context 'when import has finished with failed relations' do
+ let(:project) { create(:project, :import_finished, import_correlation_id: correlation_id) }
+ let(:entity) { described_class.new(project) }
+
+ it 'includes basic fields with failed relations', :aggregate_failures do
+ create(:import_failure, :hard_failure, project: project, correlation_id_value: correlation_id)
+
+ expect(subject[:import_status]).to eq('finished')
+ expect(subject[:correlation_id]).to eq(correlation_id)
+ expect(subject[:import_error]).to be_nil
+ expect(subject[:failed_relations]).not_to be_empty
+ end
+ end
+
+ context 'when import has failed' do
+ let(:project) { create(:project, :import_failed, import_correlation_id: correlation_id, import_last_error: 'error') }
+ let(:entity) { described_class.new(project) }
+
+ it 'includes basic fields with import error', :aggregate_failures do
+ expect(subject[:import_status]).to eq('failed')
+ expect(subject[:correlation_id]).to eq(correlation_id)
+ expect(subject[:import_error]).to eq('error')
+ expect(subject[:failed_relations]).to eq([])
+ end
+ end
+ end
+end
diff --git a/spec/lib/api/entities/user_spec.rb b/spec/lib/api/entities/user_spec.rb
new file mode 100644
index 00000000000..20524b197e0
--- /dev/null
+++ b/spec/lib/api/entities/user_spec.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe API::Entities::User do
+ let(:user) { create(:user) }
+ let(:current_user) { create(:user) }
+
+ subject { described_class.new(user, current_user: current_user).as_json }
+
+ it 'exposes correct attributes' do
+ expect(subject).to include(:bio, :location, :public_email, :skype, :linkedin, :twitter, :website_url, :organization, :job_title, :work_information)
+ end
+
+ it 'exposes created_at if the current user can read the user profile' do
+ allow(Ability).to receive(:allowed?).with(current_user, :read_user_profile, user).and_return(true)
+
+ expect(subject).to include(:created_at)
+ end
+
+ it 'does not expose created_at if the current user cannot read the user profile' do
+ allow(Ability).to receive(:allowed?).with(current_user, :read_user_profile, user).and_return(false)
+
+ expect(subject).not_to include(:created_at)
+ end
+end
diff --git a/spec/lib/api/validations/validators/limit_spec.rb b/spec/lib/api/validations/validators/limit_spec.rb
new file mode 100644
index 00000000000..600f74e1fb2
--- /dev/null
+++ b/spec/lib/api/validations/validators/limit_spec.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe API::Validations::Validators::Limit do
+ include ApiValidatorsHelpers
+
+ subject do
+ described_class.new(['test'], 255, false, scope.new)
+ end
+
+ context 'valid limit param' do
+ it 'does not raise a validation error' do
+ expect_no_validation_error('test' => '123-456')
+ expect_no_validation_error('test' => '00000000-ffff-0000-ffff-000000000000')
+ expect_no_validation_error('test' => "#{'a' * 255}")
+ end
+ end
+
+ context 'longer than limit param' do
+ it 'raises a validation error' do
+ expect_validation_error('test' => "#{'a' * 256}")
+ end
+ end
+end