debian-mirror-gitlab/spec/requests/api/graphql/mutations/issues/set_due_date_spec.rb

85 lines
2.4 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 'Setting Due Date of an issue' do
2020-01-01 13:55:28 +05:30
include GraphqlHelpers
let(:current_user) { create(:user) }
let(:issue) { create(:issue) }
let(:project) { issue.project }
let(:input) { { due_date: 2.days.since } }
let(:mutation) do
variables = {
project_path: project.full_path,
iid: issue.iid.to_s
}
graphql_mutation(:issue_set_due_date, variables.merge(input),
<<-QL.strip_heredoc
clientMutationId
errors
issue {
iid
dueDate
}
QL
)
end
def mutation_response
graphql_mutation_response(:issue_set_due_date)
end
before do
project.add_developer(current_user)
end
it 'returns an error if the user is not allowed to update the issue' do
2021-12-11 22:18:48 +05:30
error = Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR
2020-01-01 13:55:28 +05:30
post_graphql_mutation(mutation, current_user: create(:user))
expect(graphql_errors).to include(a_hash_including('message' => error))
end
2021-06-08 01:23:25 +05:30
context 'when due date value is a valid date' do
it 'updates the issue due date' do
post_graphql_mutation(mutation, current_user: current_user)
expect(response).to have_gitlab_http_status(:success)
expect(mutation_response['issue']['dueDate']).to eq(2.days.since.to_date.to_s)
end
end
context 'when due date value is null' do
let(:input) { { due_date: nil } }
it 'updates the issue to remove the due date' do
post_graphql_mutation(mutation, current_user: current_user)
2020-01-01 13:55:28 +05:30
2021-06-08 01:23:25 +05:30
expect(response).to have_gitlab_http_status(:success)
expect(mutation_response['issue']['dueDate']).to be nil
end
end
context 'when due date argument is not given' do
let(:input) { {} }
it 'returns an error' do
post_graphql_mutation(mutation, current_user: current_user)
2021-10-27 15:23:28 +05:30
expect(graphql_errors).to include(a_hash_including('message' => /Arguments must be provided: dueDate/))
2021-06-08 01:23:25 +05:30
end
2020-01-01 13:55:28 +05:30
end
2020-10-24 23:57:45 +05:30
context 'when the due date value is not a valid time' do
2020-01-01 13:55:28 +05:30
let(:input) { { due_date: 'test' } }
2020-10-24 23:57:45 +05:30
it 'returns a coercion error' do
2020-01-01 13:55:28 +05:30
post_graphql_mutation(mutation, current_user: current_user)
2020-10-24 23:57:45 +05:30
expect(graphql_errors).to include(a_hash_including('message' => /provided invalid value for dueDate/))
2020-01-01 13:55:28 +05:30
end
end
end