2019-10-17 09:07:07 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-27 15:10:40 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe GitlabSchema.types['Issue'] do
|
|
|
|
it { expect(described_class).to expose_permissions_using(Types::PermissionTypes::Issue) }
|
|
|
|
|
|
|
|
it { expect(described_class.graphql_name).to eq('Issue') }
|
2019-03-04 02:30:32 +00:00
|
|
|
|
|
|
|
it { expect(described_class).to require_graphql_authorizations(:read_issue) }
|
2019-05-31 16:46:16 +00:00
|
|
|
|
2019-06-07 17:13:26 +00:00
|
|
|
it { expect(described_class.interfaces).to include(Types::Notes::NoteableType.to_graphql) }
|
|
|
|
|
2019-05-31 16:46:16 +00:00
|
|
|
it 'has specific fields' do
|
2019-10-02 03:06:35 +00:00
|
|
|
fields = %i[iid title description state reference author assignees participants labels milestone due_date
|
2019-10-02 00:06:26 +00:00
|
|
|
confidential discussion_locked upvotes downvotes user_notes_count web_path web_url relative_position
|
2019-11-18 15:06:27 +00:00
|
|
|
subscribed time_estimate total_time_spent closed_at created_at updated_at task_completion_status]
|
2019-06-20 08:02:33 +00:00
|
|
|
|
|
|
|
fields.each do |field_name|
|
2019-05-31 16:46:16 +00:00
|
|
|
expect(described_class).to have_graphql_field(field_name)
|
|
|
|
end
|
|
|
|
end
|
2019-09-18 08:26:20 +00:00
|
|
|
|
|
|
|
describe "issue notes" do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project) { create(:project, :public) }
|
|
|
|
let(:issue) { create(:issue, project: project) }
|
|
|
|
let(:confidential_issue) { create(:issue, :confidential, project: project) }
|
|
|
|
let(:private_note_body) { "mentioned in issue #{confidential_issue.to_reference(project)}" }
|
|
|
|
let!(:note1) { create(:note, system: true, noteable: issue, author: user, project: project, note: private_note_body) }
|
|
|
|
let!(:note2) { create(:note, system: true, noteable: issue, author: user, project: project, note: 'public note') }
|
|
|
|
|
|
|
|
let(:query) do
|
|
|
|
%(
|
|
|
|
query {
|
|
|
|
project(fullPath:"#{project.full_path}"){
|
|
|
|
issue(iid:"#{issue.iid}"){
|
|
|
|
descriptionHtml
|
|
|
|
notes{
|
|
|
|
edges{
|
|
|
|
node{
|
|
|
|
bodyHtml
|
|
|
|
author{
|
|
|
|
username
|
|
|
|
}
|
|
|
|
body
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'query issue notes' do
|
|
|
|
subject { GitlabSchema.execute(query, context: { current_user: current_user }).as_json }
|
|
|
|
|
|
|
|
shared_examples_for 'does not include private notes' do
|
|
|
|
it "does not return private notes" do
|
|
|
|
notes = subject.dig("data", "project", "issue", "notes", 'edges')
|
|
|
|
notes_body = notes.map {|n| n.dig('node', 'body')}
|
|
|
|
|
|
|
|
expect(notes.size).to eq 1
|
|
|
|
expect(notes_body).not_to include(private_note_body)
|
|
|
|
expect(notes_body).to include('public note')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'includes private notes' do
|
|
|
|
it "returns all notes" do
|
|
|
|
notes = subject.dig("data", "project", "issue", "notes", 'edges')
|
|
|
|
notes_body = notes.map {|n| n.dig('node', 'body')}
|
|
|
|
|
|
|
|
expect(notes.size).to eq 2
|
|
|
|
expect(notes_body).to include(private_note_body)
|
|
|
|
expect(notes_body).to include('public note')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user signed in' do
|
|
|
|
let(:current_user) { user }
|
|
|
|
|
|
|
|
it_behaves_like 'does not include private notes'
|
|
|
|
|
|
|
|
context 'when user member of the project' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'includes private notes'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is anonymous' do
|
|
|
|
let(:current_user) { nil }
|
|
|
|
|
|
|
|
it_behaves_like 'does not include private notes'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-11-27 15:10:40 +00:00
|
|
|
end
|