Skip to content

Commit

Permalink
removed redundant line in validate()
Browse files Browse the repository at this point in the history
  • Loading branch information
boycce committed Aug 9, 2024
1 parent 9f50e1c commit 9dfe7f3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 35 deletions.
1 change: 0 additions & 1 deletion lib/model-validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ Model.prototype._validateFields = function (dataRoot, fields, data, opts, parent
}

// Normalise array indexes and return
if (fieldsIsArray) data2 = data2.filter(() => true) //todo: remove???
if (data === null) data2 = null
return [errors, data2]
}
Expand Down
2 changes: 1 addition & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ module.exports = {
parseDotNotation: function(obj) {
/**
* Converts dot notation field paths into deep objects
* @param {object} obj - e.g. { 'deep.companyLogos2.1.logo': '' }
* @param {object} obj - e.g. { 'deep.companyLogos2.1.logo': '' } (not mutated)
* @return {object} - e.g. { deep: { companyLogos2: [{ logo: '' }] }}
*/
if (!Object.keys(obj).some(key => key.includes('.'))) return obj
Expand Down
40 changes: 7 additions & 33 deletions test/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ test('util > parseDotNotation', async () => {
'deep.companyLogo3': 'c',
'deep.companyLogos.0.logo': 'd',
'deep.companyLogos.1.logo': 'e',
'deep.companyLogos.2': 'f',
}
const output = {
name: 'Martin',
deep: { // object first seen here
companyLogo2: 'b',
companyLogo3: 'c',
companyLogos: [{ logo: 'd' }, { logo: 'e' }],
companyLogos: [{ logo: 'd' }, { logo: 'e' }, 'f'],
},
specialInstructions: [
{
Expand Down Expand Up @@ -79,7 +80,7 @@ test('util > parseDotNotation', async () => {
test('util > parseBracketNotation', async () => {
const input = {
'name': 'Martin',
// 'pets[]': '', // <-- not supported
// 'pets[]': '', // <-- no longer supported
'deep[companyLogo1]': 'a',
// not dot notation
'specialInstructions': [
Expand Down Expand Up @@ -107,16 +108,17 @@ test('util > parseBracketNotation', async () => {
},
// should be added into above
'deep[companyLogo3]': 'c',
'deep[companyLogos][0][logo]':'d',
'deep[companyLogos][1][logo]':'e',
'deep[companyLogos][0][logo]': 'd',
'deep[companyLogos][1][logo]': 'e',
'deep[companyLogos][2]': 'f',
}
const output = {
name: 'Martin',
// pets: expect.any(Array),
deep: { // object first seen here
companyLogo2: 'b',
companyLogo3: 'c',
companyLogos: [{ logo: 'd' }, { logo: 'e' }],
companyLogos: [{ logo: 'd' }, { logo: 'e' }, 'f'],
},
specialInstructions: [
{
Expand Down Expand Up @@ -156,34 +158,6 @@ test('util > parseBracketNotation', async () => {
)
})

// test('util > parseBracketToDotNotation', async () => {
// expect(await util.parseBracketToDotNotation({
// 'name': 'Martin',
// 'pets[]': '',
// 'deep[companyLogo]': 'a',
// 'deep[companyLogos][0]': 'b',
// 'deep[companyLogos2][0][logo]':'c',
// 'deep[companyLogos2][1][logo]': '',
// 'users[0][first]': 'Martin',
// 'users[0][last]': 'Luther',
// 'users[1][first]': 'Bruce',
// 'users[1][last]': 'Lee',
// })).toEqual({
// name: 'Martin',
// pets: expect.any(Array),
// 'deep.companyLogo': 'a',
// 'deep.companyLogos.0': 'b',
// 'deep.companyLogos2.0.logo': 'c',
// 'deep.companyLogos2.1.logo': '',
// 'users.0.first': 'Martin',
// 'users.0.last': 'Luther',
// 'users.1.first': 'Bruce',
// 'users.1.last': 'Lee',
// })
// expect(() => util.parseBracketNotation({ 'users[][\'name\']': 'Martin' })).toThrow(
// 'Monastery: Array items in bracket notation need array indexes "users[][\'name\']", e.g. users[0][name]'
// )
// })

test('util > isId', async () => {
expect(util.isId('')).toEqual(false)
Expand Down

0 comments on commit 9dfe7f3

Please sign in to comment.