summaryrefslogtreecommitdiff
path: root/spec/lib/api
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/api')
-rw-r--r--spec/lib/api/entities/ci/job_artifact_file_spec.rb18
-rw-r--r--spec/lib/api/entities/ci/job_request/dependency_spec.rb27
-rw-r--r--spec/lib/api/entities/user_spec.rb57
-rw-r--r--spec/lib/api/entities/wiki_page_spec.rb56
-rw-r--r--spec/lib/api/helpers_spec.rb20
5 files changed, 178 insertions, 0 deletions
diff --git a/spec/lib/api/entities/ci/job_artifact_file_spec.rb b/spec/lib/api/entities/ci/job_artifact_file_spec.rb
new file mode 100644
index 00000000000..9e4ec272518
--- /dev/null
+++ b/spec/lib/api/entities/ci/job_artifact_file_spec.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe API::Entities::Ci::JobArtifactFile do
+ let(:artifact_file) { instance_double(JobArtifactUploader, filename: 'ci_build_artifacts.zip', cached_size: 42) }
+ let(:entity) { described_class.new(artifact_file) }
+
+ subject { entity.as_json }
+
+ it 'returns the filename' do
+ expect(subject[:filename]).to eq('ci_build_artifacts.zip')
+ end
+
+ it 'returns the size' do
+ expect(subject[:size]).to eq(42)
+ end
+end
diff --git a/spec/lib/api/entities/ci/job_request/dependency_spec.rb b/spec/lib/api/entities/ci/job_request/dependency_spec.rb
new file mode 100644
index 00000000000..fa5f3da554c
--- /dev/null
+++ b/spec/lib/api/entities/ci/job_request/dependency_spec.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe API::Entities::Ci::JobRequest::Dependency do
+ let(:job) { create(:ci_build, :artifacts) }
+ let(:entity) { described_class.new(job) }
+
+ subject { entity.as_json }
+
+ it 'returns the dependency id' do
+ expect(subject[:id]).to eq(job.id)
+ end
+
+ it 'returns the dependency name' do
+ expect(subject[:name]).to eq(job.name)
+ end
+
+ it 'returns the dependency token' do
+ expect(subject[:token]).to eq(job.token)
+ end
+
+ it 'returns the dependency artifacts_file', :aggregate_failures do
+ expect(subject[:artifacts_file][:filename]).to eq('ci_build_artifacts.zip')
+ expect(subject[:artifacts_file][:size]).to eq(job.artifacts_size)
+ end
+end
diff --git a/spec/lib/api/entities/user_spec.rb b/spec/lib/api/entities/user_spec.rb
index 14dc60e1a5f..be5e8e8e8c2 100644
--- a/spec/lib/api/entities/user_spec.rb
+++ b/spec/lib/api/entities/user_spec.rb
@@ -78,6 +78,63 @@ RSpec.describe API::Entities::User do
end
end
+ context 'with group bot user' do
+ let(:group) { create(:group) }
+ let(:user) { create(:user, :project_bot, name: 'group bot') }
+
+ before do
+ group.add_maintainer(user)
+ end
+
+ it 'exposes user as a bot' do
+ expect(subject[:bot]).to eq(true)
+ end
+
+ context 'when the requester is not a group member' do
+ context 'with a public group' do
+ it 'exposes group bot user name' do
+ expect(subject[:name]).to eq('group bot')
+ end
+ end
+
+ context 'with a private group' do
+ let(:group) { create(:group, :private) }
+
+ it 'does not expose group bot user name' do
+ expect(subject[:name]).to eq('****')
+ end
+ end
+ end
+
+ context 'when the requester is nil' do
+ let(:current_user) { nil }
+
+ it 'does not expose group bot user name' do
+ expect(subject[:name]).to eq('****')
+ end
+ end
+
+ context 'when the requester is a group maintainer' do
+ let(:current_user) { create(:user) }
+
+ before do
+ group.add_maintainer(current_user)
+ end
+
+ it 'exposes group bot user name' do
+ expect(subject[:name]).to eq('group bot')
+ end
+ end
+
+ context 'when the requester is an admin' do
+ let(:current_user) { create(:user, :admin) }
+
+ it 'exposes group bot user name', :enable_admin_mode do
+ expect(subject[:name]).to eq('group bot')
+ end
+ end
+ end
+
it 'exposes local_time' do
local_time = '2:30 PM'
expect(entity).to receive(:local_time).with(timezone).and_return(local_time)
diff --git a/spec/lib/api/entities/wiki_page_spec.rb b/spec/lib/api/entities/wiki_page_spec.rb
new file mode 100644
index 00000000000..238c8233a14
--- /dev/null
+++ b/spec/lib/api/entities/wiki_page_spec.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe API::Entities::WikiPage do
+ let_it_be_with_reload(:wiki_page) { create(:wiki_page) }
+
+ let(:params) { {} }
+ let(:entity) { described_class.new(wiki_page, params) }
+
+ subject { entity.as_json }
+
+ it 'returns the proper encoding for the wiki page content' do
+ expect(entity.as_json[:encoding]).to eq 'UTF-8'
+
+ wiki_page.update_attributes(content: 'new_content'.encode('ISO-8859-1')) # rubocop:disable Rails/ActiveRecordAliases, Rails/SaveBang
+
+ expect(entity.as_json[:encoding]).to eq 'ISO-8859-1'
+ end
+
+ it 'returns the raw wiki page content' do
+ expect(subject[:content]).to eq wiki_page.content
+ end
+
+ context 'when render_html param is passed' do
+ context 'when it is true' do
+ let(:params) { { render_html: true } }
+
+ it 'returns the wiki page content rendered' do
+ expect(subject[:content]).to eq "<p data-sourcepos=\"1:1-1:#{wiki_page.content.size}\" dir=\"auto\">#{wiki_page.content}</p>"
+ end
+
+ it 'includes the wiki page version in the render context' do
+ expect(entity).to receive(:render_wiki_content).with(anything, hash_including(ref: wiki_page.version.id)).and_call_original
+
+ subject[:content]
+ end
+
+ context 'when page is an Ascii document' do
+ let(:wiki_page) { create(:wiki_page, content: "*Test* _content_", format: :asciidoc) }
+
+ it 'renders the page without errors' do
+ expect(subject[:content]).to eq("<div>&#x000A;<p><strong>Test</strong> <em>content</em></p>&#x000A;</div>")
+ end
+ end
+ end
+
+ context 'when it is false' do
+ let(:params) { { render_html: false } }
+
+ it 'returns the raw wiki page content' do
+ expect(subject[:content]).to eq wiki_page.content
+ end
+ end
+ end
+end
diff --git a/spec/lib/api/helpers_spec.rb b/spec/lib/api/helpers_spec.rb
index b2d4a3094af..2afe5a1a9d7 100644
--- a/spec/lib/api/helpers_spec.rb
+++ b/spec/lib/api/helpers_spec.rb
@@ -109,6 +109,26 @@ RSpec.describe API::Helpers do
end
end
end
+
+ context 'when project is pending delete' do
+ let(:project_pending_delete) { create(:project, pending_delete: true) }
+
+ it 'does not return the project pending delete' do
+ expect(Project).not_to receive(:find_by_full_path)
+
+ expect(subject.find_project(project_pending_delete.id)).to be_nil
+ end
+ end
+
+ context 'when project is hidden' do
+ let(:hidden_project) { create(:project, :hidden) }
+
+ it 'does not return the hidden project' do
+ expect(Project).not_to receive(:find_by_full_path)
+
+ expect(subject.find_project(hidden_project.id)).to be_nil
+ end
+ end
end
describe '#find_project!' do