1
0
Fork 0

[DEV-3192] fixed test cases

master
Jeffrey Fisher 2018-06-12 15:20:14 -04:00
parent 3e32442a43
commit 94f76c5a77
2 changed files with 26 additions and 38 deletions

View File

@ -66,35 +66,34 @@ module.exports = Class( 'ProgramInit',
while ( length-- )
{
var field = program.groupExclusiveFields[ group ][ length ],
defaultValue = {};
defaultValue;
if ( defaults.hasOwnProperty(field) )
{
defaultValue = defaults[ field ];
}
// Initialize with existing document data if any
data[ field ] = doc_data[ field ] ? doc_data[ field ] : [];
// Initialize with existing document data if any
data[ field ] = doc_data[ field ] ? doc_data[ field ] : [];
// If no document data, initialize with default value
if ( !doc_data[ field ] )
{
data[ field ][ 0 ] = defaultValue;
}
// If min rows on the group is greater than the data
// currently in the bucket, then populate the rest
// of the data with the default data until the
// arrays are the same length
if ( groups.hasOwnProperty( group ) &&
data[ field ].length < groups[ group ].min )
{
var index = data[ field ].length;
while ( index < groups[ group ].min )
// If no document data, initialize with default value
if ( !doc_data[ field ] )
{
data[ field ][ index ] = defaultValue;
index++;
data[ field ][ 0 ] = defaultValue;
}
// If min rows on the group is greater than the data
// currently in the bucket, then populate the rest
// of the data with the default data until the
// arrays are the same length
if ( groups.hasOwnProperty( group ) &&
data[ field ].length < groups[ group ].min )
{
var index = data[ field ].length;
while ( index < groups[ group ].min )
{
data[ field ][ index ] = defaultValue;
index++;
}
}
}
}

View File

@ -68,7 +68,10 @@ describe( 'ProgramInit', () =>
},
{
label: "keeps existing data with defaults",
defaults: { foo: "init" },
defaults: {
foo: "init",
bar: "test"
},
meta: {
groups: {}
},
@ -82,20 +85,6 @@ describe( 'ProgramInit', () =>
bar: [ "baz" ],
},
},
{
label: "keeps existing doc data with no defaults",
defaults: {},
meta: {
groups: {}
},
groupExclusiveFields: {
Something: [ "foo" ],
},
doc_data: { foo: [ "bar" ] },
expected: {
foo: [ "bar" ],
},
},
{
label: "does not overwrite existing data with defaults",
defaults: { foo: "init" },