2020-11-24 15:15:51 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
RSpec.describe 'A Todoable that implements the CurrentUserTodos interface',
|
|
|
|
feature_category: :team_planning do
|
2020-11-24 15:15:51 +05:30
|
|
|
include GraphqlHelpers
|
|
|
|
|
|
|
|
let_it_be(:current_user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project, :public) }
|
|
|
|
let_it_be(:todoable) { create(:issue, project: project) }
|
|
|
|
let_it_be(:done_todo) { create(:todo, state: :done, target: todoable, user: current_user) }
|
|
|
|
let_it_be(:pending_todo) { create(:todo, state: :pending, target: todoable, user: current_user) }
|
2021-09-30 23:02:18 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
let(:state) { 'null' }
|
|
|
|
|
|
|
|
let(:todoable_response) do
|
|
|
|
graphql_data_at(:project, :issue, :currentUserTodos, :nodes)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:query) do
|
|
|
|
<<~GQL
|
|
|
|
{
|
|
|
|
project(fullPath: "#{project.full_path}") {
|
|
|
|
issue(iid: "#{todoable.iid}") {
|
|
|
|
currentUserTodos(state: #{state}) {
|
|
|
|
nodes {
|
|
|
|
#{all_graphql_fields_for('Todo', max_depth: 1)}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GQL
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns todos of the current user' do
|
|
|
|
post_graphql(query, current_user: current_user)
|
|
|
|
|
|
|
|
expect(todoable_response).to contain_exactly(
|
2022-07-16 23:28:13 +05:30
|
|
|
a_graphql_entity_for(done_todo),
|
|
|
|
a_graphql_entity_for(pending_todo)
|
2020-11-24 15:15:51 +05:30
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not return todos of another user', :aggregate_failures do
|
|
|
|
post_graphql(query, current_user: create(:user))
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:success)
|
|
|
|
expect(todoable_response).to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not error when there is no logged in user', :aggregate_failures do
|
|
|
|
post_graphql(query)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:success)
|
|
|
|
expect(todoable_response).to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when `state` argument is `pending`' do
|
|
|
|
let(:state) { 'pending' }
|
|
|
|
|
|
|
|
it 'returns just the pending todo' do
|
|
|
|
post_graphql(query, current_user: current_user)
|
|
|
|
|
|
|
|
expect(todoable_response).to contain_exactly(
|
2022-07-16 23:28:13 +05:30
|
|
|
a_graphql_entity_for(pending_todo)
|
2020-11-24 15:15:51 +05:30
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when `state` argument is `done`' do
|
|
|
|
let(:state) { 'done' }
|
|
|
|
|
|
|
|
it 'returns just the done todo' do
|
|
|
|
post_graphql(query, current_user: current_user)
|
|
|
|
|
|
|
|
expect(todoable_response).to contain_exactly(
|
2022-07-16 23:28:13 +05:30
|
|
|
a_graphql_entity_for(done_todo)
|
2020-11-24 15:15:51 +05:30
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|