@hmcts/one-per-page
Advanced tools
Comparing version 4.0.1 to 4.0.2
@@ -5,3 +5,3 @@ { | ||
"homepage": "https://github.com/hmcts/one-per-page#readme", | ||
"version": "4.0.1", | ||
"version": "4.0.2", | ||
"main": "./src/main.js", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -78,3 +78,11 @@ const { fieldDescriptor } = require('./fieldDescriptor'); | ||
const fieldName = `${name}[${i}]`; | ||
return { [i]: field.parse(fieldName, { [fieldName]: value }) }; | ||
const valueBody = {}; | ||
if (typeof value === 'object') { | ||
Object.keys(value).forEach(key => { | ||
valueBody[`${fieldName}-${key}`] = value[key]; | ||
}); | ||
} else { | ||
valueBody[fieldName] = value; | ||
} | ||
return { [i]: field.parse(fieldName, valueBody) }; | ||
}) | ||
@@ -81,0 +89,0 @@ .reduce(flattenObject, {}); |
@@ -202,2 +202,23 @@ const { expect } = require('../util/chai'); | ||
describe('list(object({ a: text, b: bool }))', fieldTest( | ||
list(object({ a: text, b: bool })), it => { | ||
it.parses({ to: [{}], from: [{}] }); | ||
it.parses({ | ||
to: [{ a: 'text', b: true }], | ||
from: [{ a: 'text', b: 'true' }] | ||
}); | ||
it.deserializes({ | ||
value: [{ a: 'text', b: 'true' }], | ||
from: [{ a: 'text', b: 'true' }] | ||
}); | ||
it.serializes({ | ||
to: [{ a: 'text', b: true }], | ||
from: [{ a: 'text', b: true }] | ||
}); | ||
} | ||
)); | ||
describe('appendToList([list], [index], text)', fieldTest( | ||
@@ -204,0 +225,0 @@ appendToList('items', 1, text), it => { |
1343342
8912