debian-mirror-gitlab/spec/lib/api/entities/release_spec.rb

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

81 lines
2.7 KiB
Ruby
Raw Normal View History

2020-01-01 13:55:28 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe API::Entities::Release do
2020-01-01 13:55:28 +05:30
let_it_be(:project) { create(:project) }
2021-04-29 21:17:54 +05:30
2020-06-23 00:09:42 +05:30
let(:release) { create(:release, project: project) }
2020-04-22 19:07:51 +05:30
let(:evidence) { release.evidences.first }
let(:user) { create(:user) }
2021-06-08 01:23:25 +05:30
let(:entity) { described_class.new(release, current_user: user, include_html_description: include_html_description).as_json }
let(:include_html_description) { false }
2020-04-08 14:13:33 +05:30
2020-06-23 00:09:42 +05:30
before do
::Releases::CreateEvidenceService.new(release).execute
end
2020-04-22 19:07:51 +05:30
describe 'evidences' do
2020-01-01 13:55:28 +05:30
context 'when the current user can download code' do
2020-04-22 19:07:51 +05:30
let(:entity_evidence) { entity[:evidences].first }
2020-01-01 13:55:28 +05:30
it 'exposes the evidence sha and the json path' do
allow(Ability).to receive(:allowed?).and_call_original
allow(Ability).to receive(:allowed?)
.with(user, :download_code, project).and_return(true)
2020-04-22 19:07:51 +05:30
expect(entity_evidence[:sha]).to eq(evidence.summary_sha)
expect(entity_evidence[:collected_at]).to eq(evidence.collected_at)
expect(entity_evidence[:filepath]).to eq(
Gitlab::Routing.url_helpers.namespace_project_evidence_url(
namespace_id: project.namespace,
project_id: project,
tag: release,
id: evidence.id,
format: :json))
2020-01-01 13:55:28 +05:30
end
end
context 'when the current user cannot download code' do
it 'does not expose any evidence data' do
allow(Ability).to receive(:allowed?).and_call_original
allow(Ability).to receive(:allowed?)
.with(user, :download_code, project).and_return(false)
2020-04-22 19:07:51 +05:30
expect(entity.keys).not_to include(:evidences)
2020-01-01 13:55:28 +05:30
end
end
end
2020-04-08 14:13:33 +05:30
describe 'description_html' do
let(:issue) { create(:issue, :confidential, project: project) }
let(:issue_path) { Gitlab::Routing.url_helpers.project_issue_path(project, issue) }
let(:issue_title) { 'title="%s"' % issue.title }
let(:release) { create(:release, project: project, description: "Now shipping #{issue.to_reference}") }
2020-04-22 19:07:51 +05:30
subject(:description_html) { entity.as_json['description_html'] }
2020-04-08 14:13:33 +05:30
2021-06-08 01:23:25 +05:30
it 'is inexistent' do
expect(description_html).to be_nil
2020-04-08 14:13:33 +05:30
end
2021-06-08 01:23:25 +05:30
context 'when include_html_description option is true' do
let(:include_html_description) { true }
it 'renders special references if current user has access' do
project.add_reporter(user)
expect(description_html).to include(issue_path)
expect(description_html).to include(issue_title)
end
it 'does not render special references if current user has no access' do
project.add_guest(user)
2020-04-08 14:13:33 +05:30
2021-06-08 01:23:25 +05:30
expect(description_html).not_to include(issue_path)
expect(description_html).not_to include(issue_title)
end
2020-04-08 14:13:33 +05:30
end
end
2020-01-01 13:55:28 +05:30
end