UNPKG

@sterblue/sterblue-sdk

Version:

Sterblue Graph SDK for graphile.sterblue.com

109 lines (105 loc) 3.24 kB
"use strict"; var _getPaginationPath = require("../get-pagination-path"); var _graphqlTag = _interopRequireDefault(require("graphql-tag")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } describe("test query", () => { test("simple test for query, string as input", async () => { const query = ` query test($id: ID, $first: Int, $offset: Int) { user(id: $id, first: $first, offset: $offset) { firstName lastName teehee { id } } } `; const path = (0, _getPaginationPath.getPaginationPath)(query); expect(path).toEqual(["user"]); }); test("simple test for query", async () => { const query = (0, _graphqlTag.default)` query test($id: ID, $first: Int, $offset: Int) { user(id: $id, first: $first, offset: $offset) { firstName lastName teehee { id } } } `; const path = (0, _getPaginationPath.getPaginationPath)(query); expect(path).toEqual(["user"]); }); test("simple test for query nested", async () => { const query = (0, _graphqlTag.default)` query test($id: ID, $first: Int, $offset: Int) { user(id: $id) { firstName lastName teehee(first: $first, offset: $offset) { id } } } `; const path = (0, _getPaginationPath.getPaginationPath)(query); expect(path).toEqual(["user", "teehee"]); }); test("simple test for query, fist and offset have set values", async () => { const query = (0, _graphqlTag.default)` query test($id: ID, $first: Int, $offset: Int) { user(id: $id) { firstName lastName teehee(first: 1, offset: 10) { id } } } `; const path = (0, _getPaginationPath.getPaginationPath)(query); expect(path).toEqual(null); }); test("simple test for query, no first or offset , should fail", async () => { const query = (0, _graphqlTag.default)` query test($id: ID, $first: Int, $offset: Int) { user(id: $id) { firstName lastName teehee { id } } } `; const path = (0, _getPaginationPath.getPaginationPath)(query); expect(path).toEqual(null); }); test("A test case that failed for no reason in sdk use", async () => { const query = (0, _graphqlTag.default)` # The query MUST declare the first and offset variables query getImagesInPolygon( $first: Int $offset: Int # $polygon: GeoJSON # $filter: ImageFilter! # $orderBy: [ImagesOrderBy!] ) { # There MUST be somewhere in the query the use of offset and first images( first: $first offset: $offset # filter: { # and: [$filter, { location: { geometry: { intersects: $polygon } } }] # } # orderBy: $orderBy ) { id location { geometry { geojson } } } } `; const path = (0, _getPaginationPath.getPaginationPath)(query); expect(path).toEqual(["images"]); }); });