diff options
Diffstat (limited to 'spec/requests/api/graphql/todo_query_spec.rb')
-rw-r--r-- | spec/requests/api/graphql/todo_query_spec.rb | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/spec/requests/api/graphql/todo_query_spec.rb b/spec/requests/api/graphql/todo_query_spec.rb index 3f743f4402a..be7242d95bd 100644 --- a/spec/requests/api/graphql/todo_query_spec.rb +++ b/spec/requests/api/graphql/todo_query_spec.rb @@ -11,23 +11,31 @@ RSpec.describe 'Todo Query' do let_it_be(:todo_owner) { create(:user) } - let_it_be(:todo) { create(:todo, user: todo_owner, target: project) } - - before do - project.add_developer(todo_owner) - end + let_it_be(:todo) { create(:todo, user: todo_owner, target: issue) } + let(:todo_subject) { todo } let(:fields) do <<~GRAPHQL id + targetType + target { + webUrl + ... on WorkItem { + id + } + } GRAPHQL end let(:query) do - graphql_query_for(:todo, { id: todo.to_global_id.to_s }, fields) + graphql_query_for(:todo, { id: todo_subject.to_global_id.to_s }, fields) + end + + before do + project.add_developer(todo_owner) end - subject do + subject(:graphql_response) do result = GitlabSchema.execute(query, context: { current_user: current_user }).to_h graphql_dig_at(result, :data, :todo) end @@ -35,7 +43,23 @@ RSpec.describe 'Todo Query' do context 'when requesting user is todo owner' do let(:current_user) { todo_owner } - it { is_expected.to include('id' => todo.to_global_id.to_s) } + 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 end context 'when requesting user is not todo owner' do |