From d16739a83a20e1729e08dbcbbc155be15972d146 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 22 May 2021 15:45:20 -0400 Subject: Json schema validation improvements (#1697) * Create new JsonSchema class * Add proxy handler * Update tests * Update validation scripts * Update backend * Update audio downloader * Update options util * Update dictionary importer * Update json schema file reference * Remove old json-schema.js * Rename new json-schema.js * Update file names * Rename class --- test/test-json-schema.js | 8 ++++---- test/test-profile-conditions-util.js | 11 +++-------- 2 files changed, 7 insertions(+), 12 deletions(-) (limited to 'test') diff --git a/test/test-json-schema.js b/test/test-json-schema.js index d082a53f..ba0131bf 100644 --- a/test/test-json-schema.js +++ b/test/test-json-schema.js @@ -25,19 +25,19 @@ vm.execute([ 'js/general/cache-map.js', 'js/data/json-schema.js' ]); -const JsonSchemaValidator = vm.get('JsonSchemaValidator'); +const JsonSchema = vm.get('JsonSchema'); function schemaValidate(schema, value) { - return new JsonSchemaValidator().isValid(value, schema); + return new JsonSchema(schema).isValid(value); } function getValidValueOrDefault(schema, value) { - return new JsonSchemaValidator().getValidValueOrDefault(schema, value); + return new JsonSchema(schema).getValidValueOrDefault(value); } function createProxy(schema, value) { - return new JsonSchemaValidator().createProxy(value, schema); + return new JsonSchema(schema).createProxy(value); } function clone(value) { diff --git a/test/test-profile-conditions-util.js b/test/test-profile-conditions-util.js index b77578de..2d076a7f 100644 --- a/test/test-profile-conditions-util.js +++ b/test/test-profile-conditions-util.js @@ -27,12 +27,7 @@ vm.execute([ 'js/data/json-schema.js', 'js/background/profile-conditions-util.js' ]); -const [JsonSchemaValidator, ProfileConditionsUtil] = vm.get(['JsonSchemaValidator', 'ProfileConditionsUtil']); - - -function schemaValidate(value, schema) { - return new JsonSchemaValidator().isValid(value, schema); -} +const [ProfileConditionsUtil] = vm.get(['ProfileConditionsUtil']); function testNormalizeContext() { @@ -1081,12 +1076,12 @@ function testSchemas() { const profileConditionsUtil = new ProfileConditionsUtil(); const schema = profileConditionsUtil.createSchema(conditionGroups); if (typeof expectedSchema !== 'undefined') { - vm.assert.deepStrictEqual(schema, expectedSchema); + vm.assert.deepStrictEqual(schema.schema, expectedSchema); } if (Array.isArray(inputs)) { for (const {expected, context} of inputs) { const normalizedContext = profileConditionsUtil.normalizeContext(context); - const actual = schemaValidate(normalizedContext, schema); + const actual = schema.isValid(normalizedContext); assert.strictEqual(actual, expected); } } -- cgit v1.2.3