it("should generate a valid number above exclusive minimum", () => { let min = MAX_SAFE_INTEGER - 10; let schema = new JsonSchema({ type: "integer", minimum: min, exclusiveMinimum: true }); for (let i = 0; i < iterations; i++) { expect(schema.sample()) .to.be.a("number") .and.satisfy(Number.isFinite) .and.satisfy(isWholeNumber) .and.above(min) .and.at.most(MAX_SAFE_INTEGER); } });
describe('Test the withGen function', () => { it('should replace the generator', () => { const gen = () => testcheck.gen.intWithin(5, 7); const spec = s.withGen(s.intIn(0, 10), gen); expect(s.exercise(spec)).to.have.length(10) .to.satisfy(sample => _.every(sample, ([v]) => s.isIntInRange(5, 8, v))); }); });
it('should implement a generator', () => { expect(s.exercise(s.collOf(isInteger))).to.have.length(10) .to.satisfy(sample => _.every(sample, ([v]) => _.isArray(v))); });
it("should generate a valid number within min/max", () => { let schema = new JsonSchema({ type: "integer", minimum: 1, maximum: 10 }); for (let i = 0; i < iterations; i++) { expect(schema.sample()) .to.be.a("number") .and.satisfy(Number.isFinite) .and.satisfy(isWholeNumber) .and.at.least(1) .and.at.most(10); } });
it('should implement a generator', () => { s.def('::ingredient2', s.cat(':quantity', isInteger, ':unit', isString)); expect(s.exercise('::ingredient2', 7)).to.have.length(7) .to.satisfy(sample => every(sample, ([[v1, v2]]) => isInteger(v1) || isString(v2))); });
it("should not return anything if no response schema is specified in the Swagger API", (done) => { delete api.paths["/pets"][method].responses[200].schema; helper.initTest(api, (supertest) => { let request = supertest[method]("/api/pets").set("Accept", contentType); helper.processMethod(request, method, ""); request.end(helper.checkResults(done, (res) => { expect(res.headers["content-length"]).to.satisfy((contentLength) => { // This is the difference between returning an empty array vs. nothing at all return contentLength === undefined || contentLength === "0"; }); done(); })); }); });
it("should generate a valid number within exclusive min/max", () => { let schema = new JsonSchema({ type: "integer", minimum: 1, maximum: 10, exclusiveMinimum: true, exclusiveMaximum: true }); for (let i = 0; i < iterations; i++) { expect(schema.sample()) .to.be.a("number") .and.satisfy(Number.isFinite) .and.satisfy(isWholeNumber) .and.above(1) .and.below(10); } });
it("should generate a valid date", () => { let schema = new JsonSchema({ type: "string", format: "date" }); for (let i = 0; i < iterations; i++) { expect(schema.sample()) .to.be.an.instanceOf(Date) .and.satisfy((date) => { return date.getUTCHours() === 0 && date.getUTCMinutes() === 0 && date.getUTCSeconds() === 0 && date.getUTCMilliseconds() === 0; }); } });
it("should generate a valid number below exclusive maximum", () => { let max = MIN_SAFE_INTEGER + 10; let schema = new JsonSchema({ type: "integer", maximum: max, exclusiveMaximum: true }); for (let i = 0; i < iterations; i++) { expect(schema.sample()) .to.be.a("number") .and.satisfy(Number.isFinite) .and.satisfy(isWholeNumber) .and.at.least(MIN_SAFE_INTEGER) .and.below(max); } });
it("should generate a valid int32", () => { let schema = new JsonSchema({ type: "integer", format: "int32" }); for (let i = 0; i < iterations; i++) { expect(schema.sample()) .to.be.a("number") .and.satisfy(Number.isFinite) .and.satisfy(isWholeNumber) .and.at.least(-2147483648) .and.at.most(2147483647); } });
it("should generate a valid number above minimum", () => { let min = MAX_SAFE_INTEGER - 10; let schema = new JsonSchema({ type: "integer", minimum: min }); for (let i = 0; i < iterations; i++) { expect(schema.sample()) .to.be.a("number") .and.satisfy(Number.isFinite) .and.satisfy(isWholeNumber) .and.at.least(min) .and.at.most(MAX_SAFE_INTEGER); } });
it("should generate a valid int64", () => { let schema = new JsonSchema({ type: "integer", format: "int64" }); for (let i = 0; i < iterations; i++) { expect(schema.sample()) .to.be.a("number") .and.satisfy(Number.isFinite) .and.satisfy(isWholeNumber) .and.at.least(MIN_SAFE_INTEGER) .and.at.most(MAX_SAFE_INTEGER); } });
it("should generate a valid number below maximum", () => { let max = MIN_SAFE_INTEGER + 10; let schema = new JsonSchema({ type: "integer", maximum: max }); for (let i = 0; i < iterations; i++) { expect(schema.sample()) .to.be.a("number") .and.satisfy(Number.isFinite) .and.satisfy(isWholeNumber) .and.at.least(MIN_SAFE_INTEGER) .and.at.most(max); } });