diff options
-rw-r--r-- | package.json | 2 | ||||
-rwxr-xr-x | scripts/test_umd.sh | 7 | ||||
-rw-r--r-- | src/schemas/order_schemas.ts | 2 | ||||
-rw-r--r-- | test/schema_test.ts | 46 |
4 files changed, 55 insertions, 2 deletions
diff --git a/package.json b/package.json index 334f353dc..26ae8a504 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "build": "run-p build:*:prod", "lint": "tslint src/*.ts test/*.ts", "test": "run-s clean test:commonjs", - "test:umd": "run-s substitute_umd_bundle run_mocha; npm run clean", + "test:umd": "./scripts/test_umd.sh", "test:coverage": "nyc npm run test --all", "update_contracts": "for i in ${npm_package_config_artifacts}; do copyfiles -u 4 ../contracts/build/contracts/$i.json ../0x.js/src/artifacts; done;", "testrpc": "testrpc -p 8545 --networkId 50 -m \"${npm_package_config_mnemonic}\"", diff --git a/scripts/test_umd.sh b/scripts/test_umd.sh new file mode 100755 index 000000000..d200c76d0 --- /dev/null +++ b/scripts/test_umd.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +# This script runs umd tests and cleans up after them while preserving the `return_code` for CI +# UMD tests should only be run after building the commonjs because they reuse some of the commonjs build artifacts +run-s substitute_umd_bundle run_mocha +return_code=$? +npm run clean +exit $return_code diff --git a/src/schemas/order_schemas.ts b/src/schemas/order_schemas.ts index 72012dc26..4999f3e9d 100644 --- a/src/schemas/order_schemas.ts +++ b/src/schemas/order_schemas.ts @@ -7,7 +7,7 @@ export const addressSchema = { export const numberSchema = { id: '/numberSchema', type: 'string', - format: '\d+(\.\d+)?', + pattern: '^\\d+(\\.\\d+)?$', }; export const orderSchema = { diff --git a/test/schema_test.ts b/test/schema_test.ts new file mode 100644 index 000000000..133914e6d --- /dev/null +++ b/test/schema_test.ts @@ -0,0 +1,46 @@ +import 'mocha'; +import * as _ from 'lodash'; +import * as chai from 'chai'; +import * as BigNumber from 'bignumber.js'; +import promisify = require('es6-promisify'); +import {numberSchema} from '../src/schemas/order_schemas'; +import {SchemaValidator} from '../src/utils/schema_validator'; + +chai.config.includeStack = true; +const expect = chai.expect; + +describe('Schema', () => { + const validator = new SchemaValidator(); + describe('#numberSchema', () => { + describe('number regex', () => { + it('should validate valid numbers', () => { + const testCases = ['42', '0', '1.3', '0.2', '00.00']; + _.forEach(testCases, (testCase: string) => { + expect(validator.validate(testCase as any, numberSchema).errors).to.be.lengthOf(0); + }); + }); + it('should fail for invalid numbers', () => { + const testCases = ['.3', '1.', 'abacaba', 'и', '1..0']; + _.forEach(testCases, (testCase: string) => { + expect(validator.validate(testCase as any, numberSchema).errors).to.be.lengthOf(1); + }); + }); + }); + }); + describe('BigNumber serialization', () => { + it.only('should correctly serialize BigNumbers', () => { + const testCases = { + '42': '42', + '0': '0', + '1.3': '1.3', + '0.2': '0.2', + '00.00': '0', + '.3': '0.3', + }; + _.forEach(testCases, (serialized: string, input: string) => { + expect(SchemaValidator.convertToJSONSchemaCompatibleObject(new BigNumber(input))) + .to.be.equal(serialized); + }); + }); + }); +}); |