UNPKG

stagify

Version:

mongoose aggregate pipeline parser

51 lines (50 loc) 2.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var stagify_1 = require("../stagify"); describe.only('utils/stagify', function () { it('should return correct match and sort when pass "name=sambath&sort[createdAt]=-1"', function () { // arrage var input = 'name=sambath&sort[createdAt]=-1'; var expectedResult = [ { $match: { name: { $eq: 'sambath' } } }, { $sort: { createdAt: -1 } }, { $skip: 0 }, { $limit: 25 }, ]; // act var output = (0, stagify_1.default)(input); // assert expect(output).toEqual(expectedResult); }); it('should return correct match when pass "name=sambath"', function () { var input = 'name=sambath'; var expected = [{ $match: { name: { $eq: 'sambath' } } }, { $skip: 0 }, { $limit: 25 }]; var output = (0, stagify_1.default)(input); expect(output).toEqual(expected); }); it('should return correct sort when pass "sort[age]=1&sort[name]=-1"', function () { var input = 'sort[age]=1&sort[name]=-1'; var expected = [ { $match: {} }, { $sort: { age: 1, name: -1 }, }, { $skip: 0 }, { $limit: 25 }, ]; var output = (0, stagify_1.default)(input); expect(output).toEqual(expected); }); it('should return correct skip and limit when pass "page=2&limit=20"', function () { var input = 'page=2&limit=20'; var expected = [{ $match: {} }, { $skip: 20 }, { $limit: 20 }]; var output = (0, stagify_1.default)(input); expect(output).toEqual(expected); }); it('should return correct skip select when pass "select[name]=1&limit=20"', function () { var input = 'select[name]=1&limit=20'; var expected = [{ $match: {} }, { $project: { name: 1 } }, { $skip: 0 }, { $limit: 20 }]; var output = (0, stagify_1.default)(input); expect(output).toEqual(expected); }); });