1# frozen_string_literal: true 2 3require 'spec_helper' 4 5RSpec.describe GitlabSchema.types['Timeframe'] do 6 let(:input) { { start: "2018-06-04", end: "2020-10-06" } } 7 let(:output) { { start: Date.parse(input[:start]), end: Date.parse(input[:end]) } } 8 9 it 'coerces ISO-dates into Time objects' do 10 expect(described_class.coerce_isolated_input(input)).to eq(output) 11 end 12 13 it 'rejects invalid input' do 14 input[:start] = 'foo' 15 16 expect { described_class.coerce_isolated_input(input) } 17 .to raise_error(GraphQL::CoercionError) 18 end 19 20 it 'accepts times as input' do 21 with_time = input.merge(start: '2018-06-04T13:48:14Z') 22 23 expect(described_class.coerce_isolated_input(with_time)).to eq(output) 24 end 25 26 it 'requires both ends of the range' do 27 types = described_class.arguments.slice('start', 'end').values.map(&:type) 28 29 expect(types).to all(be_non_null) 30 end 31 32 it 'rejects invalid range' do 33 input.merge!(start: input[:end], end: input[:start]) 34 35 expect { described_class.coerce_isolated_input(input) } 36 .to raise_error(::Gitlab::Graphql::Errors::ArgumentError, 'start must be before end') 37 end 38end 39