Welcome to mirror list, hosted at ThFree Co, Russian Federation.

duration_type_spec.rb « types « graphql « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5b88819f1575b1b11ced5d6842ce6850ab3949e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe GitlabSchema.types['Duration'] do
  let(:duration) { 17.minutes }

  it 'presents information as a floating point number' do
    expect(described_class.coerce_isolated_result(duration)).to eq(duration.to_f)
  end

  it 'accepts integers as input' do
    expect(described_class.coerce_isolated_input(100)).to eq(100.0)
  end

  it 'accepts floats as input' do
    expect(described_class.coerce_isolated_input(0.5)).to eq(0.5)
  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