From afb7479ba88b0228c860ebae01ac95f1316904ee Mon Sep 17 00:00:00 2001 From: Michael Solati Date: Mon, 8 Feb 2021 15:32:28 -0800 Subject: [PATCH] test(numbers): add tests for numbers --- fbschema/Integer.json | 16 ++-- fbschema/Number.json | 18 ++-- fbschema/String.json | 12 +-- test/Integer.ts | 154 ++++++++++++++++++++++++++++++++ test/Number.ts | 162 ++++++++++++++++++++++++++++++++++ test/{string.ts => String.ts} | 16 ++-- 6 files changed, 347 insertions(+), 31 deletions(-) create mode 100644 test/Integer.ts create mode 100644 test/Number.ts rename test/{string.ts => String.ts} (86%) diff --git a/fbschema/Integer.json b/fbschema/Integer.json index 815ee34..346921c 100644 --- a/fbschema/Integer.json +++ b/fbschema/Integer.json @@ -2,35 +2,35 @@ "title": "Integer Collection", "type": "object", "properties": { - "simpleInteger": { + "simple": { "type": "integer" }, - "minimumInteger": { + "minimum": { "type": "integer", "minimum": 3 }, - "exclusiveMinimumInteger": { + "exclusiveMinimum": { "type": "integer", "exclusiveMinimum": 3 }, - "maximumInteger": { + "maximum": { "type": "integer", "maximum": 10 }, - "exclusiveMaximumInteger": { + "exclusiveMaximum": { "type": "integer", "exclusiveMaximum": 10 }, - "multipleOfInteger": { + "multipleOf": { "type": "integer", "multipleOf": 10 }, - "rangeInteger": { + "range": { "type": "integer", "minimum": 0, "maximum": 100 }, - "enumInteger": { + "enum": { "type": "integer", "enum": [ 1, diff --git a/fbschema/Number.json b/fbschema/Number.json index 5793241..8d5771f 100644 --- a/fbschema/Number.json +++ b/fbschema/Number.json @@ -2,35 +2,35 @@ "title": "Number Collection", "type": "object", "properties": { - "simpleNumber": { + "simple": { "type": "number" }, - "minimumNumber": { + "minimum": { "type": "number", "minimum": 3 }, - "exclusiveMinimumNumber": { + "exclusiveMinimum": { "type": "number", "exclusiveMinimum": 3 }, - "maximumNumber": { + "maximum": { "type": "number", "maximum": 10 }, - "exclusiveMaximumNumber": { + "exclusiveMaximum": { "type": "number", "exclusiveMaximum": 10 }, - "multipleOfNumber": { + "multipleOf": { "type": "number", - "multipleOf": 10 + "multipleOf": 0.5 }, - "rangeNumber": { + "range": { "type": "number", "minimum": 0, "maximum": 100 }, - "enumNumber": { + "enum": { "type": "number", "enum": [ 1.1, diff --git a/fbschema/String.json b/fbschema/String.json index 029f178..9bc2a7d 100644 --- a/fbschema/String.json +++ b/fbschema/String.json @@ -2,18 +2,18 @@ "title": "String Collection", "type": "object", "properties": { - "simpleString": { + "simple": { "type": "string" }, - "minLengthString": { + "minLength": { "type": "string", - "minLength": "3" + "minLength": 3 }, - "maxLengthString": { + "maxLength": { "type": "string", - "maxLength": "10" + "maxLength": 10 }, - "enumString": { + "enum": { "enum": [ "1", "2", diff --git a/test/Integer.ts b/test/Integer.ts new file mode 100644 index 0000000..880bc27 --- /dev/null +++ b/test/Integer.ts @@ -0,0 +1,154 @@ +import * as chai from 'chai'; + +import {firestore} from './common'; + +const expect = chai.expect; +const collection = firestore.collection('IntegerCollection'); + +describe('Integer Tests:', () => { + describe('Create Tests:', () => { + it('Accepts property of type `integer`', () => { + return collection + .add({ + simple: 1, + }) + .then(() => expect(true).to.be.true); + }); + + it('Does not accept property of type other than `integer`', () => { + return collection + .add({ + simple: '1', + }) + .catch(() => expect(true).to.be.true); + }); + + it('Does not accept property of type `number`', () => { + return collection + .add({ + simple: 0.1, + }) + .catch(() => expect(true).to.be.true); + }); + + it('Accepts integer of 3 when `minimum` set to 3', () => { + return collection + .add({ + minimum: 3, + }) + .then(() => expect(true).to.be.true); + }); + + it('Does not accept integer of 2 when `minimum` set to 3', () => { + return collection + .add({ + minimum: 2, + }) + .catch(() => expect(true).to.be.true); + }); + + it('Accepts integer of 4 when `exclusiveMinimum` set to 3', () => { + return collection + .add({ + exclusiveMinimum: 4, + }) + .then(() => expect(true).to.be.true); + }); + + it('Does not accept integer of 3 when `exclusiveMinimum` set to 3', () => { + return collection + .add({ + exclusiveMinimum: 3, + }) + .catch(() => expect(true).to.be.true); + }); + + it('Accepts integer of 10 when `maximum` set to 10', () => { + return collection + .add({ + maximum: 10, + }) + .then(() => expect(true).to.be.true); + }); + + it('Does not accept integer of 11 when `maximum` set to 10', () => { + return collection + .add({ + maximum: 11, + }) + .catch(() => expect(true).to.be.true); + }); + + it('Accepts integer of 9 when `exclusiveMaximum` set to 10', () => { + return collection + .add({ + exclusiveMaximum: 9, + }) + .then(() => expect(true).to.be.true); + }); + + it('Does not accept integer of 10 when `exclusiveMaximum` set to 10', () => { + return collection + .add({ + exclusiveMaximum: 10, + }) + .catch(() => expect(true).to.be.true); + }); + + it('Accepts integer of 100 when `multipleOf` set to 10', () => { + return collection + .add({ + multipleOf: 100, + }) + .then(() => expect(true).to.be.true); + }); + + it('Does not accept integer of 101 when `multipleOf` set to 10', () => { + return collection + .add({ + multipleOf: 101, + }) + .catch(() => expect(true).to.be.true); + }); + + it('Accepts integer of 50 when `minimum` is set to 0 and `maximum` is set to 100', () => { + return collection + .add({ + range: 50, + }) + .then(() => expect(true).to.be.true); + }); + + it('Does not accept integer of -1 when `minimum` is set to 0 and `maximum` is set to 100', () => { + return collection + .add({ + range: -1, + }) + .catch(() => expect(true).to.be.true); + }); + + it('Does not accept integer of 101 when `minimum` is set to 0 and `maximum` is set to 100', () => { + return collection + .add({ + range: 101, + }) + .catch(() => expect(true).to.be.true); + }); + + it('Accepts integer of accepted enum value', () => { + return collection + .add({ + enum: 1, + }) + .then(() => expect(true).to.be.true); + }); + + it('Does not accept integer of unaccepted enum value', () => { + return collection + .add({ + enum: 4, + }) + .catch(() => expect(true).to.be.true); + }); + }); +}); diff --git a/test/Number.ts b/test/Number.ts new file mode 100644 index 0000000..8085dcb --- /dev/null +++ b/test/Number.ts @@ -0,0 +1,162 @@ +import * as chai from 'chai'; + +import {firestore} from './common'; + +const expect = chai.expect; +const collection = firestore.collection('NumberCollection'); + +describe('Number Tests:', () => { + describe('Create Tests:', () => { + it('Accepts property of type `number`', () => { + return collection + .add({ + simple: 0.1, + }) + .then(() => expect(true).to.be.true); + }); + + it('Does not accept property of type other than `number`', () => { + return collection + .add({ + simple: '0.1', + }) + .catch(() => expect(true).to.be.true); + }); + + it('Accepts number of 3.1 when `minimum` set to 3', () => { + return collection + .add({ + minimum: 3.1, + }) + .then(() => expect(true).to.be.true); + }); + + it('Accepts number of 3 when `minimum` set to 3', () => { + return collection + .add({ + minimum: 3, + }) + .then(() => expect(true).to.be.true); + }); + + it('Does not accept number of 2.9 when `minimum` set to 3', () => { + return collection + .add({ + minimum: 2.9, + }) + .catch(() => expect(true).to.be.true); + }); + + it('Accepts number of 3.1 when `exclusiveMinimum` set to 3', () => { + return collection + .add({ + exclusiveMinimum: 3.1, + }) + .then(() => expect(true).to.be.true); + }); + + it('Does not accept number of 3 when `exclusiveMinimum` set to 3', () => { + return collection + .add({ + exclusiveMinimum: 3, + }) + .catch(() => expect(true).to.be.true); + }); + + it('Accepts number of 9.9 when `maximum` set to 10', () => { + return collection + .add({ + maximum: 9.9, + }) + .then(() => expect(true).to.be.true); + }); + + it('Accepts number of 10 when `maximum` set to 10', () => { + return collection + .add({ + maximum: 10, + }) + .then(() => expect(true).to.be.true); + }); + + it('Does not accept number of 10.1 when `maximum` set to 10', () => { + return collection + .add({ + maximum: 10.1, + }) + .catch(() => expect(true).to.be.true); + }); + + it('Accepts number of 9.9 when `exclusiveMaximum` set to 10', () => { + return collection + .add({ + exclusiveMaximum: 9.9, + }) + .then(() => expect(true).to.be.true); + }); + + it('Does not accept number of 10 when `exclusiveMaximum` set to 10', () => { + return collection + .add({ + exclusiveMaximum: 10, + }) + .catch(() => expect(true).to.be.true); + }); + + it('Accepts number of 2.5 when `multipleOf` set to 0.5', () => { + return collection + .add({ + multipleOf: 2.5, + }) + .then(() => expect(true).to.be.true); + }); + + it('Does not accept number of 3.1 when `multipleOf` set to 0.5', () => { + return collection + .add({ + multipleOf: 3.1, + }) + .catch(() => expect(true).to.be.true); + }); + + it('Accepts number of 50.1 when `minimum` is set to 0 and `maximum` is set to 100', () => { + return collection + .add({ + range: 50.1, + }) + .then(() => expect(true).to.be.true); + }); + + it('Does not accept number of -0.1 when `minimum` is set to 0 and `maximum` is set to 100', () => { + return collection + .add({ + range: -0.1, + }) + .catch(() => expect(true).to.be.true); + }); + + it('Does not accept number of 100.1 when `minimum` is set to 0 and `maximum` is set to 100', () => { + return collection + .add({ + range: 100.1, + }) + .catch(() => expect(true).to.be.true); + }); + + it('Accepts number of accepted enum value', () => { + return collection + .add({ + enum: 1.1, + }) + .then(() => expect(true).to.be.true); + }); + + it('Does not accept number of unaccepted enum value', () => { + return collection + .add({ + enum: 1, + }) + .catch(() => expect(true).to.be.true); + }); + }); +}); diff --git a/test/string.ts b/test/String.ts similarity index 86% rename from test/string.ts rename to test/String.ts index bc34a66..7ac07dc 100644 --- a/test/string.ts +++ b/test/String.ts @@ -10,56 +10,56 @@ describe('String Tests:', () => { it('Accepts property of type `string`', () => { return collection .add({ - simpleString: '123456', + simple: '123456', }) .then(() => expect(true).to.be.true); }); it('Does not accept property of type other than `string`', () => { return collection .add({ - simpleString: 1, + simple: 1, }) .catch(() => expect(true).to.be.true); }); it('Accepts string of length of 3 when `minLength` set to 3', () => { return collection .add({ - minLengthString: '123', + minLength: '123', }) .then(() => expect(true).to.be.true); }); it('Does not accept string of length of 2 when `minLength` set to 3', () => { return collection .add({ - minLengthString: '12', + minLength: '12', }) .catch(() => expect(true).to.be.true); }); it('Accepts string of length of 10 when `maxLength` set to 10', () => { return collection .add({ - maxLengthString: '1234567890', + maxLength: '1234567890', }) .then(() => expect(true).to.be.true); }); it('Does not accept string of length of 11 when `maxLength` set to 10', () => { return collection .add({ - maxLengthString: '12345678901', + maxLength: '12345678901', }) .catch(() => expect(true).to.be.true); }); it('Accepts string of accepted enum value', () => { return collection .add({ - enumString: '1', + enum: '1', }) .then(() => expect(true).to.be.true); }); it('Does not accept string of unaccepted enum value', () => { return collection .add({ - enumString: '4', + enum: '4', }) .catch(() => expect(true).to.be.true); });