UNPKG

typeorm-paginator

Version:
1,159 lines (1,158 loc) 46.8 kB
"use strict"; var _regeneratorRuntime = _interopRequireDefault(require("regenerator-runtime")); var _typeorm = require("typeorm"); var _cursorPaginator = require("./cursor-paginator"); function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = { }; Object.keys(descriptor).forEach(function(key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ("value" in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function(desc, decorator) { return decorator ? decorator(target, property, desc) || desc : desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; } function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _asyncToGenerator(fn) { return function() { var self = this, args = arguments; return new Promise(function(resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var _class, _descriptor, _dec, _descriptor1, _dec1, _descriptor2, _dec2; function timestampTransformFrom(value) { if (value instanceof _typeorm.FindOperator) { return new _typeorm.FindOperator(value._type, timestampTransformFrom(value._value)); } if (typeof value === 'function') { return value; } if (typeof value === 'undefined') { return; } if (value === null) { return null; } if (typeof value === 'number') { return value; } return ~~(new Date(value).getTime() / 1000); } function timestampTransformTo(value) { if (value instanceof _typeorm.FindOperator) { var nextValue = timestampTransformTo(value._value); return new _typeorm.FindOperator(value._type, nextValue, value._useParameter, value._multipleParameters); } if (typeof value === 'function') { return value; } if (typeof value === 'undefined') { return; } if (value === null) { return null; } return new Date(value * 1000); } var _dec3 = (0, _typeorm).Entity({ name: 'users' }); var User = _class = _dec3(((_class = function User1() { "use strict"; _classCallCheck(this, User1); _initializerDefineProperty(this, "id", _descriptor, this); _initializerDefineProperty(this, "name", _descriptor1, this); _initializerDefineProperty(this, "createdAt", _descriptor2, this); }) || _class, _dec = (0, _typeorm).PrimaryGeneratedColumn(), _dec1 = (0, _typeorm).Column({ type: String, name: 'user_name' }), _dec2 = (0, _typeorm).Column({ type: 'datetime', name: 'created_at', transformer: { from: timestampTransformFrom, to: timestampTransformTo } }), _descriptor = _applyDecoratedDescriptor(_class.prototype, "id", [ _dec ], { configurable: true, enumerable: true, writable: true, initializer: void 0 }), _descriptor1 = _applyDecoratedDescriptor(_class.prototype, "name", [ _dec1 ], { configurable: true, enumerable: true, writable: true, initializer: void 0 }), _descriptor2 = _applyDecoratedDescriptor(_class.prototype, "createdAt", [ _dec2 ], { configurable: true, enumerable: true, writable: true, initializer: void 0 }), _class)) || _class; function testPromisePaginationAndResolve(pagination) { expect(pagination.count).toBeInstanceOf(Promise); expect(pagination.hasNext).toBeInstanceOf(Promise); expect(pagination.hasPrev).toBeInstanceOf(Promise); expect(pagination.nextCursor).toBeInstanceOf(Promise); expect(pagination.prevCursor).toBeInstanceOf(Promise); expect(pagination.nodes).toBeInstanceOf(Promise); return Promise.resolve().then(_asyncToGenerator(_regeneratorRuntime.default.mark(function _callee() { return _regeneratorRuntime.default.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: _ctx.next = 2; return pagination.count; case 2: _ctx.t0 = _ctx.sent; _ctx.next = 5; return pagination.nodes; case 5: _ctx.t1 = _ctx.sent; _ctx.next = 8; return pagination.hasPrev; case 8: _ctx.t2 = _ctx.sent; _ctx.next = 11; return pagination.hasNext; case 11: _ctx.t3 = _ctx.sent; _ctx.next = 14; return pagination.prevCursor; case 14: _ctx.t4 = _ctx.sent; _ctx.next = 17; return pagination.nextCursor; case 17: _ctx.t5 = _ctx.sent; return _ctx.abrupt("return", { count: _ctx.t0, nodes: _ctx.t1, hasPrev: _ctx.t2, hasNext: _ctx.t3, prevCursor: _ctx.t4, nextCursor: _ctx.t5 }); case 19: case "end": return _ctx.stop(); } }, _callee); }))); } describe('testsuite of cursor-paginator', function() { var connection; beforeAll(_asyncToGenerator(_regeneratorRuntime.default.mark(function _callee() { return _regeneratorRuntime.default.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: _ctx.next = 2; return (0, _typeorm).createConnection({ type: 'sqlite', database: ':memory:', entities: [ User, ], synchronize: true }); case 2: connection = _ctx.sent; case 3: case "end": return _ctx.stop(); } }, _callee); }))); beforeEach(_asyncToGenerator(_regeneratorRuntime.default.mark(function _callee() { return _regeneratorRuntime.default.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: _ctx.next = 2; return connection.getRepository(User).clear(); case 2: case "end": return _ctx.stop(); } }, _callee); }))); it('test paginate default', _asyncToGenerator(_regeneratorRuntime.default.mark(function _callee() { var repoUsers, nodes, paginator, pagination; return _regeneratorRuntime.default.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: repoUsers = connection.getRepository(User); nodes = [ repoUsers.create({ name: 'a', createdAt: 1600000000 }), repoUsers.create({ name: 'b', createdAt: 1600000001 }), repoUsers.create({ name: 'b', createdAt: 1600000002 }), repoUsers.create({ name: 'c', createdAt: 1600000003 }), repoUsers.create({ name: 'c', createdAt: 1600000004 }), repoUsers.create({ name: 'c', createdAt: 1600000005 }), ]; _ctx.next = 4; return repoUsers.save(nodes); case 4: paginator = new _cursorPaginator.CursorPaginator(User, { orderBy: { id: false } }); _ctx.next = 7; return paginator.paginate(repoUsers.createQueryBuilder()); case 7: pagination = _ctx.sent; expect(pagination).toEqual({ count: 6, nodes: [ nodes[5], nodes[4], nodes[3], nodes[2], nodes[1], nodes[0], ], hasPrev: false, hasNext: false, nextCursor: expect.any(String), prevCursor: expect.any(String) }); case 9: case "end": return _ctx.stop(); } }, _callee); }))); it('test cursor paginate by single-order', _asyncToGenerator(_regeneratorRuntime.default.mark(function _callee() { var repoUsers, nodes, paginator, pagination, paginationPrev, paginationNext, paginationNextPrev, paginationNextNext; return _regeneratorRuntime.default.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: repoUsers = connection.getRepository(User); nodes = [ repoUsers.create({ name: 'a', createdAt: 1600000000 }), repoUsers.create({ name: 'b', createdAt: 1600000001 }), repoUsers.create({ name: 'b', createdAt: 1600000002 }), repoUsers.create({ name: 'c', createdAt: 1600000003 }), repoUsers.create({ name: 'c', createdAt: 1600000004 }), repoUsers.create({ name: 'c', createdAt: 1600000005 }), ]; _ctx.next = 4; return repoUsers.save(nodes); case 4: paginator = new _cursorPaginator.CursorPaginator(User, { orderBy: { id: false }, take: 3 }); _ctx.next = 7; return paginator.paginate(repoUsers.createQueryBuilder()); case 7: pagination = _ctx.sent; expect(pagination).toEqual({ count: 6, nodes: [ nodes[5], nodes[4], nodes[3], ], hasPrev: false, hasNext: true, prevCursor: expect.any(String), nextCursor: expect.any(String) }); _ctx.next = 11; return paginator.paginate(repoUsers.createQueryBuilder(), { prevCursor: pagination.prevCursor }); case 11: paginationPrev = _ctx.sent; expect(paginationPrev).toEqual({ count: 6, nodes: [], hasPrev: false, hasNext: true, prevCursor: null, nextCursor: null }); _ctx.next = 15; return paginator.paginate(repoUsers.createQueryBuilder(), { nextCursor: pagination.nextCursor }); case 15: paginationNext = _ctx.sent; expect(paginationNext).toEqual({ count: 6, nodes: [ nodes[2], nodes[1], nodes[0], ], hasPrev: true, hasNext: false, prevCursor: expect.any(String), nextCursor: expect.any(String) }); _ctx.next = 19; return paginator.paginate(repoUsers.createQueryBuilder(), { prevCursor: paginationNext.prevCursor }); case 19: paginationNextPrev = _ctx.sent; expect(paginationNextPrev).toEqual({ count: 6, nodes: [ nodes[5], nodes[4], nodes[3], ], hasPrev: false, hasNext: true, prevCursor: expect.any(String), nextCursor: expect.any(String) }); _ctx.next = 23; return paginator.paginate(repoUsers.createQueryBuilder(), { nextCursor: paginationNext.nextCursor }); case 23: paginationNextNext = _ctx.sent; expect(paginationNextNext).toEqual({ count: 6, nodes: [], hasPrev: true, hasNext: false, prevCursor: null, nextCursor: null }); case 25: case "end": return _ctx.stop(); } }, _callee); }))); it('test cursor paginate by multi-orders', _asyncToGenerator(_regeneratorRuntime.default.mark(function _callee() { var repoUsers, nodes, paginator, pagination1, pagination2, pagination2Next, pagination2NextNext, pagination2NextNextPrev; return _regeneratorRuntime.default.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: repoUsers = connection.getRepository(User); nodes = [ repoUsers.create({ name: 'c', createdAt: 1600000000 }), repoUsers.create({ name: 'b', createdAt: 1600000001 }), repoUsers.create({ name: 'a', createdAt: 1600000002 }), repoUsers.create({ name: 'c', createdAt: 1600000003 }), repoUsers.create({ name: 'b', createdAt: 1600000004 }), repoUsers.create({ name: 'c', createdAt: 1600000005 }), ]; _ctx.next = 4; return repoUsers.save(nodes); case 4: paginator = new _cursorPaginator.CursorPaginator(User, { orderBy: [ { name: true }, { id: false }, ] }); _ctx.next = 7; return paginator.paginate(repoUsers.createQueryBuilder()); case 7: pagination1 = _ctx.sent; expect(pagination1).toEqual({ count: 6, nodes: [ nodes[2], nodes[4], nodes[1], nodes[5], nodes[3], nodes[0], ], hasPrev: false, hasNext: false, prevCursor: expect.any(String), nextCursor: expect.any(String) }); _ctx.next = 11; return paginator.paginate(repoUsers.createQueryBuilder(), { take: 2 }); case 11: pagination2 = _ctx.sent; expect(pagination2).toEqual({ count: 6, nodes: [ nodes[2], nodes[4], ], hasPrev: false, hasNext: true, prevCursor: expect.any(String), nextCursor: expect.any(String) }); _ctx.next = 15; return paginator.paginate(repoUsers.createQueryBuilder(), { take: 2, nextCursor: pagination2.nextCursor }); case 15: pagination2Next = _ctx.sent; expect(pagination2Next).toEqual({ count: 6, nodes: [ nodes[1], nodes[5], ], hasPrev: true, hasNext: true, prevCursor: expect.any(String), nextCursor: expect.any(String) }); _ctx.next = 19; return paginator.paginate(repoUsers.createQueryBuilder(), { take: 2, nextCursor: pagination2Next.nextCursor }); case 19: pagination2NextNext = _ctx.sent; expect(pagination2NextNext).toEqual({ count: 6, nodes: [ nodes[3], nodes[0], ], hasPrev: true, hasNext: false, prevCursor: expect.any(String), nextCursor: expect.any(String) }); _ctx.next = 23; return paginator.paginate(repoUsers.createQueryBuilder(), { take: 2, prevCursor: pagination2NextNext.prevCursor }); case 23: pagination2NextNextPrev = _ctx.sent; expect(pagination2NextNextPrev).toEqual({ count: 6, nodes: [ nodes[1], nodes[5], ], hasPrev: true, hasNext: true, prevCursor: expect.any(String), nextCursor: expect.any(String) }); case 25: case "end": return _ctx.stop(); } }, _callee); }))); it('test cursor paginate with transformer', _asyncToGenerator(_regeneratorRuntime.default.mark(function _callee() { var repoUsers, nodes, paginator, pagination, paginationPrev, paginationNext, paginationNextPrev, paginationNextNext; return _regeneratorRuntime.default.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: repoUsers = connection.getRepository(User); nodes = [ repoUsers.create({ name: 'a', createdAt: 1600000000 }), repoUsers.create({ name: 'b', createdAt: 1600000003 }), repoUsers.create({ name: 'b', createdAt: 1600000005 }), repoUsers.create({ name: 'c', createdAt: 1600000002 }), repoUsers.create({ name: 'c', createdAt: 1600000004 }), repoUsers.create({ name: 'c', createdAt: 1600000001 }), ]; _ctx.next = 4; return repoUsers.save(nodes); case 4: paginator = new _cursorPaginator.CursorPaginator(User, { orderBy: { createdAt: false }, take: 3 }); _ctx.next = 7; return paginator.paginate(repoUsers.createQueryBuilder()); case 7: pagination = _ctx.sent; expect(pagination).toEqual({ count: 6, nodes: [ nodes[2], nodes[4], nodes[1], ], hasPrev: false, hasNext: true, prevCursor: expect.any(String), nextCursor: expect.any(String) }); _ctx.next = 11; return paginator.paginate(repoUsers.createQueryBuilder(), { prevCursor: pagination.prevCursor }); case 11: paginationPrev = _ctx.sent; expect(paginationPrev).toEqual({ count: 6, nodes: [], hasPrev: false, hasNext: true, prevCursor: null, nextCursor: null }); _ctx.next = 15; return paginator.paginate(repoUsers.createQueryBuilder(), { nextCursor: pagination.nextCursor }); case 15: paginationNext = _ctx.sent; expect(paginationNext).toEqual({ count: 6, nodes: [ nodes[3], nodes[5], nodes[0], ], hasPrev: true, hasNext: false, prevCursor: expect.any(String), nextCursor: expect.any(String) }); _ctx.next = 19; return paginator.paginate(repoUsers.createQueryBuilder(), { prevCursor: paginationNext.prevCursor }); case 19: paginationNextPrev = _ctx.sent; expect(paginationNextPrev).toEqual({ count: 6, nodes: [ nodes[2], nodes[4], nodes[1], ], hasPrev: false, hasNext: true, prevCursor: expect.any(String), nextCursor: expect.any(String) }); _ctx.next = 23; return paginator.paginate(repoUsers.createQueryBuilder(), { nextCursor: paginationNext.nextCursor }); case 23: paginationNextNext = _ctx.sent; expect(paginationNextNext).toEqual({ count: 6, nodes: [], hasPrev: true, hasNext: false, prevCursor: null, nextCursor: null }); case 25: case "end": return _ctx.stop(); } }, _callee); }))); it('test promisePaginate default', _asyncToGenerator(_regeneratorRuntime.default.mark(function _callee() { var repoUsers, nodes, paginator, pagination; return _regeneratorRuntime.default.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: repoUsers = connection.getRepository(User); nodes = [ repoUsers.create({ name: 'a', createdAt: 1600000000 }), repoUsers.create({ name: 'b', createdAt: 1600000001 }), repoUsers.create({ name: 'b', createdAt: 1600000002 }), repoUsers.create({ name: 'c', createdAt: 1600000003 }), repoUsers.create({ name: 'c', createdAt: 1600000004 }), repoUsers.create({ name: 'c', createdAt: 1600000005 }), ]; _ctx.next = 4; return repoUsers.save(nodes); case 4: paginator = new _cursorPaginator.CursorPaginator(User, { orderBy: { id: false } }); _ctx.next = 7; return testPromisePaginationAndResolve(paginator.promisePaginate(repoUsers.createQueryBuilder())); case 7: pagination = _ctx.sent; expect(pagination).toEqual({ count: 6, nodes: [ nodes[5], nodes[4], nodes[3], nodes[2], nodes[1], nodes[0], ], hasPrev: false, hasNext: false, nextCursor: expect.any(String), prevCursor: expect.any(String) }); case 9: case "end": return _ctx.stop(); } }, _callee); }))); it('test cursor promisePaginate by single-order', _asyncToGenerator(_regeneratorRuntime.default.mark(function _callee() { var repoUsers, nodes, paginator, pagination, paginationPrev, paginationNext, paginationNextPrev, paginationNextNext; return _regeneratorRuntime.default.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: repoUsers = connection.getRepository(User); nodes = [ repoUsers.create({ name: 'a', createdAt: 1600000000 }), repoUsers.create({ name: 'b', createdAt: 1600000001 }), repoUsers.create({ name: 'b', createdAt: 1600000002 }), repoUsers.create({ name: 'c', createdAt: 1600000003 }), repoUsers.create({ name: 'c', createdAt: 1600000004 }), repoUsers.create({ name: 'c', createdAt: 1600000005 }), ]; _ctx.next = 4; return repoUsers.save(nodes); case 4: paginator = new _cursorPaginator.CursorPaginator(User, { orderBy: { id: false }, take: 3 }); _ctx.next = 7; return testPromisePaginationAndResolve(paginator.promisePaginate(repoUsers.createQueryBuilder())); case 7: pagination = _ctx.sent; expect(pagination).toEqual({ count: 6, nodes: [ nodes[5], nodes[4], nodes[3], ], hasPrev: false, hasNext: true, prevCursor: expect.any(String), nextCursor: expect.any(String) }); _ctx.next = 11; return testPromisePaginationAndResolve(paginator.promisePaginate(repoUsers.createQueryBuilder(), { prevCursor: pagination.prevCursor })); case 11: paginationPrev = _ctx.sent; expect(paginationPrev).toEqual({ count: 6, nodes: [], hasPrev: false, hasNext: true, prevCursor: null, nextCursor: null }); _ctx.next = 15; return testPromisePaginationAndResolve(paginator.promisePaginate(repoUsers.createQueryBuilder(), { nextCursor: pagination.nextCursor })); case 15: paginationNext = _ctx.sent; expect(paginationNext).toEqual({ count: 6, nodes: [ nodes[2], nodes[1], nodes[0], ], hasPrev: true, hasNext: false, prevCursor: expect.any(String), nextCursor: expect.any(String) }); _ctx.next = 19; return testPromisePaginationAndResolve(paginator.promisePaginate(repoUsers.createQueryBuilder(), { prevCursor: paginationNext.prevCursor })); case 19: paginationNextPrev = _ctx.sent; expect(paginationNextPrev).toEqual({ count: 6, nodes: [ nodes[5], nodes[4], nodes[3], ], hasPrev: false, hasNext: true, prevCursor: expect.any(String), nextCursor: expect.any(String) }); _ctx.next = 23; return testPromisePaginationAndResolve(paginator.promisePaginate(repoUsers.createQueryBuilder(), { nextCursor: paginationNext.nextCursor })); case 23: paginationNextNext = _ctx.sent; expect(paginationNextNext).toEqual({ count: 6, nodes: [], hasPrev: true, hasNext: false, prevCursor: null, nextCursor: null }); case 25: case "end": return _ctx.stop(); } }, _callee); }))); it('test cursor promisePaginate by multi-orders', _asyncToGenerator(_regeneratorRuntime.default.mark(function _callee() { var repoUsers, nodes, paginator, pagination1, pagination2, pagination2Next, pagination2NextNext, pagination2NextNextPrev; return _regeneratorRuntime.default.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: repoUsers = connection.getRepository(User); nodes = [ repoUsers.create({ name: 'c', createdAt: 1600000000 }), repoUsers.create({ name: 'b', createdAt: 1600000001 }), repoUsers.create({ name: 'a', createdAt: 1600000002 }), repoUsers.create({ name: 'c', createdAt: 1600000003 }), repoUsers.create({ name: 'b', createdAt: 1600000004 }), repoUsers.create({ name: 'c', createdAt: 1600000005 }), ]; _ctx.next = 4; return repoUsers.save(nodes); case 4: paginator = new _cursorPaginator.CursorPaginator(User, { orderBy: [ { name: true }, { id: false }, ] }); _ctx.next = 7; return testPromisePaginationAndResolve(paginator.promisePaginate(repoUsers.createQueryBuilder())); case 7: pagination1 = _ctx.sent; expect(pagination1).toEqual({ count: 6, nodes: [ nodes[2], nodes[4], nodes[1], nodes[5], nodes[3], nodes[0], ], hasPrev: false, hasNext: false, prevCursor: expect.any(String), nextCursor: expect.any(String) }); _ctx.next = 11; return testPromisePaginationAndResolve(paginator.promisePaginate(repoUsers.createQueryBuilder(), { take: 2 })); case 11: pagination2 = _ctx.sent; expect(pagination2).toEqual({ count: 6, nodes: [ nodes[2], nodes[4], ], hasPrev: false, hasNext: true, prevCursor: expect.any(String), nextCursor: expect.any(String) }); _ctx.next = 15; return testPromisePaginationAndResolve(paginator.promisePaginate(repoUsers.createQueryBuilder(), { take: 2, nextCursor: pagination2.nextCursor })); case 15: pagination2Next = _ctx.sent; expect(pagination2Next).toEqual({ count: 6, nodes: [ nodes[1], nodes[5], ], hasPrev: true, hasNext: true, prevCursor: expect.any(String), nextCursor: expect.any(String) }); _ctx.next = 19; return testPromisePaginationAndResolve(paginator.promisePaginate(repoUsers.createQueryBuilder(), { take: 2, nextCursor: pagination2Next.nextCursor })); case 19: pagination2NextNext = _ctx.sent; expect(pagination2NextNext).toEqual({ count: 6, nodes: [ nodes[3], nodes[0], ], hasPrev: true, hasNext: false, prevCursor: expect.any(String), nextCursor: expect.any(String) }); _ctx.next = 23; return testPromisePaginationAndResolve(paginator.promisePaginate(repoUsers.createQueryBuilder(), { take: 2, prevCursor: pagination2NextNext.prevCursor })); case 23: pagination2NextNextPrev = _ctx.sent; expect(pagination2NextNextPrev).toEqual({ count: 6, nodes: [ nodes[1], nodes[5], ], hasPrev: true, hasNext: true, prevCursor: expect.any(String), nextCursor: expect.any(String) }); case 25: case "end": return _ctx.stop(); } }, _callee); }))); it('test cursor promisePaginate with transformer', _asyncToGenerator(_regeneratorRuntime.default.mark(function _callee() { var repoUsers, nodes, paginator, pagination, paginationPrev, paginationNext, paginationNextPrev, paginationNextNext; return _regeneratorRuntime.default.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: repoUsers = connection.getRepository(User); nodes = [ repoUsers.create({ name: 'a', createdAt: 1600000000 }), repoUsers.create({ name: 'b', createdAt: 1600000003 }), repoUsers.create({ name: 'b', createdAt: 1600000005 }), repoUsers.create({ name: 'c', createdAt: 1600000002 }), repoUsers.create({ name: 'c', createdAt: 1600000004 }), repoUsers.create({ name: 'c', createdAt: 1600000001 }), ]; _ctx.next = 4; return repoUsers.save(nodes); case 4: paginator = new _cursorPaginator.CursorPaginator(User, { orderBy: { createdAt: false }, take: 3 }); _ctx.next = 7; return testPromisePaginationAndResolve(paginator.promisePaginate(repoUsers.createQueryBuilder())); case 7: pagination = _ctx.sent; expect(pagination).toEqual({ count: 6, nodes: [ nodes[2], nodes[4], nodes[1], ], hasPrev: false, hasNext: true, prevCursor: expect.any(String), nextCursor: expect.any(String) }); _ctx.next = 11; return testPromisePaginationAndResolve(paginator.promisePaginate(repoUsers.createQueryBuilder(), { prevCursor: pagination.prevCursor })); case 11: paginationPrev = _ctx.sent; expect(paginationPrev).toEqual({ count: 6, nodes: [], hasPrev: false, hasNext: true, prevCursor: null, nextCursor: null }); _ctx.next = 15; return testPromisePaginationAndResolve(paginator.promisePaginate(repoUsers.createQueryBuilder(), { nextCursor: pagination.nextCursor })); case 15: paginationNext = _ctx.sent; expect(paginationNext).toEqual({ count: 6, nodes: [ nodes[3], nodes[5], nodes[0], ], hasPrev: true, hasNext: false, prevCursor: expect.any(String), nextCursor: expect.any(String) }); _ctx.next = 19; return testPromisePaginationAndResolve(paginator.promisePaginate(repoUsers.createQueryBuilder(), { prevCursor: paginationNext.prevCursor })); case 19: paginationNextPrev = _ctx.sent; expect(paginationNextPrev).toEqual({ count: 6, nodes: [ nodes[2], nodes[4], nodes[1], ], hasPrev: false, hasNext: true, prevCursor: expect.any(String), nextCursor: expect.any(String) }); _ctx.next = 23; return testPromisePaginationAndResolve(paginator.promisePaginate(repoUsers.createQueryBuilder(), { nextCursor: paginationNext.nextCursor })); case 23: paginationNextNext = _ctx.sent; expect(paginationNextNext).toEqual({ count: 6, nodes: [], hasPrev: true, hasNext: false, prevCursor: null, nextCursor: null }); case 25: case "end": return _ctx.stop(); } }, _callee); }))); });