|
| 1 | +import 'reflect-metadata'; |
| 2 | + |
| 3 | +import * as D from './decorator'; |
| 4 | +import * as graphql from 'graphql'; |
| 5 | + |
| 6 | +import { SchemaFactoryError, SchemaFactoryErrorType, schemaFactory } from './schema_factory'; |
| 7 | + |
| 8 | +import { PageInfo } from './page-info.type'; |
| 9 | +import { execute } from 'graphql/execution'; |
| 10 | +import { parse } from 'graphql/language'; |
| 11 | +import { validate } from 'graphql/validation'; |
| 12 | + |
| 13 | +const assert = require('assert'); |
| 14 | + |
| 15 | +// const parse = require("graphql/language").parse as (source: string) => any; |
| 16 | +// const validate = require("graphql/validation").validate as (schema: any, ast: any, ...args: any[]) => any[]; |
| 17 | +// const execute = require("graphql/execution").execute as (schema: any, ast: any, ...args: any[]) => Promise<any>; |
| 18 | + |
| 19 | +describe('PageInfo', function () { |
| 20 | + |
| 21 | + it('should return correct pagination when all parameters are provided', function () { |
| 22 | + let pageInfo = new PageInfo(100, 0, 10); |
| 23 | + assert(pageInfo.hasNextPage === true); |
| 24 | + assert(pageInfo.hasPreviousPage === false); |
| 25 | + }); |
| 26 | + |
| 27 | + it('should return correct pagination when both limit and offset are not provided', function () { |
| 28 | + let pageInfo = new PageInfo(100, undefined, undefined); |
| 29 | + assert(pageInfo.hasNextPage === false); |
| 30 | + assert(pageInfo.hasPreviousPage === false); |
| 31 | + }); |
| 32 | + |
| 33 | + describe('limit', function () { |
| 34 | + |
| 35 | + it('should return correct pagination when limit is bigger than count', function () { |
| 36 | + let pageInfo = new PageInfo(100, 10, 200); |
| 37 | + assert(pageInfo.hasNextPage === false); |
| 38 | + assert(pageInfo.hasPreviousPage === true); |
| 39 | + }); |
| 40 | + |
| 41 | + it('should return correct pagination when limit is smaller than count', function () { |
| 42 | + let pageInfo = new PageInfo(100, 10, 10); |
| 43 | + assert(pageInfo.hasNextPage === true); |
| 44 | + assert(pageInfo.hasPreviousPage === true); |
| 45 | + }); |
| 46 | + |
| 47 | + it('should return correct pagination when limit is a negative number', function () { |
| 48 | + let pageInfo = new PageInfo(100, 10, -10); |
| 49 | + assert(pageInfo.hasNextPage === false); |
| 50 | + assert(pageInfo.hasPreviousPage === true); |
| 51 | + }); |
| 52 | + |
| 53 | + it('should return correct pagination when limit is zero', function () { |
| 54 | + let pageInfo = new PageInfo(100, 10, 0); |
| 55 | + assert(pageInfo.hasNextPage === false); |
| 56 | + assert(pageInfo.hasPreviousPage === true); |
| 57 | + }); |
| 58 | + |
| 59 | + it('should return correct pagination when limit is not provided', function () { |
| 60 | + let pageInfo = new PageInfo(100, 10, undefined); |
| 61 | + assert(pageInfo.hasNextPage === false); |
| 62 | + assert(pageInfo.hasPreviousPage === true); |
| 63 | + }); |
| 64 | + |
| 65 | + }); |
| 66 | + |
| 67 | + describe('offset', function () { |
| 68 | + |
| 69 | + it('should return correct pagination when offset is a bigger than count', function () { |
| 70 | + let pageInfo = new PageInfo(100, 200, 10); |
| 71 | + assert(pageInfo.hasNextPage === false); |
| 72 | + assert(pageInfo.hasPreviousPage === true); |
| 73 | + }); |
| 74 | + |
| 75 | + it('should return correct pagination when offset is smaller than count', function () { |
| 76 | + let pageInfo = new PageInfo(100, 5, 10); |
| 77 | + assert(pageInfo.hasNextPage === true); |
| 78 | + assert(pageInfo.hasPreviousPage === true); |
| 79 | + }); |
| 80 | + |
| 81 | + it('should return correct pagination when offset is a negative number', function () { |
| 82 | + let pageInfo = new PageInfo(100, -5, 10); |
| 83 | + assert(pageInfo.hasNextPage === true); |
| 84 | + assert(pageInfo.hasPreviousPage === false); |
| 85 | + }); |
| 86 | + |
| 87 | + it('should return correct pagination when offset is zero', function () { |
| 88 | + let pageInfo = new PageInfo(100, 0, 10); |
| 89 | + assert(pageInfo.hasNextPage === true); |
| 90 | + assert(pageInfo.hasPreviousPage === false); |
| 91 | + }); |
| 92 | + |
| 93 | + it('should return correct pagination when offset is not provided', function () { |
| 94 | + let pageInfo = new PageInfo(100, undefined, 10); |
| 95 | + assert(pageInfo.hasNextPage === true); |
| 96 | + assert(pageInfo.hasPreviousPage === false); |
| 97 | + }); |
| 98 | + |
| 99 | + }); |
| 100 | + |
| 101 | +}); |
0 commit comments