Sha256: 6a2cd093c5d99697e8a67f3045757f253ab2d4dab9f373515e170d164d21e99d

Contents?: true

Size: 1.6 KB

Versions: 7

Compression:

Stored size: 1.6 KB

Contents

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

7 entries across 7 versions & 1 rubygems

Version Path
graphql-1.2.6 spec/graphql/schema/unique_within_type_spec.rb
graphql-1.2.5 spec/graphql/schema/unique_within_type_spec.rb
graphql-1.2.4 spec/graphql/schema/unique_within_type_spec.rb
graphql-1.2.3 spec/graphql/schema/unique_within_type_spec.rb
graphql-1.2.2 spec/graphql/schema/unique_within_type_spec.rb
graphql-1.2.1 spec/graphql/schema/unique_within_type_spec.rb
graphql-1.2.0 spec/graphql/schema/unique_within_type_spec.rb