Sha256: 6c8b22571ce635640cb66cc0d16bf28eaff5d8a3088d35a59b532b1d8c40aa74

Contents?: true

Size: 1.66 KB

Versions: 28

Compression:

Stored size: 1.66 KB

Contents

# frozen_string_literal: true
require "spec_helper"

describe GraphQL::Subscriptions::Serialize do
  def serialize_dump(v)
    GraphQL::Subscriptions::Serialize.dump(v)
  end

  def serialize_load(v)
    GraphQL::Subscriptions::Serialize.load(v)
  end

  if defined?(GlobalID)
    it "should serialize GlobalID::Identification in Array/Hash" do
      user_a = GlobalIDUser.new("a")
      user_b = GlobalIDUser.new("b")

      str_a = serialize_dump(["first", 2, user_a])
      str_b = serialize_dump({"first" => 'first', "second" => 2, "user" => user_b})

      assert_equal str_a, '["first",2,{"__gid__":"Z2lkOi8vZ3JhcGhxbC1ydWJ5LXRlc3QvR2xvYmFsSURVc2VyL2E"}]'
      assert_equal str_b, '{"first":"first","second":2,"user":{"__gid__":"Z2lkOi8vZ3JhcGhxbC1ydWJ5LXRlc3QvR2xvYmFsSURVc2VyL2I"}}'
    end

    it "should deserialize GlobalID::Identification in Array/Hash" do
      user_a = GlobalIDUser.new("a")
      user_b = GlobalIDUser.new("b")

      str_a = '["first",2,{"__gid__":"Z2lkOi8vZ3JhcGhxbC1ydWJ5LXRlc3QvR2xvYmFsSURVc2VyL2E"}]'
      str_b = '{"first":"first","second":2,"user":{"__gid__":"Z2lkOi8vZ3JhcGhxbC1ydWJ5LXRlc3QvR2xvYmFsSURVc2VyL2I"}}'

      parsed_obj_a = serialize_load(str_a)
      parsed_obj_b = serialize_load(str_b)

      assert_equal parsed_obj_a, ["first", 2, user_a]
      assert_equal parsed_obj_b, {'first' => 'first', 'second' => 2, 'user' => user_b}
    end
  end

  it "can deserialize symbols" do
    value = { a: :a, "b" => 2 }

    dumped = serialize_dump(value)
    expected_dumped = '{"a":{"__sym__":"a"},"b":2,"__sym_keys__":["a"]}'
    assert_equal expected_dumped, dumped
    loaded = serialize_load(dumped)
    assert_equal value, loaded
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
graphql-1.8.18 spec/graphql/subscriptions/serialize_spec.rb
graphql-1.9.11 spec/graphql/subscriptions/serialize_spec.rb
graphql-1.9.10 spec/graphql/subscriptions/serialize_spec.rb
graphql-1.9.9 spec/graphql/subscriptions/serialize_spec.rb
graphql-1.9.8 spec/graphql/subscriptions/serialize_spec.rb
graphql-1.9.7 spec/graphql/subscriptions/serialize_spec.rb
graphql-1.9.6 spec/graphql/subscriptions/serialize_spec.rb
graphql-1.9.5 spec/graphql/subscriptions/serialize_spec.rb
graphql-1.9.4 spec/graphql/subscriptions/serialize_spec.rb
graphql-1.9.3 spec/graphql/subscriptions/serialize_spec.rb
graphql-1.9.2 spec/graphql/subscriptions/serialize_spec.rb
graphql-1.8.17 spec/graphql/subscriptions/serialize_spec.rb
graphql-1.8.16 spec/graphql/subscriptions/serialize_spec.rb
graphql-1.9.1 spec/graphql/subscriptions/serialize_spec.rb
graphql-1.9.0 spec/graphql/subscriptions/serialize_spec.rb
graphql-1.8.15 spec/graphql/subscriptions/serialize_spec.rb
graphql-1.9.0.pre4 spec/graphql/subscriptions/serialize_spec.rb
graphql-1.8.14 spec/graphql/subscriptions/serialize_spec.rb
graphql-1.9.0.pre3 spec/graphql/subscriptions/serialize_spec.rb
graphql-1.9.0.pre2 spec/graphql/subscriptions/serialize_spec.rb