Skip to content

Commit

Permalink
fix specs
Browse files Browse the repository at this point in the history
  • Loading branch information
gfx committed Jul 24, 2018
1 parent 89b98b0 commit 2682bd3
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 64 deletions.
18 changes: 9 additions & 9 deletions spec/graphql/relay/array_connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions spec/graphql/relay/base_connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions spec/graphql/relay/mongo_relation_connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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
Expand Down
44 changes: 22 additions & 22 deletions spec/graphql/relay/page_info_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
38 changes: 19 additions & 19 deletions spec/graphql/relay/relation_connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2682bd3

Please sign in to comment.