@@ -1462,4 +1462,234 @@ describe('miscellaneous', function() {
14621462 done ( ) ;
14631463 } ) ;
14641464 } ) ;
1465+
1466+ it_exclude_dbs ( [ 'postgres' ] ) ( 'import objects from rest array' , ( done ) => {
1467+ let headers = {
1468+ 'Content-Type' : 'application/json' ,
1469+ 'X-Parse-Application-Id' : 'test' ,
1470+ 'X-Parse-Master-Key' : 'test'
1471+ } ;
1472+ request . post (
1473+ {
1474+ headers : headers ,
1475+ url : 'http://localhost:8378/1/import/TestObject' ,
1476+ body : JSON . stringify ( [
1477+ { column1 : 'row1Column1' , column2 : 'row1Column2' } ,
1478+ { column1 : 'row2Column1' , column2 : 'row2Column2' }
1479+ ] )
1480+ } ,
1481+ ( err ) => {
1482+ expect ( err ) . toBe ( null ) ;
1483+ let query = new Parse . Query ( 'TestObject' ) ;
1484+ query . ascending ( 'column1' ) ;
1485+ query . find ( ) . then ( ( results ) => {
1486+ expect ( results . length ) . toEqual ( 2 ) ;
1487+ expect ( results [ 0 ] . get ( 'column1' ) ) . toEqual ( 'row1Column1' ) ;
1488+ expect ( results [ 0 ] . get ( 'column2' ) ) . toEqual ( 'row1Column2' ) ;
1489+ expect ( results [ 1 ] . get ( 'column1' ) ) . toEqual ( 'row2Column1' ) ;
1490+ expect ( results [ 1 ] . get ( 'column2' ) ) . toEqual ( 'row2Column2' ) ;
1491+ done ( ) ;
1492+ } ) ;
1493+ }
1494+ ) ;
1495+ } ) ;
1496+
1497+ it_exclude_dbs ( [ 'postgres' ] ) ( 'import objects from json with results field' , ( done ) => {
1498+ let headers = {
1499+ 'Content-Type' : 'application/json' ,
1500+ 'X-Parse-Application-Id' : 'test' ,
1501+ 'X-Parse-Master-Key' : 'test'
1502+ } ;
1503+ request . post (
1504+ {
1505+ headers : headers ,
1506+ url : 'http://localhost:8378/1/import/TestObject' ,
1507+ body : JSON . stringify ( {
1508+ results : [
1509+ { column1 : 'row1Column1' , column2 : 'row1Column2' } ,
1510+ { column1 : 'row2Column1' , column2 : 'row2Column2' }
1511+ ]
1512+ } )
1513+ } ,
1514+ ( err ) => {
1515+ expect ( err ) . toBe ( null ) ;
1516+ let query = new Parse . Query ( 'TestObject' ) ;
1517+ query . ascending ( 'column1' ) ;
1518+ query . find ( ) . then ( ( results ) => {
1519+ expect ( results . length ) . toEqual ( 2 ) ;
1520+ expect ( results [ 0 ] . get ( 'column1' ) ) . toEqual ( 'row1Column1' ) ;
1521+ expect ( results [ 0 ] . get ( 'column2' ) ) . toEqual ( 'row1Column2' ) ;
1522+ expect ( results [ 1 ] . get ( 'column1' ) ) . toEqual ( 'row2Column1' ) ;
1523+ expect ( results [ 1 ] . get ( 'column2' ) ) . toEqual ( 'row2Column2' ) ;
1524+ done ( ) ;
1525+ } ) ;
1526+ }
1527+ ) ;
1528+ } ) ;
1529+
1530+ it_exclude_dbs ( [ 'postgres' ] ) ( 'import objects with object id' , ( done ) => {
1531+ let headers = {
1532+ 'Content-Type' : 'application/json' ,
1533+ 'X-Parse-Application-Id' : 'test' ,
1534+ 'X-Parse-Master-Key' : 'test'
1535+ } ;
1536+ request . post (
1537+ {
1538+ headers : headers ,
1539+ url : 'http://localhost:8378/1/import/TestObject' ,
1540+ body : JSON . stringify ( {
1541+ results : [
1542+ {
1543+ "objectId" : "aaaaaaaaaa" ,
1544+ "data" : "somedataa"
1545+ } ,
1546+ {
1547+ "objectId" : "bbbbbbbbbb" ,
1548+ "data" : "somedatab"
1549+ }
1550+ ]
1551+ } )
1552+ } ,
1553+ ( err ) => {
1554+ expect ( err ) . toBe ( null ) ;
1555+ let query = new Parse . Query ( 'TestObject' ) ;
1556+ query . ascending ( 'data' ) ;
1557+ query . find ( ) . then ( ( results ) => {
1558+ expect ( results . length ) . toEqual ( 2 ) ;
1559+ expect ( results [ 0 ] . id ) . toEqual ( 'aaaaaaaaaa' ) ;
1560+ expect ( results [ 1 ] . id ) . toEqual ( 'bbbbbbbbbb' ) ;
1561+ done ( ) ;
1562+ } ) ;
1563+ }
1564+ ) ;
1565+ } ) ;
1566+
1567+ it_exclude_dbs ( [ 'postgres' ] ) ( 'update objects with existing object id' , ( done ) => {
1568+ let headers = {
1569+ 'Content-Type' : 'application/json' ,
1570+ 'X-Parse-Application-Id' : 'test' ,
1571+ 'X-Parse-Master-Key' : 'test'
1572+ } ;
1573+ request . post (
1574+ {
1575+ headers : headers ,
1576+ url : 'http://localhost:8378/1/import/TestObject' ,
1577+ body : JSON . stringify ( {
1578+ results : [
1579+ {
1580+ "objectId" : "aaaaaaaaaa" ,
1581+ "data" : "somedataa"
1582+ } ,
1583+ {
1584+ "objectId" : "bbbbbbbbbb" ,
1585+ "data" : "somedatab"
1586+ }
1587+ ]
1588+ } )
1589+ } ,
1590+ ( err ) => {
1591+ expect ( err ) . toBe ( null ) ;
1592+ request . post (
1593+ {
1594+ headers : headers ,
1595+ url : 'http://localhost:8378/1/import/TestObject' ,
1596+ body : JSON . stringify ( {
1597+ results : [
1598+ {
1599+ "objectId" : "aaaaaaaaaa" ,
1600+ "data" : "somedataa2"
1601+ }
1602+ ]
1603+ } )
1604+ } ,
1605+ ( err ) => {
1606+ expect ( err ) . toBe ( null ) ;
1607+ let query = new Parse . Query ( 'TestObject' ) ;
1608+ query . ascending ( 'data' ) ;
1609+ query . find ( ) . then ( ( results ) => {
1610+ expect ( results . length ) . toEqual ( 2 ) ;
1611+ expect ( results [ 0 ] . id ) . toEqual ( 'aaaaaaaaaa' ) ;
1612+ expect ( results [ 0 ] . get ( 'data' ) ) . toEqual ( 'somedataa2' ) ;
1613+ expect ( results [ 1 ] . id ) . toEqual ( 'bbbbbbbbbb' ) ;
1614+ expect ( results [ 1 ] . get ( 'data' ) ) . toEqual ( 'somedatab' ) ;
1615+ done ( ) ;
1616+ } ) ;
1617+ }
1618+ ) ;
1619+ }
1620+ ) ;
1621+ } ) ;
1622+
1623+ it_exclude_dbs ( [ 'postgres' ] ) ( 'import relations object from json' , ( done ) => {
1624+ let headers = {
1625+ 'Content-Type' : 'application/json' ,
1626+ 'X-Parse-Application-Id' : 'test' ,
1627+ 'X-Parse-Master-Key' : 'test'
1628+ } ;
1629+
1630+ let promises = [ ] ;
1631+
1632+ let object = new Parse . Object ( 'TestObjectDad' ) ;
1633+ let relatedObject = new Parse . Object ( 'TestObjectChild' ) ;
1634+ Parse . Object . saveAll ( [ object , relatedObject ] ) . then ( ( ) => {
1635+ object . relation ( 'RelationObject' ) . add ( relatedObject ) ;
1636+ return object . save ( ) ;
1637+ } ) ;
1638+
1639+ promises . push ( rp ( {
1640+ method : 'POST' ,
1641+ headers : headers ,
1642+ url : 'http://localhost:8378/1/import/TestObjectDad' ,
1643+ body : JSON . stringify ( {
1644+ results : [
1645+ {
1646+ "objectId" : "aaa" ,
1647+ "Name" : "namea" ,
1648+ }
1649+ ]
1650+ } )
1651+ } ) ) ;
1652+
1653+ promises . push ( rp ( {
1654+ method : 'POST' ,
1655+ headers : headers ,
1656+ url : 'http://localhost:8378/1/import/TestObjectChild' ,
1657+ body : JSON . stringify ( {
1658+ results : [
1659+ {
1660+ "objectId" : "bbb" ,
1661+ "Name" : "nameb"
1662+ }
1663+ ]
1664+ } )
1665+ } ) ) ;
1666+
1667+ Promise . all ( promises ) . then ( ( ) => {
1668+ rp (
1669+ {
1670+ method : 'POST' ,
1671+ headers : headers ,
1672+ url : 'http://localhost:8378/1/import/TestObjectDad/RelationObject' ,
1673+ body : JSON . stringify ( {
1674+ results : [
1675+ {
1676+ "owningId" : "aaa" ,
1677+ "relatedId" : "bbb"
1678+ }
1679+ ]
1680+ } )
1681+ } ,
1682+ ( err ) => {
1683+ expect ( err ) . toBe ( null ) ;
1684+ let query = new Parse . Query ( 'TestObjectDad' ) ;
1685+ query . _where = { "RelationObject" :{ "__type" :"Pointer" , "className" :"TestObjectChild" , "objectId" :"bbb" } } ;
1686+ query . find ( ) . then ( ( results ) => {
1687+ expect ( results . length ) . toEqual ( 1 ) ;
1688+ expect ( results [ 0 ] . id ) . toEqual ( 'aaa' ) ;
1689+ done ( ) ;
1690+ } ) ;
1691+ }
1692+ )
1693+ } ) ;
1694+ } ) ;
14651695} ) ;
0 commit comments