From e9e46464c27e5155dd404888ebbd1452fc37541b Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Tue, 13 Mar 2018 21:54:54 -0400 Subject: [PATCH] Add `SchemaVersion` type --- js/modules/types/schema_version.js | 5 +++++ test/modules/types/schema_version_test.js | 25 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 js/modules/types/schema_version.js create mode 100644 test/modules/types/schema_version_test.js diff --git a/js/modules/types/schema_version.js b/js/modules/types/schema_version.js new file mode 100644 index 000000000..3a0d08980 --- /dev/null +++ b/js/modules/types/schema_version.js @@ -0,0 +1,5 @@ +const isNumber = require('lodash/isNumber'); + + +exports.isValid = value => + isNumber(value) && value >= 0; diff --git a/test/modules/types/schema_version_test.js b/test/modules/types/schema_version_test.js new file mode 100644 index 000000000..a3205c485 --- /dev/null +++ b/test/modules/types/schema_version_test.js @@ -0,0 +1,25 @@ +require('mocha-testcheck').install(); +const { assert } = require('chai'); + +const SchemaVersion = require('../../../js/modules/types/schema_version'); + + +describe('SchemaVersion', () => { + describe('isValid', () => { + check.it( + 'should return true for positive integers', + gen.posInt, + (input) => { + assert.isTrue(SchemaVersion.isValid(input)); + } + ); + + check.it( + 'should return false for any other value', + gen.primitive.suchThat(value => typeof value !== 'number' || value < 0), + (input) => { + assert.isFalse(SchemaVersion.isValid(input)); + } + ); + }); +});