@@ -1584,4 +1584,105 @@ describe('ParseQuery', () => {
15841584 } ) ;
15851585
15861586 } ) ;
1587+
1588+ it ( 'selecting sub-objects does not inject objects when sub-object does not exist' , ( done ) => {
1589+ jest . dontMock ( "../ParseObject" ) ;
1590+ jest . resetModules ( ) ;
1591+ ParseObject = require ( '../ParseObject' ) . default ;
1592+ CoreManager = require ( '../CoreManager' ) ;
1593+ ParseQuery = require ( '../ParseQuery' ) . default ;
1594+
1595+ ParseObject . enableSingleInstance ( ) ;
1596+
1597+ var objectToReturn = {
1598+ objectId : 'T01' ,
1599+ name : 'Name' ,
1600+ tbd : 'exists' ,
1601+ className :"Thing" ,
1602+ createdAt : '2017-01-10T10:00:00Z'
1603+ } ;
1604+
1605+ CoreManager . setQueryController ( {
1606+ find ( className , params , options ) {
1607+ return ParsePromise . as ( {
1608+ results : [ objectToReturn ]
1609+ } ) ;
1610+ }
1611+ } ) ;
1612+
1613+ var q = new ParseQuery ( "Thing" ) ;
1614+ q . select ( "other" , "tbd" , "subObject.key1" )
1615+ var testObject ;
1616+ return q . find ( ) . then ( ( results ) => {
1617+ testObject = results [ 0 ] ;
1618+
1619+ expect ( testObject . get ( "name" ) ) . toBe ( "Name" ) ;
1620+ expect ( testObject . has ( "other" ) ) . toBe ( false ) ;
1621+ expect ( testObject . has ( "subObject" ) ) . toBe ( false ) ;
1622+
1623+ } ) . then ( ( ) => {
1624+ done ( ) ;
1625+ } , ( error ) => {
1626+ done . fail ( error ) ;
1627+ } ) ;
1628+ } ) ;
1629+
1630+ it ( 'removes missing sub objects from the cached object when they are selected' , ( done ) => {
1631+ jest . dontMock ( "../ParseObject" ) ;
1632+ jest . resetModules ( ) ;
1633+ ParseObject = require ( '../ParseObject' ) . default ;
1634+ CoreManager = require ( '../CoreManager' ) ;
1635+ ParseQuery = require ( '../ParseQuery' ) . default ;
1636+
1637+ ParseObject . enableSingleInstance ( ) ;
1638+
1639+ var objectToReturn = {
1640+ objectId : 'T01' ,
1641+ name : 'Name' ,
1642+ tbd : 'exists' ,
1643+ className :"Thing" ,
1644+ subObject1 : { foo :"bar" } ,
1645+ subObject2 : { foo :"bar" } ,
1646+ subObject3 : { foo :"bar" } ,
1647+ subObject5 : { subSubObject :{ foo :"foo" , bar :"bar" } } ,
1648+ createdAt : '2017-01-10T10:00:00Z'
1649+ } ;
1650+
1651+ CoreManager . setQueryController ( {
1652+ find ( className , params , options ) {
1653+ return ParsePromise . as ( {
1654+ results : [ objectToReturn ]
1655+ } ) ;
1656+ }
1657+ } ) ;
1658+
1659+ var q = new ParseQuery ( "Thing" ) ;
1660+ var testObject ;
1661+ return q . find ( ) . then ( ( results ) => {
1662+ testObject = results [ 0 ] ;
1663+
1664+ expect ( testObject . has ( "subObject1" ) ) . toBe ( true ) ;
1665+ expect ( testObject . has ( "subObject2" ) ) . toBe ( true ) ;
1666+ expect ( testObject . has ( "subObject3" ) ) . toBe ( true ) ;
1667+ expect ( testObject . has ( "subObject4" ) ) . toBe ( false ) ;
1668+
1669+ var q2 = new ParseQuery ( "Thing" ) ;
1670+ q . select ( "name" , "subObject1" , "subObject2.foo" , "subObject4.foo" , "subObject5.subSubObject.foo" ) ;
1671+ objectToReturn = { objectId : 'T01' , name :"Name" , subObject4 : { foo :"bar" } , subObject5 : { subSubObject :{ } } } ;
1672+ return q . find ( ) ;
1673+ } ) . then ( ( results ) => {
1674+ expect ( testObject . has ( "subObject1" ) ) . toBe ( false ) ; //selected and not returned
1675+ expect ( testObject . has ( "subObject2" ) ) . toBe ( false ) ; //selected and not returned
1676+ expect ( testObject . has ( "subObject3" ) ) . toBe ( true ) ; //not selected, so should still be there
1677+ expect ( testObject . has ( "subObject4" ) ) . toBe ( true ) ; //selected and just added
1678+ expect ( testObject . has ( "subObject5" ) ) . toBe ( true ) ;
1679+ expect ( testObject . get ( "subObject5" ) . subSubObject ) . toBeDefined ( ) ;
1680+ expect ( testObject . get ( "subObject5" ) . subSubObject . bar ) . toBeDefined ( ) ; //not selected but a sibiling was, so should still be there
1681+ } ) . then ( ( ) => {
1682+ done ( ) ;
1683+ } , ( error ) => {
1684+ done . fail ( error ) ;
1685+ } ) ;
1686+ } ) ;
1687+
15871688} ) ;
0 commit comments