Skip to content

Commit

Permalink
test(numbers): add tests for numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSolati committed Feb 8, 2021
1 parent c2f21c2 commit afb7479
Show file tree
Hide file tree
Showing 6 changed files with 347 additions and 31 deletions.
16 changes: 8 additions & 8 deletions fbschema/Integer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 9 additions & 9 deletions fbschema/Number.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions fbschema/String.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
154 changes: 154 additions & 0 deletions test/Integer.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
});

0 comments on commit afb7479

Please sign in to comment.