File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed
Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -249,7 +249,7 @@ module.exports = class Flattener {
249249 const flattenedRecord = { } ;
250250
251251 Object . keys ( record ) . forEach ( ( attribute ) => {
252- if ( typeof record [ attribute ] === 'object' ) {
252+ if ( record [ attribute ] !== null && typeof record [ attribute ] === 'object' ) {
253253 const flattenedPath = ( flattenComposedKey ) ? `${ flattenComposedKey } ${ FLATTEN_SEPARATOR } ${ attribute } ` : attribute ;
254254
255255 if ( flattenedFields . find ( ( flattenedField ) => flattenedField === flattenedPath ) ) {
Original file line number Diff line number Diff line change @@ -898,8 +898,7 @@ describe('service > Flattener', () => {
898898 engine : {
899899 horsePower : '78' ,
900900 identification : {
901- manufacturer : 'Renault'
902- + '' ,
901+ manufacturer : 'Renault' ,
903902 } ,
904903 } ,
905904 name : 'Car' ,
@@ -918,6 +917,33 @@ describe('service > Flattener', () => {
918917 name : 'Car' ,
919918 } ) ;
920919 } ) ;
920+
921+ it ( 'should correctly set values to null' , ( ) => {
922+ expect . assertions ( 1 ) ;
923+
924+ const record = {
925+ engine : {
926+ horsePower : '78' ,
927+ identification : {
928+ manufacturer : null ,
929+ } ,
930+ } ,
931+ name : null ,
932+ } ;
933+
934+ const flattenedFields = [
935+ `engine${ FLATTEN_SEPARATOR } horsePower` ,
936+ `engine${ FLATTEN_SEPARATOR } identification${ FLATTEN_SEPARATOR } manufacturer` ,
937+ ] ;
938+
939+ const flattenedRecord = Flattener . flattenRecordDataForUpdates ( record , null , flattenedFields ) ;
940+
941+ expect ( flattenedRecord ) . toStrictEqual ( {
942+ 'engine.horsePower' : '78' ,
943+ 'engine.identification.manufacturer' : null ,
944+ name : null ,
945+ } ) ;
946+ } ) ;
921947 } ) ;
922948
923949 describe ( 'getFlattenedFieldsName' , ( ) => {
You can’t perform that action at this time.
0 commit comments