@@ -1363,6 +1363,58 @@ describe('Model define with scopes configuration', function() {
13631363  } ) ; 
13641364} ) ; 
13651365
1366+ describe ( 'DataAccessObject._forDB' ,  function ( )  { 
1367+   const  ds  =  new  DataSource ( 'memory' ) ; 
1368+   const  dao  =  ds . DataAccessObject ; 
1369+ 
1370+   it ( 'should return input data if dataSource is not relational' ,  function ( )  { 
1371+     const  inputData  =  { testKey : 'testValue' } ; 
1372+     dao . getDataSource  =  ( )  =>  ( { isRelational : ( )  =>  false } ) ; 
1373+ 
1374+     const  outputData  =  dao . _forDB ( inputData ) ; 
1375+ 
1376+     assert . deepEqual ( outputData ,  inputData ) ; 
1377+   } ) ; 
1378+ 
1379+   it ( 'should return JSON stringified values for appropriate types' ,  function ( )  { 
1380+     const  inputData  =  { 
1381+       key1 : [ 1 ,  2 ,  3 ] , 
1382+       key2 : { subKey : 'value' } , 
1383+       key3 : 'nonJSONvalue' , 
1384+     } ; 
1385+     dao . getDataSource  =  ( )  =>  ( { isRelational : ( )  =>  true } ) ; 
1386+     dao . getPropertyType  =  ( propName )  =>  ( propName  !==  'key3'  ? 'JSON'  : 'String' ) ; 
1387+ 
1388+     const  outputData  =  dao . _forDB ( inputData ) ; 
1389+ 
1390+     assert . deepEqual ( outputData ,  { 
1391+       key1 : JSON . stringify ( [ 1 ,  2 ,  3 ] ) , 
1392+       key2 : JSON . stringify ( { subKey : 'value' } ) , 
1393+       key3 : 'nonJSONvalue' , 
1394+     } ) ; 
1395+   } ) ; 
1396+ 
1397+   it ( 'should return original value for non JSON, non Array types' ,  function ( )  { 
1398+     const  inputData  =  { key1 : 'string' ,  key2 : 123 ,  key3 : true } ; 
1399+     dao . getDataSource  =  ( )  =>  ( { isRelational : ( )  =>  true } ) ; 
1400+     dao . getPropertyType  =  ( )  =>  'String' ; 
1401+ 
1402+     const  outputData  =  dao . _forDB ( inputData ) ; 
1403+ 
1404+     assert . deepEqual ( outputData ,  inputData ) ; 
1405+   } ) ; 
1406+ 
1407+   it ( 'should not process null values' ,  function ( )  { 
1408+     const  inputData  =  { key1 : 'value' ,  key2 : null } ; 
1409+     dao . getDataSource  =  ( )  =>  ( { isRelational : ( )  =>  true } ) ; 
1410+     dao . getPropertyType  =  ( propName )  =>  'JSON' ; 
1411+ 
1412+     const  outputData  =  dao . _forDB ( inputData ) ; 
1413+ 
1414+     assert . deepEqual ( outputData ,  { key1 : JSON . stringify ( 'value' ) ,  key2 : null } ) ; 
1415+   } ) ; 
1416+ } ) ; 
1417+ 
13661418describe ( 'DataAccessObject' ,  function ( )  { 
13671419  let  ds ,  model ,  where ,  error ,  filter ; 
13681420
0 commit comments