[DEV-4338] Change behavior of default data
Default data was converted to an empty array if the data evaluated to false. We only want to convert it if it is undefined so values that are false remain false.master
parent
deb92bf052
commit
a2d1ea706a
|
@ -297,7 +297,19 @@ module.exports = Class( 'DataProcessor',
|
|||
const bdata = ( diff_data[ bucketid ] || [] )[ index ] ||
|
||||
( bucket.getDataByName( bucketid ) || [] )[ index ];
|
||||
|
||||
result[ srcid ] = bdata || [];
|
||||
if ( typeof bdata === 'undefined' )
|
||||
{
|
||||
// This might be better as an empty string, but we will
|
||||
// need to look into it more before we change it. It has
|
||||
// been an empty array for a long time and it might cause
|
||||
// issues to change it now.
|
||||
result[ srcid ] = [];
|
||||
}
|
||||
else
|
||||
{
|
||||
result[ srcid ] = bdata;
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
{}
|
||||
|
|
|
@ -107,7 +107,7 @@ describe( 'DataProcessor', () =>
|
|||
expect( given_request ).to.equal( request );
|
||||
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
Sut( filter, dapi_factory, null, createStubStagingBucket )
|
||||
.processDiff( {}, request, program );
|
||||
|
@ -250,6 +250,69 @@ describe( 'DataProcessor', () =>
|
|||
|
||||
return Promise.all( dapis );
|
||||
} );
|
||||
|
||||
|
||||
it( "check _mapDapiData default values", () =>
|
||||
{
|
||||
const triggered = {};
|
||||
|
||||
// g prefix = "given"
|
||||
const getFieldData = function( gfield, gindex, gdapim, gdapi, gdata)
|
||||
{
|
||||
triggered[ gdapi.name ] = triggered[ gdapi.name ] || [];
|
||||
triggered[ gdapi.name ][ gindex ] = arguments;
|
||||
|
||||
expect( gdata ).to.deep.equal( { ina: '', inb: [] } );
|
||||
|
||||
return Promise.resolve( true );
|
||||
};
|
||||
|
||||
const dapi_manager = {};
|
||||
|
||||
const {
|
||||
request,
|
||||
program,
|
||||
filter,
|
||||
meta_source,
|
||||
} = createStubs( false, {}, getFieldData );
|
||||
|
||||
const sut = Sut(
|
||||
filter,
|
||||
() => dapi_manager,
|
||||
meta_source,
|
||||
createStubStagingBucket
|
||||
);
|
||||
|
||||
program.meta.fields = {
|
||||
foo: {
|
||||
dapi: {
|
||||
name: 'dapi_foo',
|
||||
mapsrc: { ina: 'src', inb: 'src1' },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
program.mapis = {
|
||||
src1: [ 'foo' ], // change
|
||||
};
|
||||
|
||||
// data changed
|
||||
const data = {
|
||||
src: [ 'src0', '' ],
|
||||
src1: [ undefined, '' ],
|
||||
};
|
||||
|
||||
const bucket = createStubBucket( {
|
||||
src: [ 'bsrc0', '' ],
|
||||
src1: [ 'bsrc10', undefined],
|
||||
} );
|
||||
|
||||
const { dapis } = sut.processDiff(
|
||||
data, request, program, bucket
|
||||
);
|
||||
|
||||
return Promise.all( dapis );
|
||||
} );
|
||||
} );
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue