From 329504e20bfc51b6d18b1a224b95e206f18cc5b3 Mon Sep 17 00:00:00 2001 From: jmfrancois Date: Fri, 6 Oct 2023 10:10:25 +0200 Subject: [PATCH] chore: secu --- packages/jsfc/package.json | 2 +- .../src/{lib => }/canonical-title-map.spec.js | 0 .../jsfc/src/{lib => }/canonical-title-map.ts | 2 +- packages/jsfc/src/index.js | 16 ++++---- packages/jsfc/src/lib/sf-path.spec.js | 38 ------------------- packages/jsfc/src/lib/traverse.spec.js | 24 ------------ packages/jsfc/src/{lib => }/merge.js | 8 ++-- packages/jsfc/src/{lib => }/merge.spec.js | 0 packages/jsfc/src/{lib => }/resolve.js | 4 +- packages/jsfc/src/{lib => }/resolve.spec.js | 7 ++-- ...faults.spec.js => schema-defaults.test.js} | 15 ++++---- .../jsfc/src/{lib => }/schema-defaults.ts | 0 packages/jsfc/src/{lib => }/select.js | 0 .../{lib/select.spec.js => select.test.js} | 14 ++----- packages/jsfc/src/sf-path.test.js | 10 +++++ packages/jsfc/src/{lib => }/sf-path.ts | 2 +- packages/jsfc/src/traverse.test.js | 8 ++++ packages/jsfc/src/{lib => }/traverse.ts | 2 +- packages/jsfc/src/{lib => }/validate.js | 0 .../validate.spec.js => validate.test.js} | 17 +++------ 20 files changed, 56 insertions(+), 113 deletions(-) rename packages/jsfc/src/{lib => }/canonical-title-map.spec.js (100%) rename packages/jsfc/src/{lib => }/canonical-title-map.ts (86%) delete mode 100644 packages/jsfc/src/lib/sf-path.spec.js delete mode 100644 packages/jsfc/src/lib/traverse.spec.js rename packages/jsfc/src/{lib => }/merge.js (97%) rename packages/jsfc/src/{lib => }/merge.spec.js (100%) rename packages/jsfc/src/{lib => }/resolve.js (78%) rename packages/jsfc/src/{lib => }/resolve.spec.js (94%) rename packages/jsfc/src/{lib/schema-defaults.spec.js => schema-defaults.test.js} (78%) rename packages/jsfc/src/{lib => }/schema-defaults.ts (100%) rename packages/jsfc/src/{lib => }/select.js (100%) rename packages/jsfc/src/{lib/select.spec.js => select.test.js} (94%) create mode 100644 packages/jsfc/src/sf-path.test.js rename packages/jsfc/src/{lib => }/sf-path.ts (94%) create mode 100644 packages/jsfc/src/traverse.test.js rename packages/jsfc/src/{lib => }/traverse.ts (97%) rename packages/jsfc/src/{lib => }/validate.js (100%) rename packages/jsfc/src/{lib/validate.spec.js => validate.test.js} (71%) diff --git a/packages/jsfc/package.json b/packages/jsfc/package.json index 31fbbbcb889..cf873f862a5 100644 --- a/packages/jsfc/package.json +++ b/packages/jsfc/package.json @@ -9,7 +9,7 @@ "watch": "webpack --watch", "dist-untested": "webpack --config webpack.config.dist.js", "test:cov": "npm run test", - "test": "echo need to fix all tests before" + "test": "talend-scripts test" }, "author": "json-schema-form", "contributors": [ diff --git a/packages/jsfc/src/lib/canonical-title-map.spec.js b/packages/jsfc/src/canonical-title-map.spec.js similarity index 100% rename from packages/jsfc/src/lib/canonical-title-map.spec.js rename to packages/jsfc/src/canonical-title-map.spec.js diff --git a/packages/jsfc/src/lib/canonical-title-map.ts b/packages/jsfc/src/canonical-title-map.ts similarity index 86% rename from packages/jsfc/src/lib/canonical-title-map.ts rename to packages/jsfc/src/canonical-title-map.ts index 9721a7b0d87..e73dbfb5b3f 100644 --- a/packages/jsfc/src/lib/canonical-title-map.ts +++ b/packages/jsfc/src/canonical-title-map.ts @@ -1,6 +1,6 @@ // Takes a titleMap in either object or list format and returns one // in the list format. -export default function(titleMap: Array, originalEnum?: any) { +export default function (titleMap: Array, originalEnum?: any) { if (!Array.isArray(titleMap)) { const canonical = []; if (originalEnum) { diff --git a/packages/jsfc/src/index.js b/packages/jsfc/src/index.js index 0f1e78a10b6..d2716c0d55c 100644 --- a/packages/jsfc/src/index.js +++ b/packages/jsfc/src/index.js @@ -1,12 +1,12 @@ import tv4index from 'tv4'; -import * as schemaDefaultsImp from './lib/schema-defaults'; -import * as sfPathImp from './lib/sf-path'; -import canonicalTitleMapImp from './lib/canonical-title-map'; -export { merge } from './lib/merge'; -export { select } from './lib/select'; -export { jsonref } from './lib/resolve'; -export { traverseSchema, traverseForm } from './lib/traverse'; -export { validate } from './lib/validate'; +import * as schemaDefaultsImp from './schema-defaults'; +import * as sfPathImp from './sf-path'; +import canonicalTitleMapImp from './canonical-title-map'; +export { merge } from './merge'; +export { select } from './select'; +export { jsonref } from './resolve'; +export { traverseSchema, traverseForm } from './traverse'; +export { validate } from './validate'; export const sfPath = sfPathImp; export const schemaDefaults = schemaDefaultsImp; diff --git a/packages/jsfc/src/lib/sf-path.spec.js b/packages/jsfc/src/lib/sf-path.spec.js deleted file mode 100644 index 4612c33fc91..00000000000 --- a/packages/jsfc/src/lib/sf-path.spec.js +++ /dev/null @@ -1,38 +0,0 @@ -import chai from 'chai'; -import { describe, it } from 'mocha'; -import { parse, stringify, normalize, name } from './sf-path'; - -chai.should(); - -describe('sf-path.js', () => { - it('should hold functions for working with object paths and keys', () => { - parse.should.be.an('function'); - stringify.should.be.an('function'); - normalize.should.be.an('function'); - name.should.be.an('function'); - }); - - // describe('parse', () => { - // it('should ', () => { - // should.be.eq(); - // }); - // }); - // - // describe('stringify', () => { - // it('should ', () => { - // should.be.eq(); - // }); - // }); - // - // describe('normalize', () => { - // it('should ', () => { - // should.be.eq(); - // }); - // }); - // - // describe('name', () => { - // it('should ', () => { - // should.be.eq(); - // }); - // }); -}); diff --git a/packages/jsfc/src/lib/traverse.spec.js b/packages/jsfc/src/lib/traverse.spec.js deleted file mode 100644 index 11fdc0500e8..00000000000 --- a/packages/jsfc/src/lib/traverse.spec.js +++ /dev/null @@ -1,24 +0,0 @@ -import chai from 'chai'; -import { describe, it } from 'mocha'; -import { traverseSchema, traverseForm } from './traverse'; - -chai.should(); - -describe('traverse.js', () => { - it('should hold functions for applying functions on branches of a json-schema or ui-schema', () => { - traverseSchema.should.be.an('function'); - traverseForm.should.be.an('function'); - }); - - // describe('traverseSchema', () => { - // it('should ', () => { - // should.be.eq(); - // }); - // }); - // - // describe('traverseForm', () => { - // it('should ', () => { - // should.be.eq(); - // }); - // }); -}); diff --git a/packages/jsfc/src/lib/merge.js b/packages/jsfc/src/merge.js similarity index 97% rename from packages/jsfc/src/lib/merge.js rename to packages/jsfc/src/merge.js index 13c1b578fb3..f9d866fbb60 100644 --- a/packages/jsfc/src/lib/merge.js +++ b/packages/jsfc/src/merge.js @@ -40,26 +40,26 @@ export function merge( //simple case, we have a "...", just put the formItemRest there if (stdForm.form && idxRest !== -1) { let formKeys = form - .map(function(obj) { + .map(function (obj) { if (typeof obj === 'string') { return obj; } else if (obj.key) { return obj.key; } }) - .filter(function(element) { + .filter(function (element) { return element !== undefined; }); formItemRest = formItemRest.concat( stdForm.form - .map(function(obj) { + .map(function (obj) { let isInside = formKeys.indexOf(obj.key[0]) !== -1; if (!isInside) { return obj; } }) - .filter(function(element) { + .filter(function (element) { return element !== undefined; }), ); diff --git a/packages/jsfc/src/lib/merge.spec.js b/packages/jsfc/src/merge.spec.js similarity index 100% rename from packages/jsfc/src/lib/merge.spec.js rename to packages/jsfc/src/merge.spec.js diff --git a/packages/jsfc/src/lib/resolve.js b/packages/jsfc/src/resolve.js similarity index 78% rename from packages/jsfc/src/lib/resolve.js rename to packages/jsfc/src/resolve.js index 478b2fce880..01125653903 100644 --- a/packages/jsfc/src/lib/resolve.js +++ b/packages/jsfc/src/resolve.js @@ -1,7 +1,7 @@ -import * as JsonRefs from './../../lib/json-refs-standalone'; +import * as JsonRefs from './../../json-refs-standalone'; export function jsonref(schema, callBack) { - let promise = new Promise(function(resolve, reject) { + let promise = new Promise(function (resolve, reject) { JsonRefs.resolveRefs(schema, { filter: ['relative', 'local', 'remote'], }) diff --git a/packages/jsfc/src/lib/resolve.spec.js b/packages/jsfc/src/resolve.spec.js similarity index 94% rename from packages/jsfc/src/lib/resolve.spec.js rename to packages/jsfc/src/resolve.spec.js index 989c57e71d5..b8ae8cabf42 100644 --- a/packages/jsfc/src/lib/resolve.spec.js +++ b/packages/jsfc/src/resolve.spec.js @@ -83,8 +83,7 @@ describe('resolve.js', () => { type: 'object', properties: { relative: { - $ref: - 'https://raw.githubusercontent.com/json-schema-org/json-schema-org.github.io/master/geo', + $ref: 'https://raw.githubusercontent.com/json-schema-org/json-schema-org.github.io/master/geo', }, }, }; @@ -112,7 +111,7 @@ describe('resolve.js', () => { }); it('should resolve relative json-ref via callback', done => { - jsonref(schema, function(error, resolved) { + jsonref(schema, function (error, resolved) { if (error) done(error); resolved.properties.storage.oneOf[0].properties.should.have.property('device'); done(); @@ -121,7 +120,7 @@ describe('resolve.js', () => { //I believe this only fails in phantomjs due to https://github.com/ariya/phantomjs/issues/11195 it('should resolve remote json-ref via callback', done => { - jsonref(remote, function(error, resolved) { + jsonref(remote, function (error, resolved) { if (error) done(error); //resolved.properties.relative.latitude.type.should.equal('number'); done(); diff --git a/packages/jsfc/src/lib/schema-defaults.spec.js b/packages/jsfc/src/schema-defaults.test.js similarity index 78% rename from packages/jsfc/src/lib/schema-defaults.spec.js rename to packages/jsfc/src/schema-defaults.test.js index dd0a0a5d81c..96a96682238 100644 --- a/packages/jsfc/src/lib/schema-defaults.spec.js +++ b/packages/jsfc/src/schema-defaults.test.js @@ -1,9 +1,5 @@ -import chai from 'chai'; -import { describe, it } from 'mocha'; import { select } from './select'; -chai.should(); - describe('select.js', () => { const data = { name: 'Freddy', @@ -36,28 +32,31 @@ describe('select.js', () => { }; it('should provide a function for getting and setting an object value', () => { - select.should.be.an('function'); + expect(typeof select).toBe('function'); }); describe('select', () => { it('should get a value from an object', () => { let value = select('frienemies[1].weapon.boomstick.method[0]', data); - value.should.eq('boom'); + expect(value).toBe('boom'); }); it('should set a value on an object', () => { let value = select('weapon.glove.method[1]', data, 'slice'); - data.weapon.glove.method.should.be.deep.equal(['stab', 'slice']); + expect(value).toBe('slice'); + expect(data.weapon.glove.method[1]).toBe('slice'); + expect(data.weapon.glove.method).toEqual(['stab', 'slice']); }); it('should create any undefined objects or arrays in the path when setting a value', () => { let data = {}; let value = select('property.array[1].value', data, 'something'); - data.should.be.deep.equal({ + expect(data).toMatchObject({ property: { array: [, { value: 'something' }], }, }); + expect(value).toBe('something'); }); }); }); diff --git a/packages/jsfc/src/lib/schema-defaults.ts b/packages/jsfc/src/schema-defaults.ts similarity index 100% rename from packages/jsfc/src/lib/schema-defaults.ts rename to packages/jsfc/src/schema-defaults.ts diff --git a/packages/jsfc/src/lib/select.js b/packages/jsfc/src/select.js similarity index 100% rename from packages/jsfc/src/lib/select.js rename to packages/jsfc/src/select.js diff --git a/packages/jsfc/src/lib/select.spec.js b/packages/jsfc/src/select.test.js similarity index 94% rename from packages/jsfc/src/lib/select.spec.js rename to packages/jsfc/src/select.test.js index 280089de3c0..798cf775ebf 100644 --- a/packages/jsfc/src/lib/select.spec.js +++ b/packages/jsfc/src/select.test.js @@ -1,19 +1,15 @@ -import chai from 'chai'; -import { describe, it } from 'mocha'; import { defaultForm, createDefaults } from './schema-defaults'; -chai.should(); - describe('schema-defaults.js', () => { it('should hold functions for generating a default form schema from defaults it creates', () => { - defaultForm.should.be.an('function'); - createDefaults.should.be.an('function'); + expect(typeof defaultForm).toBe('function'); + expect(typeof createDefaults).toBe('function'); }); describe('createDefaults', () => { it('should create default rules', () => { const rules = createDefaults(); - rules.should.be.an('object'); + expect(typeof rules).toBe('object'); }); }); @@ -55,7 +51,6 @@ describe('schema-defaults.js', () => { }, }, }; - const form = [ { title: 'Name', @@ -199,9 +194,8 @@ describe('schema-defaults.js', () => { ], }, ]; - const f = defaultForm(schema, createDefaults()); - f.form.should.be.deep.equal(form); + expect(f.form).toMatchObject(form); }); }); }); diff --git a/packages/jsfc/src/sf-path.test.js b/packages/jsfc/src/sf-path.test.js new file mode 100644 index 00000000000..41e2472997b --- /dev/null +++ b/packages/jsfc/src/sf-path.test.js @@ -0,0 +1,10 @@ +import { parse, stringify, normalize, name } from './sf-path'; + +describe('sf-path.js', () => { + it('should hold functions for working with object paths and keys', () => { + expect(typeof parse).toBe('function'); + expect(typeof stringify).toBe('function'); + expect(typeof normalize).toBe('function'); + expect(typeof name).toBe('function'); + }); +}); diff --git a/packages/jsfc/src/lib/sf-path.ts b/packages/jsfc/src/sf-path.ts similarity index 94% rename from packages/jsfc/src/lib/sf-path.ts rename to packages/jsfc/src/sf-path.ts index e68709949eb..2ff737d6a1f 100644 --- a/packages/jsfc/src/lib/sf-path.ts +++ b/packages/jsfc/src/sf-path.ts @@ -18,7 +18,7 @@ export function name(key: Array, separator?: string, formName = '', omit let fieldSeparator = separator || '-'; if (omitNumbers) { - fieldKey = fieldKey.filter(function(currentKey: any) { + fieldKey = fieldKey.filter(function (currentKey: any) { return typeof currentKey !== 'number'; }); } diff --git a/packages/jsfc/src/traverse.test.js b/packages/jsfc/src/traverse.test.js new file mode 100644 index 00000000000..dc13f77fd3f --- /dev/null +++ b/packages/jsfc/src/traverse.test.js @@ -0,0 +1,8 @@ +import { traverseSchema, traverseForm } from './traverse'; + +describe('traverse.js', () => { + it('should hold functions for applying functions on branches of a json-schema or ui-schema', () => { + expect(typeof traverseSchema).toBe('function'); + expect(typeof traverseForm).toBe('function'); + }); +}); diff --git a/packages/jsfc/src/lib/traverse.ts b/packages/jsfc/src/traverse.ts similarity index 97% rename from packages/jsfc/src/lib/traverse.ts rename to packages/jsfc/src/traverse.ts index 76c1ce7b32c..07cca79ef19 100644 --- a/packages/jsfc/src/lib/traverse.ts +++ b/packages/jsfc/src/traverse.ts @@ -7,7 +7,7 @@ export function traverseSchema(schema, fn, path, ignoreArrays) { path = path || []; - const traverse = function( + const traverse = function ( schemaObject: any, processorFunction: Function, pathArray: Array, diff --git a/packages/jsfc/src/lib/validate.js b/packages/jsfc/src/validate.js similarity index 100% rename from packages/jsfc/src/lib/validate.js rename to packages/jsfc/src/validate.js diff --git a/packages/jsfc/src/lib/validate.spec.js b/packages/jsfc/src/validate.test.js similarity index 71% rename from packages/jsfc/src/lib/validate.spec.js rename to packages/jsfc/src/validate.test.js index 59b2239e1f7..e6c61b1c605 100644 --- a/packages/jsfc/src/lib/validate.spec.js +++ b/packages/jsfc/src/validate.test.js @@ -1,12 +1,8 @@ -import chai from 'chai'; -import { describe, it } from 'mocha'; import { validate } from './validate'; -let should = chai.should(); - describe('validate.js', () => { it('should hold a validation function for testing against tv4 until an option to pass in a validator is created', () => { - validate.should.be.an('function'); + expect(typeof validate).toBe('function'); }); describe('validate', () => { @@ -14,16 +10,15 @@ describe('validate.js', () => { it('should return a result object {"error":null, "missing":[], "valid":true}, with valid set to true when the data is valid for the schema', () => { let value = 'Batman'; let result = validate(form, value, {}); - should.not.exist(result.error); - result.missing.should.be.a('array'); - result.missing.length.should.equal(0); - result.valid.should.equal(true); + expect(result.error).toBe(null); + expect(result.missing).toEqual([]); + expect(result.valid).toBe(true); }); it('should return an error object with a message "Invalid type: array (expected string)" when the data is not valid', () => { let value = [0]; let result = validate(form, value, {}); - result.error.message.should.eq('Invalid type: array (expected string)'); + expect(result.error.message).toBe('Invalid type: array (expected string)'); }); it('should return an error object with a message "CUSTOM_ERROR_INVALID_INPUT" when the integer value is not valid', () => { @@ -31,7 +26,7 @@ describe('validate.js', () => { const testForm = { type: 'number', key: ['hero'], schema: { type: 'number' } }; const event = { target: { validity: { valid: false } } }; let result = validate(testForm, value, event); - result.error.message.should.eq('CUSTOM_ERROR_INVALID_INPUT'); + expect(result.error.message).toBe('CUSTOM_ERROR_INVALID_INPUT'); }); }); });