Skip to content

Commit

Permalink
chore: secu
Browse files Browse the repository at this point in the history
  • Loading branch information
jmfrancois committed Oct 6, 2023
1 parent 7d627f3 commit 329504e
Show file tree
Hide file tree
Showing 20 changed files with 56 additions and 113 deletions.
2 changes: 1 addition & 1 deletion packages/jsfc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
Original file line number Diff line number Diff line change
@@ -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<any>, originalEnum?: any) {
export default function (titleMap: Array<any>, originalEnum?: any) {
if (!Array.isArray(titleMap)) {
const canonical = [];
if (originalEnum) {
Expand Down
16 changes: 8 additions & 8 deletions packages/jsfc/src/index.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
38 changes: 0 additions & 38 deletions packages/jsfc/src/lib/sf-path.spec.js

This file was deleted.

24 changes: 0 additions & 24 deletions packages/jsfc/src/lib/traverse.spec.js

This file was deleted.

8 changes: 4 additions & 4 deletions packages/jsfc/src/lib/merge.js → packages/jsfc/src/merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}),
);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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'],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
};
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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');
});
});
});
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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');
});
});

Expand Down Expand Up @@ -55,7 +51,6 @@ describe('schema-defaults.js', () => {
},
},
};

const form = [
{
title: 'Name',
Expand Down Expand Up @@ -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);
});
});
});
10 changes: 10 additions & 0 deletions packages/jsfc/src/sf-path.test.js
Original file line number Diff line number Diff line change
@@ -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');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function name(key: Array<string>, 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';
});
}
Expand Down
8 changes: 8 additions & 0 deletions packages/jsfc/src/traverse.test.js
Original file line number Diff line number Diff line change
@@ -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');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,37 +1,32 @@
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', () => {
const form = { key: ['hero'], schema: { type: 'string' } };
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', () => {
let value = 'stringValue';
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');
});
});
});

0 comments on commit 329504e

Please sign in to comment.