From 2682bd30e9368b9132c79e709cf3723e4151a405 Mon Sep 17 00:00:00 2001 From: "FUJI Goro (gfx)" Date: Tue, 24 Jul 2018 11:08:37 +0900 Subject: [PATCH] fix specs --- spec/graphql/relay/array_connection_spec.rb | 18 ++++---- spec/graphql/relay/base_connection_spec.rb | 6 +-- .../relay/mongo_relation_connection_spec.rb | 22 +++++----- spec/graphql/relay/page_info_spec.rb | 44 +++++++++---------- .../graphql/relay/relation_connection_spec.rb | 38 ++++++++-------- 5 files changed, 64 insertions(+), 64 deletions(-) diff --git a/spec/graphql/relay/array_connection_spec.rb b/spec/graphql/relay/array_connection_spec.rb index e13f1613a71..0ab85dc3435 100644 --- a/spec/graphql/relay/array_connection_spec.rb +++ b/spec/graphql/relay/array_connection_spec.rb @@ -43,8 +43,8 @@ def get_page_info(result, key = "bases") assert_equal(2, number_of_ships) assert_equal(true, result["data"]["rebels"]["ships"]["pageInfo"]["hasNextPage"]) assert_equal(false, result["data"]["rebels"]["ships"]["pageInfo"]["hasPreviousPage"]) - assert_equal("MQ==", result["data"]["rebels"]["ships"]["pageInfo"]["startCursor"]) - assert_equal("Mg==", result["data"]["rebels"]["ships"]["pageInfo"]["endCursor"]) + assert_equal("MQ", result["data"]["rebels"]["ships"]["pageInfo"]["startCursor"]) + assert_equal("Mg", result["data"]["rebels"]["ships"]["pageInfo"]["endCursor"]) result = star_wars_query(query_string, "first" => 3) number_of_ships = get_names(result).length @@ -55,14 +55,14 @@ def get_page_info(result, key = "bases") result = star_wars_query(query_string, "first" => 2) assert_equal(true, result["data"]["rebels"]["ships"]["pageInfo"]["hasNextPage"]) assert_equal(false, result["data"]["rebels"]["ships"]["pageInfo"]["hasPreviousPage"]) - assert_equal("MQ==", result["data"]["rebels"]["ships"]["pageInfo"]["startCursor"]) - assert_equal("Mg==", result["data"]["rebels"]["ships"]["pageInfo"]["endCursor"]) + assert_equal("MQ", result["data"]["rebels"]["ships"]["pageInfo"]["startCursor"]) + assert_equal("Mg", result["data"]["rebels"]["ships"]["pageInfo"]["endCursor"]) result = star_wars_query(query_string, "first" => 100) assert_equal(false, result["data"]["rebels"]["ships"]["pageInfo"]["hasNextPage"]) assert_equal(false, result["data"]["rebels"]["ships"]["pageInfo"]["hasPreviousPage"]) - assert_equal("MQ==", result["data"]["rebels"]["ships"]["pageInfo"]["startCursor"]) - assert_equal("NQ==", result["data"]["rebels"]["ships"]["pageInfo"]["endCursor"]) + assert_equal("MQ", result["data"]["rebels"]["ships"]["pageInfo"]["startCursor"]) + assert_equal("NQ", result["data"]["rebels"]["ships"]["pageInfo"]["endCursor"]) end it "provides bidirectional_pagination" do @@ -166,8 +166,8 @@ def get_page_info(result, key = "bases") assert_equal(false, result["data"]["rebels"]["ships"]["pageInfo"]["hasNextPage"]) assert_equal(false, result["data"]["rebels"]["ships"]["pageInfo"]["hasPreviousPage"]) - assert_equal("MQ==", result["data"]["rebels"]["ships"]["pageInfo"]["startCursor"]) - assert_equal("NQ==", result["data"]["rebels"]["ships"]["pageInfo"]["endCursor"]) + assert_equal("MQ", result["data"]["rebels"]["ships"]["pageInfo"]["startCursor"]) + assert_equal("NQ", result["data"]["rebels"]["ships"]["pageInfo"]["endCursor"]) assert_equal(5, result["data"]["rebels"]["ships"]["edges"].length) end @@ -217,7 +217,7 @@ def get_names(result) assert_equal(["Yavin", "Echo Base"], get_names(result)) assert_equal(false, get_page_info(result)["hasPreviousPage"], "hasPreviousPage is false when last is not specified") - third_cursor = "Mw==" + third_cursor = "Mw" first_and_second_names = ["Yavin", "Echo Base"] result = star_wars_query(query_string, "last" => 100, "before" => third_cursor) assert_equal(first_and_second_names, get_names(result)) diff --git a/spec/graphql/relay/base_connection_spec.rb b/spec/graphql/relay/base_connection_spec.rb index ee3e8fea752..64d4c410279 100644 --- a/spec/graphql/relay/base_connection_spec.rb +++ b/spec/graphql/relay/base_connection_spec.rb @@ -77,11 +77,11 @@ def decode(str, nonce: false); str.reverse; end assert_equal "Person/1", conn.decode("1/nosreP") end - it "defaults to base64" do + it "defaults to base64 (urlsafe_base64 without padding)" do conn = GraphQL::Relay::BaseConnection.new([], {}, context: nil) - assert_equal "UGVyc29uLzE=", conn.encode("Person/1") - assert_equal "Person/1", conn.decode("UGVyc29uLzE=") + assert_equal "UGVyc29uLzE", conn.encode("Person/1") + assert_equal "Person/1", conn.decode("UGVyc29uLzE=") # can decode with padding end it "handles trimmed base64" do diff --git a/spec/graphql/relay/mongo_relation_connection_spec.rb b/spec/graphql/relay/mongo_relation_connection_spec.rb index 685382e149c..1823760211a 100644 --- a/spec/graphql/relay/mongo_relation_connection_spec.rb +++ b/spec/graphql/relay/mongo_relation_connection_spec.rb @@ -62,19 +62,19 @@ def get_last_cursor(result) assert_equal(2, get_names(result).length) assert_equal(true, get_page_info(result)["hasNextPage"]) assert_equal(false, get_page_info(result)["hasPreviousPage"]) - assert_equal("MQ==", get_page_info(result)["startCursor"]) - assert_equal("Mg==", get_page_info(result)["endCursor"]) - assert_equal("MQ==", get_first_cursor(result)) - assert_equal("Mg==", get_last_cursor(result)) + assert_equal("MQ", get_page_info(result)["startCursor"]) + assert_equal("Mg", get_page_info(result)["endCursor"]) + assert_equal("MQ", get_first_cursor(result)) + assert_equal("Mg", get_last_cursor(result)) result = star_trek_query(query_string, "first" => 3) assert_equal(3, get_names(result).length) assert_equal(false, get_page_info(result)["hasNextPage"]) assert_equal(false, get_page_info(result)["hasPreviousPage"]) - assert_equal("MQ==", get_page_info(result)["startCursor"]) - assert_equal("Mw==", get_page_info(result)["endCursor"]) - assert_equal("MQ==", get_first_cursor(result)) - assert_equal("Mw==", get_last_cursor(result)) + assert_equal("MQ", get_page_info(result)["startCursor"]) + assert_equal("Mw", get_page_info(result)["endCursor"]) + assert_equal("MQ", get_first_cursor(result)) + assert_equal("Mw", get_last_cursor(result)) end it 'provides custom fields on the connection type' do @@ -270,7 +270,7 @@ def get_last_cursor(result) assert_equal(first_and_second_names, get_names(result)) assert_equal(false, result["data"]["federation"]["bases"]["pageInfo"]["hasPreviousPage"], "hasPreviousPage is false when last is not specified") - third_cursor = "Mw==" + third_cursor = "Mw" result = star_trek_query(query_string, "last" => 100, "before" => third_cursor) assert_equal(first_and_second_names, get_names(result)) @@ -464,8 +464,8 @@ def get_names(result, field_name) let(:connection) { GraphQL::Relay::MongoRelationConnection.new(StarTrek::Base.where(faction_id: 1), {}) } it "returns the cursor for a node in the connection" do - assert_equal "MQ==", connection.cursor_from_node(StarTrek::Base.all[0]) - assert_equal "Mg==", connection.cursor_from_node(StarTrek::Base.all[1]) + assert_equal "MQ", connection.cursor_from_node(StarTrek::Base.all[0]) + assert_equal "Mg", connection.cursor_from_node(StarTrek::Base.all[1]) end it "raises when the node isn't found" do diff --git a/spec/graphql/relay/page_info_spec.rb b/spec/graphql/relay/page_info_spec.rb index 1dd6ebc288d..fc6dc41d4a1 100644 --- a/spec/graphql/relay/page_info_spec.rb +++ b/spec/graphql/relay/page_info_spec.rb @@ -46,63 +46,63 @@ def get_last_cursor(result) result = star_wars_query(query_string, "first" => 2) assert_equal(true, get_page_info(result)["hasNextPage"]) assert_equal(false, get_page_info(result)["hasPreviousPage"], "hasPreviousPage is false if 'last' is missing") - assert_equal("MQ==", get_page_info(result)["startCursor"]) - assert_equal("Mg==", get_page_info(result)["endCursor"]) + assert_equal("MQ", get_page_info(result)["startCursor"]) + assert_equal("Mg", get_page_info(result)["endCursor"]) last_cursor = get_last_cursor(result) result = star_wars_query(query_string, "first" => 100, "after" => last_cursor) assert_equal(false, get_page_info(result)["hasNextPage"]) assert_equal(false, get_page_info(result)["hasPreviousPage"]) - assert_equal("Mw==", get_page_info(result)["startCursor"]) - assert_equal("Mw==", get_page_info(result)["endCursor"]) + assert_equal("Mw", get_page_info(result)["startCursor"]) + assert_equal("Mw", get_page_info(result)["endCursor"]) end it "hasPreviousPage if there are more items" do result = star_wars_query(query_string, "last" => 100, "before" => cursor_of_last_base) assert_equal(false, get_page_info(result)["hasNextPage"]) assert_equal(false, get_page_info(result)["hasPreviousPage"]) - assert_equal("MQ==", get_page_info(result)["startCursor"]) - assert_equal("Mg==", get_page_info(result)["endCursor"]) + assert_equal("MQ", get_page_info(result)["startCursor"]) + assert_equal("Mg", get_page_info(result)["endCursor"]) result = star_wars_query(query_string, "last" => 1, "before" => cursor_of_last_base) assert_equal(false, get_page_info(result)["hasNextPage"]) assert_equal(true, get_page_info(result)["hasPreviousPage"]) - assert_equal("Mg==", get_page_info(result)["startCursor"]) - assert_equal("Mg==", get_page_info(result)["endCursor"]) + assert_equal("Mg", get_page_info(result)["startCursor"]) + assert_equal("Mg", get_page_info(result)["endCursor"]) end it "has both if first and last are present" do result = star_wars_query(query_string, "last" => 1, "first" => 1, "before" => cursor_of_last_base) assert_equal(true, get_page_info(result)["hasNextPage"]) assert_equal(true, get_page_info(result)["hasPreviousPage"]) - assert_equal("MQ==", get_page_info(result)["startCursor"]) - assert_equal("MQ==", get_page_info(result)["endCursor"]) + assert_equal("MQ", get_page_info(result)["startCursor"]) + assert_equal("MQ", get_page_info(result)["endCursor"]) end it "startCursor and endCursor are the cursors of the first and last edge" do result = star_wars_query(query_string, "first" => 2) assert_equal(true, get_page_info(result)["hasNextPage"]) assert_equal(false, get_page_info(result)["hasPreviousPage"]) - assert_equal("MQ==", get_page_info(result)["startCursor"]) - assert_equal("Mg==", get_page_info(result)["endCursor"]) - assert_equal("MQ==", get_first_cursor(result)) - assert_equal("Mg==", get_last_cursor(result)) + assert_equal("MQ", get_page_info(result)["startCursor"]) + assert_equal("Mg", get_page_info(result)["endCursor"]) + assert_equal("MQ", get_first_cursor(result)) + assert_equal("Mg", get_last_cursor(result)) result = star_wars_query(query_string, "first" => 1, "after" => get_page_info(result)["endCursor"]) assert_equal(false, get_page_info(result)["hasNextPage"]) assert_equal(false, get_page_info(result)["hasPreviousPage"]) - assert_equal("Mw==", get_page_info(result)["startCursor"]) - assert_equal("Mw==", get_page_info(result)["endCursor"]) - assert_equal("Mw==", get_first_cursor(result)) - assert_equal("Mw==", get_last_cursor(result)) + assert_equal("Mw", get_page_info(result)["startCursor"]) + assert_equal("Mw", get_page_info(result)["endCursor"]) + assert_equal("Mw", get_first_cursor(result)) + assert_equal("Mw", get_last_cursor(result)) result = star_wars_query(query_string, "last" => 1, "before" => get_page_info(result)["endCursor"]) assert_equal(false, get_page_info(result)["hasNextPage"]) assert_equal(true, get_page_info(result)["hasPreviousPage"]) - assert_equal("Mg==", get_page_info(result)["startCursor"]) - assert_equal("Mg==", get_page_info(result)["endCursor"]) - assert_equal("Mg==", get_first_cursor(result)) - assert_equal("Mg==", get_last_cursor(result)) + assert_equal("Mg", get_page_info(result)["startCursor"]) + assert_equal("Mg", get_page_info(result)["endCursor"]) + assert_equal("Mg", get_first_cursor(result)) + assert_equal("Mg", get_last_cursor(result)) end end diff --git a/spec/graphql/relay/relation_connection_spec.rb b/spec/graphql/relay/relation_connection_spec.rb index 2ede972193b..0155c7c6718 100644 --- a/spec/graphql/relay/relation_connection_spec.rb +++ b/spec/graphql/relay/relation_connection_spec.rb @@ -51,19 +51,19 @@ def get_last_cursor(result) assert_equal(2, get_names(result).length) assert_equal(true, get_page_info(result)["hasNextPage"]) assert_equal(false, get_page_info(result)["hasPreviousPage"]) - assert_equal("MQ==", get_page_info(result)["startCursor"]) - assert_equal("Mg==", get_page_info(result)["endCursor"]) - assert_equal("MQ==", get_first_cursor(result)) - assert_equal("Mg==", get_last_cursor(result)) + assert_equal("MQ", get_page_info(result)["startCursor"]) + assert_equal("Mg", get_page_info(result)["endCursor"]) + assert_equal("MQ", get_first_cursor(result)) + assert_equal("Mg", get_last_cursor(result)) result = star_wars_query(query_string, "first" => 3) assert_equal(3, get_names(result).length) assert_equal(false, get_page_info(result)["hasNextPage"]) assert_equal(false, get_page_info(result)["hasPreviousPage"]) - assert_equal("MQ==", get_page_info(result)["startCursor"]) - assert_equal("Mw==", get_page_info(result)["endCursor"]) - assert_equal("MQ==", get_first_cursor(result)) - assert_equal("Mw==", get_last_cursor(result)) + assert_equal("MQ", get_page_info(result)["startCursor"]) + assert_equal("Mw", get_page_info(result)["endCursor"]) + assert_equal("MQ", get_first_cursor(result)) + assert_equal("Mw", get_last_cursor(result)) end it 'provides custom fields on the connection type' do @@ -288,7 +288,7 @@ def get_last_cursor(result) assert_equal(first_and_second_names, get_names(result)) assert_equal(false, result["data"]["empire"]["bases"]["pageInfo"]["hasPreviousPage"], "hasPreviousPage is false when last is not specified") - third_cursor = "Mw==" + third_cursor = "Mw" result = star_wars_query(query_string, "last" => 100, "before" => third_cursor) assert_equal(first_and_second_names, get_names(result)) @@ -528,19 +528,19 @@ def get_last_cursor(result) assert_equal(2, get_names(result).length) assert_equal(true, get_page_info(result)["hasNextPage"]) assert_equal(false, get_page_info(result)["hasPreviousPage"]) - assert_equal("MQ==", get_page_info(result)["startCursor"]) - assert_equal("Mg==", get_page_info(result)["endCursor"]) - assert_equal("MQ==", get_first_cursor(result)) - assert_equal("Mg==", get_last_cursor(result)) + assert_equal("MQ", get_page_info(result)["startCursor"]) + assert_equal("Mg", get_page_info(result)["endCursor"]) + assert_equal("MQ", get_first_cursor(result)) + assert_equal("Mg", get_last_cursor(result)) result = star_wars_query(query_string, "first" => 3) assert_equal(3, get_names(result).length) assert_equal(false, get_page_info(result)["hasNextPage"]) assert_equal(false, get_page_info(result)["hasPreviousPage"]) - assert_equal("MQ==", get_page_info(result)["startCursor"]) - assert_equal("Mw==", get_page_info(result)["endCursor"]) - assert_equal("MQ==", get_first_cursor(result)) - assert_equal("Mw==", get_last_cursor(result)) + assert_equal("MQ", get_page_info(result)["startCursor"]) + assert_equal("Mw", get_page_info(result)["endCursor"]) + assert_equal("MQ", get_first_cursor(result)) + assert_equal("Mw", get_last_cursor(result)) end it 'provides custom fields on the connection type' do @@ -635,8 +635,8 @@ def get_last_cursor(result) let(:connection) { GraphQL::Relay::RelationConnection.new(StarWars::Base.where(faction_id: 1), {}) } it "returns the cursor for a node in the connection" do - assert_equal "MQ==", connection.cursor_from_node(StarWars::Base.all[0]) - assert_equal "Mg==", connection.cursor_from_node(StarWars::Base.all[1]) + assert_equal "MQ", connection.cursor_from_node(StarWars::Base.all[0]) + assert_equal "Mg", connection.cursor_from_node(StarWars::Base.all[1]) end it "raises when the node isn't found" do