2022-08-13 15:12:31 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'Todo Query' do
|
|
|
|
include GraphqlHelpers
|
|
|
|
|
|
|
|
let_it_be(:current_user) { nil }
|
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
let_it_be(:issue) { create(:issue, project: project) }
|
|
|
|
|
|
|
|
let_it_be(:todo_owner) { create(:user) }
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
let_it_be(:todo) { create(:todo, user: todo_owner, target: issue) }
|
|
|
|
|
|
|
|
let(:todo_subject) { todo }
|
2022-08-13 15:12:31 +05:30
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_developer(todo_owner)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:fields) do
|
|
|
|
<<~GRAPHQL
|
|
|
|
id
|
2022-11-25 23:54:43 +05:30
|
|
|
targetType
|
|
|
|
target {
|
|
|
|
webUrl
|
|
|
|
... on WorkItem {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
2022-08-13 15:12:31 +05:30
|
|
|
GRAPHQL
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:query) do
|
2022-11-25 23:54:43 +05:30
|
|
|
graphql_query_for(:todo, { id: todo_subject.to_global_id.to_s }, fields)
|
2022-08-13 15:12:31 +05:30
|
|
|
end
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
subject(:graphql_response) do
|
2022-08-13 15:12:31 +05:30
|
|
|
result = GitlabSchema.execute(query, context: { current_user: current_user }).to_h
|
|
|
|
graphql_dig_at(result, :data, :todo)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when requesting user is todo owner' do
|
|
|
|
let(:current_user) { todo_owner }
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
it { is_expected.to include('id' => todo_subject.to_global_id.to_s) }
|
|
|
|
|
|
|
|
context 'when todo target is WorkItem' do
|
|
|
|
let(:work_item) { create(:work_item, :task, project: project) }
|
|
|
|
let(:todo_subject) { create(:todo, user: todo_owner, target: work_item, target_type: WorkItem.name) }
|
|
|
|
|
|
|
|
it 'works with a WorkItem target' do
|
|
|
|
expect(graphql_response).to include(
|
|
|
|
'id' => todo_subject.to_gid.to_s,
|
|
|
|
'targetType' => 'WORKITEM',
|
|
|
|
'target' => {
|
|
|
|
'id' => work_item.to_gid.to_s,
|
|
|
|
'webUrl' => Gitlab::UrlBuilder.build(work_item)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2022-08-13 15:12:31 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when requesting user is not todo owner' do
|
|
|
|
let(:current_user) { create(:user) }
|
|
|
|
|
|
|
|
it { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when unauthenticated' do
|
|
|
|
it { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
end
|