it("test jc.max, arr-obj", function () { var table = [ { time: "10/1", mac: 10, win: 20 }, { time: "10/1", mac: 30, win: 20 }, { time: "10/1", mac: 45, win: 20 }, { time: "10/1", mac: 20, win: 20 } ] var data = jc.max(table, function (row) { return row.mac }); [data].should.deepEqual([{ time: "10/1", mac: 45, win: 20 }]); });
it('extractSet', function () { let set = {subject: 1, time: 2, paper: 3, variant: 4} PaperUtils.extractSet(set).should.deepEqual(set) PaperUtils.extractSet(Object.assign({}, set, {type: 'ms'})).should.deepEqual(set) PaperUtils.extractSet(Object.assign({}, set, {variant: 5})).should.not.deepEqual(set) PaperUtils.extractSet(Object.assign({}, set, {variant: 5, type: 'ms'})).should.not.deepEqual(set) })
it('getTypeString should work', function () { PaperUtils.longTypes.should.deepEqual(PaperUtils.shortTypes.map(PaperUtils.getTypeString)) PaperUtils.getTypeString('xx').should.equal('xx') PaperUtils.getTypeString('').should.equal('--') PaperUtils.getTypeString().should.equal('--') })
it('cloning schema with cloneSchema option', () => { const schema = { $schema: 'http://json-schema.org/draft-04/schema#', type: ['string', 'null'], }; const result = convert(schema, { cloneSchema: true }); const expected = { type: 'string', nullable: true, }; should(result).deepEqual(expected, 'result does not match the expected'); should(result).not.deepEqual(schema, 'the schema was modified in place'); });
it("test limit number > table.length type", function () { var data = jc.sql({ select: { col: ["time", "inPerson"], }, from: table, limit: 20 }); data.length.should.deepEqual(14); });
it("test jc.forIn", function () { var table; var data = jc.forIn(table, function () { return []; }); data.should.deepEqual({}); });
it("test jc.min, arr-obj", function () { var table = [ { time: "10/1", mac: 10, win: 20 }, { time: "10/1", mac: 30, win: 20 }, { time: "10/1", mac: 45, win: 20 } ] var data = jc.min(table, function (row) { return row.mac }); [data].should.deepEqual([{ time: "10/1", mac: 10, win: 20 }]); });
it('direct schema modification', () => { const schema = { $schema: 'http://json-schema.org/draft-04/schema#', type: ['string', 'null'], }; const result = convert(schema, { cloneSchema: false }); const expected = { type: 'string', nullable: true, }; should(result).deepEqual(expected, 'result does not match the expected'); should(result).deepEqual(schema, 'the schema was not modified in place'); });
it("test jc.map", function () { var table; var data = jc.map(table, function () { }); data.should.deepEqual([]); });
it('does not add nullable for non null types', () => { const schema = { $schema: 'http://json-schema.org/draft-04/schema#', type: 'string' }; const result = convert(schema); should(result).deepEqual({ type: 'string' }); });
it("test min array type", function () { var data = jc.sql({ select: { min: ["fly", "inPerson"] }, from: table }); data.should.deepEqual([{ "min_fly": 0, "min_inPerson": 13 }]); });
it("test limit over", function () { var data = jc.sql({ select: { col: ["time", "inPerson"], }, from: table, limit: [15,20] }); data.should.deepEqual([]); });
it('adds `nullable: true` for `type: [string, null]`', () => { const schema = { $schema: 'http://json-schema.org/draft-04/schema#', type: ['string', 'null'], }; const result = convert(schema); should(result).deepEqual({ type: 'string', nullable: true }); });
it('type array', () => { const schema = { $schema: 'http://json-schema.org/draft-04/schema#', type: ['string', 'null'] }; const result = convert(schema); const expected = { type: 'string', nullable: true }; should(result).deepEqual(expected); });
it("test count array type", function () { var data = jc.sql({ select: { count: ["fly", "*", "time"] }, from: table }); data.should.deepEqual([{ "count_fly": 3, "count_*": 14, "count_time": 14 }]); });