Sha256: c70d94174d3302157cf020806ad149b177edae22dc719836055b0bdfc07bfb70

Contents?: true

Size: 1.63 KB

Versions: 19

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true
require "spec_helper"

describe GraphQL::Schema::UniqueWithinType do
  describe 'encode / decode' do
    it 'Converts typename and ID to and from ID' do
      global_id = GraphQL::Schema::UniqueWithinType.encode("SomeType", 123)
      type_name, id = GraphQL::Schema::UniqueWithinType.decode(global_id)
      assert_equal("SomeType", type_name)
      assert_equal("123", id)
    end

    it "allows you specify default separator" do
      GraphQL::Schema::UniqueWithinType.default_id_separator = '|'
      global_id = GraphQL::Schema::UniqueWithinType.encode("Type-With-UUID", "250cda0e-a89d-41cf-99e1-2872d89f1100")
      type_name, id = GraphQL::Schema::UniqueWithinType.decode(global_id)
      assert_equal("Type-With-UUID", type_name)
      assert_equal("250cda0e-a89d-41cf-99e1-2872d89f1100", id)
      GraphQL::Schema::UniqueWithinType.default_id_separator = '-'
    end

    it "allows you to specify the separator" do
      custom_separator = "---"
      global_id = GraphQL::Schema::UniqueWithinType.encode("Type-With-UUID", "250cda0e-a89d-41cf-99e1-2872d89f1100", separator: custom_separator)
      type_name, id = GraphQL::Schema::UniqueWithinType.decode(global_id, separator: custom_separator)
      assert_equal("Type-With-UUID", type_name)
      assert_equal("250cda0e-a89d-41cf-99e1-2872d89f1100", id)
    end

    it "raises an error if you try and use a reserved character in the ID" do
      err = assert_raises(RuntimeError) {
        GraphQL::Schema::UniqueWithinType.encode("Best-Thing", "234")
      }
      assert_includes err.message, "encode(Best-Thing, 234) contains reserved characters `-`"
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
graphql-1.5.13 spec/graphql/schema/unique_within_type_spec.rb
graphql-1.5.7.1 spec/graphql/schema/unique_within_type_spec.rb
graphql-1.5.12 spec/graphql/schema/unique_within_type_spec.rb
graphql-1.5.11 spec/graphql/schema/unique_within_type_spec.rb
graphql-1.5.10 spec/graphql/schema/unique_within_type_spec.rb
graphql-1.5.9 spec/graphql/schema/unique_within_type_spec.rb
graphql-1.5.8 spec/graphql/schema/unique_within_type_spec.rb
graphql-1.5.7 spec/graphql/schema/unique_within_type_spec.rb
graphql-1.5.6 spec/graphql/schema/unique_within_type_spec.rb
graphql-1.5.5 spec/graphql/schema/unique_within_type_spec.rb
graphql-1.5.4 spec/graphql/schema/unique_within_type_spec.rb
graphql-1.5.3 spec/graphql/schema/unique_within_type_spec.rb
graphql-1.4.5 spec/graphql/schema/unique_within_type_spec.rb
graphql-1.4.4 spec/graphql/schema/unique_within_type_spec.rb
graphql-1.4.3 spec/graphql/schema/unique_within_type_spec.rb
graphql-1.4.2 spec/graphql/schema/unique_within_type_spec.rb
graphql-1.4.1 spec/graphql/schema/unique_within_type_spec.rb
graphql-1.4.0 spec/graphql/schema/unique_within_type_spec.rb
graphql-1.3.0 spec/graphql/schema/unique_within_type_spec.rb