1
0
Fork 0

Do not convert non-truthy dapi return values to empty string

* src/dapi/DataApiManager.js (getDataExpansion): Explicit undefined
  check before triggering default (empty string).
* test/dapi/DataApiManagerTest.js: Add associated test cases.
master
Mike Gerwitz 2017-07-21 15:20:55 -04:00
parent 1d8d382b4d
commit 229a356a9a
2 changed files with 43 additions and 1 deletions

View File

@ -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;
}

View File

@ -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 );
} )
} );
} );