spec/graphql/relay/array_connection_spec.rb in graphql-relay-0.2.0 vs spec/graphql/relay/array_connection_spec.rb in graphql-relay-0.3.0
- old
+ new
@@ -3,15 +3,19 @@
describe GraphQL::Relay::ArrayConnection do
def get_names(result)
ships = result["data"]["rebels"]["ships"]["edges"]
names = ships.map { |e| e["node"]["name"] }
end
+
+ def get_last_cursor(result)
+ result["data"]["rebels"]["ships"]["edges"].last["cursor"]
+ end
describe "results" do
let(:query_string) {%|
- query getShips($first: Int, $after: String, $last: Int, $before: String, $order: String){
+ query getShips($first: Int, $after: String, $last: Int, $before: String, $order: String, $nameIncludes: String){
rebels {
- ships(first: $first, after: $after, last: $last, before: $before, order: $order) {
+ ships(first: $first, after: $after, last: $last, before: $before, order: $order, nameIncludes: $nameIncludes) {
edges {
cursor
node {
name
}
@@ -45,11 +49,11 @@
it 'slices the result' do
result = query(query_string, "first" => 3)
assert_equal(["X-Wing", "Y-Wing", "A-Wing"], get_names(result))
# After the last result, find the next 2:
- last_cursor = result["data"]["rebels"]["ships"]["edges"].last["cursor"]
+ last_cursor = get_last_cursor(result)
result = query(query_string, "after" => last_cursor, "first" => 2)
assert_equal(["Millenium Falcon", "Home One"], get_names(result))
result = query(query_string, "before" => last_cursor, "last" => 2)
@@ -68,8 +72,19 @@
end
it 'paginates with reverse order' do
result = query(query_string, "first" => 2, "order" => "-name")
assert_equal(["Y-Wing", "X-Wing"], get_names(result))
+ end
+
+ it 'applies custom arguments' do
+ result = query(query_string, "nameIncludes" => "Wing", "first" => 2)
+ names = get_names(result)
+ assert_equal(2, names.length)
+
+ after = get_last_cursor(result)
+ result = query(query_string, "nameIncludes" => "Wing", "after" => after)
+ names = get_names(result)
+ assert_equal(1, names.length)
end
end
end