Commit 71355af6 authored by Luke Duncalfe's avatar Luke Duncalfe

GraphQL TimeType to throw GraphQL::CoercionErrors

parent 3f6b3993
......@@ -7,6 +7,8 @@ module Types
def self.coerce_input(value, ctx)
Time.parse(value)
rescue ArgumentError, TypeError => e
raise GraphQL::CoercionError, e.message
end
def self.coerce_result(value, ctx)
......
......@@ -15,4 +15,14 @@ RSpec.describe GitlabSchema.types['Time'] do
it 'coerces an ISO-time into Time object' do
expect(described_class.coerce_isolated_input(iso)).to eq(time)
end
it 'rejects invalid input' do
expect { described_class.coerce_isolated_input('not valid') }
.to raise_error(GraphQL::CoercionError)
end
it 'rejects nil' do
expect { described_class.coerce_isolated_input(nil) }
.to raise_error(GraphQL::CoercionError)
end
end
......@@ -49,13 +49,13 @@ RSpec.describe 'Setting Due Date of an issue' do
expect(mutation_response['issue']['dueDate']).to eq(2.days.since.to_date.to_s)
end
context 'when passing due date without a date value' do
context 'when the due date value is not a valid time' do
let(:input) { { due_date: 'test' } }
it 'returns internal server error' do
it 'returns a coercion error' do
post_graphql_mutation(mutation, current_user: current_user)
expect(graphql_errors).to include(a_hash_including('message' => 'Internal server error'))
expect(graphql_errors).to include(a_hash_including('message' => /provided invalid value for dueDate/))
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment