diff --git a/src/dapi/DataApiManager.js b/src/dapi/DataApiManager.js index f67960c..35d137c 100644 --- a/src/dapi/DataApiManager.js +++ b/src/dapi/DataApiManager.js @@ -679,7 +679,10 @@ module.exports = Class( 'DataApiManager' ) var param = map[ field ], fdata = []; - fdata[ index ] = ( data[ param ] || '' ); + fdata[ index ] = ( data[ param ] !== undefined ) + ? data[ param ] + : ''; + update[ field ] = fdata; } diff --git a/test/dapi/DataApiManagerTest.js b/test/dapi/DataApiManagerTest.js index f9a1656..5b06707 100644 --- a/test/dapi/DataApiManagerTest.js +++ b/test/dapi/DataApiManagerTest.js @@ -54,6 +54,45 @@ describe( 'DataApiManager', () => .setApis( { [type]: { type: type } } ) .getApiData( type, {}, ()=>{}, name, index, {}, fail ); } ); + + + // TODO: This doesn't test everything; see commit that introduced it. + [ + { + map: { out: 'in' }, + fdata: [ { in: 'foo' } ], + expected: { out: [ 'foo' ] }, + }, + + // retain booleans (in particular, don't convert `false' to an empty + // string + { + map: { out: 'in' }, + fdata: [ { in: true } ], + expected: { out: [ true ] }, + }, + { + map: { out: 'in' }, + fdata: [ { in: false } ], + expected: { out: [ false ] }, + }, + ].forEach( ( { map, fdata, expected } ) => + { + it( 'generates update from data expansion', () => + { + const name = 'fooname'; + const index = 0; + + const sut = Sut( createStubDapiFactory( {} ) ); + + sut.setFieldData( name, index, fdata, 'in', '' ); + + const bucket = { getDataByName: () => [ fdata[ 0 ].in ] }; + + expect( sut.getDataExpansion( name, index, bucket, map, true, {} ) ) + .to.deep.equal( expected ); + } ) + } ); } );