aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-08-15 17:23:09 -0400
committerGitHub <noreply@github.com>2020-08-15 17:23:09 -0400
commitd582c7a0f856c1a352992e3d16be319a891e0202 (patch)
treecb99ef132ca06ba82b10dfc528e0291f29195de1 /test
parentd8649f40d59356361ce470cc220dca6c62a66388 (diff)
JSON schema refactor (#731)
* Remove JsonSchema.clone * Move createProxy function * Group public properties first * Create private version of getPropertySchema * Mark functions as private * Use non-static getValidValueOrDefault * Mark private * Make public validate function not take an info parameter * Remove JsonSchema * Add isValid function * Use isValid for some tests * Fix incorrect type
Diffstat (limited to 'test')
-rw-r--r--test/dictionary-validate.js6
-rw-r--r--test/schema-validate.js4
-rw-r--r--test/test-schema.js18
3 files changed, 9 insertions, 19 deletions
diff --git a/test/dictionary-validate.js b/test/dictionary-validate.js
index d01d74eb..a669a542 100644
--- a/test/dictionary-validate.js
+++ b/test/dictionary-validate.js
@@ -26,7 +26,7 @@ vm.execute([
'mixed/js/cache-map.js',
'bg/js/json-schema.js'
]);
-const JsonSchema = vm.get('JsonSchema');
+const JsonSchemaValidator = vm.get('JsonSchemaValidator');
function readSchema(relativeFileName) {
@@ -45,7 +45,7 @@ async function validateDictionaryBanks(zip, fileNameFormat, schema) {
if (!file) { break; }
const data = JSON.parse(await file.async('string'));
- JsonSchema.validate(data, schema);
+ new JsonSchemaValidator().validate(data, schema);
++index;
}
@@ -60,7 +60,7 @@ async function validateDictionary(archive, schemas) {
const index = JSON.parse(await indexFile.async('string'));
const version = index.format || index.version;
- JsonSchema.validate(index, schemas.index);
+ new JsonSchemaValidator().validate(index, schemas.index);
await validateDictionaryBanks(archive, 'term_bank_?.json', version === 1 ? schemas.termBankV1 : schemas.termBankV3);
await validateDictionaryBanks(archive, 'term_meta_bank_?.json', schemas.termMetaBankV3);
diff --git a/test/schema-validate.js b/test/schema-validate.js
index aa9450dd..7b7a21a6 100644
--- a/test/schema-validate.js
+++ b/test/schema-validate.js
@@ -24,7 +24,7 @@ vm.execute([
'mixed/js/cache-map.js',
'bg/js/json-schema.js'
]);
-const JsonSchema = vm.get('JsonSchema');
+const JsonSchemaValidator = vm.get('JsonSchemaValidator');
function main() {
@@ -45,7 +45,7 @@ function main() {
console.log(`Validating ${dataFileName}...`);
const dataSource = fs.readFileSync(dataFileName, {encoding: 'utf8'});
const data = JSON.parse(dataSource);
- JsonSchema.validate(data, schema);
+ new JsonSchemaValidator().validate(data, schema);
console.log('No issues found');
} catch (e) {
console.warn(e);
diff --git a/test/test-schema.js b/test/test-schema.js
index b3544b28..a4a0de2e 100644
--- a/test/test-schema.js
+++ b/test/test-schema.js
@@ -24,7 +24,7 @@ vm.execute([
'mixed/js/cache-map.js',
'bg/js/json-schema.js'
]);
-const JsonSchema = vm.get('JsonSchema');
+const JsonSchemaValidator = vm.get('JsonSchemaValidator');
function testValidate1() {
@@ -54,12 +54,7 @@ function testValidate1() {
};
const schemaValidate = (value) => {
- try {
- JsonSchema.validate(value, schema);
- return true;
- } catch (e) {
- return false;
- }
+ return new JsonSchemaValidator().isValid(value, schema);
};
const jsValidate = (value) => {
@@ -395,12 +390,7 @@ function testValidate2() {
];
const schemaValidate = (value, schema) => {
- try {
- JsonSchema.validate(value, schema);
- return true;
- } catch (e) {
- return false;
- }
+ return new JsonSchemaValidator().isValid(value, schema);
};
for (const {schema, inputs} of data) {
@@ -555,7 +545,7 @@ function testGetValidValueOrDefault1() {
for (const {schema, inputs} of data) {
for (const [value, expected] of inputs) {
- const actual = JsonSchema.getValidValueOrDefault(schema, value);
+ const actual = new JsonSchemaValidator().getValidValueOrDefault(schema, value);
vm.assert.deepStrictEqual(actual, expected);
}
}