@@ -1517,14 +1517,24 @@ describe('FirestorePipeline', function () {
15171517 constant,
15181518 array,
15191519 arrayLength,
1520- arrayFirst,
1521- arrayFirstN,
15221520 arrayGet,
15231521 arrayConcat,
15241522 arrayFilter,
1523+ arrayFirst,
1524+ arrayFirstN,
1525+ arrayIndexOf,
1526+ arrayIndexOfAll,
1527+ arrayLastIndexOf,
1528+ arrayMaximum,
1529+ arrayMaximumN,
1530+ arrayMinimumN,
1531+ arraySlice,
1532+ arrayTransform,
1533+ arrayTransformWithIndex,
15251534 arraySum,
15261535 variable,
15271536 and,
1537+ add,
15281538 greaterThan,
15291539 arrayContains,
15301540 arrayContainsAny,
@@ -1540,7 +1550,7 @@ describe('FirestorePipeline', function () {
15401550 permissions : [ 'read' , 'write' ] ,
15411551 primaryTags : [ 'a' , 'b' ] ,
15421552 secondaryTags : [ 'c' , 'd' ] ,
1543- scores : [ 10 , 20 , 30 ] ,
1553+ scores : [ 10 , 20 , 30 , 20 ] ,
15441554 items : [ 'x' , 'y' , 'z' ] ,
15451555 } ) ,
15461556 setDoc ( doc ( coll , 'p2' ) , {
@@ -1573,15 +1583,35 @@ describe('FirestorePipeline', function () {
15731583 arrayFilter ( field ( 'scores' ) , 'score' , greaterThan ( variable ( 'score' ) , 15 ) ) . as (
15741584 'filteredItems' ,
15751585 ) ,
1586+ arrayFirst ( 'scores' ) . as ( 'firstScore' ) ,
1587+ arrayFirstN ( 'scores' , 2 ) . as ( 'firstTwoScores' ) ,
1588+ field ( 'scores' ) . arrayLast ( ) . as ( 'lastScore' ) ,
1589+ field ( 'scores' ) . arrayLastN ( 2 ) . as ( 'lastTwoScores' ) ,
1590+ arraySlice ( 'scores' , 1 , 2 ) . as ( 'middleScores' ) ,
1591+ arrayTransform ( 'scores' , 'score' , add ( variable ( 'score' ) , 1 ) ) . as ( 'incrementedScores' ) ,
1592+ arrayTransformWithIndex (
1593+ 'scores' ,
1594+ 'score' ,
1595+ 'index' ,
1596+ add ( variable ( 'score' ) , variable ( 'index' ) ) ,
1597+ ) . as ( 'indexedScores' ) ,
1598+ arrayMaximum ( 'scores' ) . as ( 'maxScore' ) ,
1599+ arrayMaximumN ( 'scores' , 2 ) . as ( 'topTwoScores' ) ,
1600+ field ( 'scores' ) . arrayMinimum ( ) . as ( 'minScore' ) ,
1601+ arrayMinimumN ( 'scores' , 2 ) . as ( 'bottomTwoScores' ) ,
1602+ arrayIndexOf ( 'scores' , 20 ) . as ( 'firstTwentyIndex' ) ,
1603+ field ( 'scores' ) . arrayIndexOf ( 20 ) . as ( 'fluentFirstTwentyIndex' ) ,
1604+ arrayLastIndexOf ( 'scores' , 20 ) . as ( 'lastTwentyIndex' ) ,
1605+ field ( 'scores' ) . arrayLastIndexOf ( 20 ) . as ( 'fluentLastTwentyIndex' ) ,
1606+ arrayIndexOfAll ( 'scores' , 20 ) . as ( 'allTwentyIndexes' ) ,
15761607 arraySum ( field ( 'scores' ) ) . as ( 'totalScore' ) ,
15771608 ) ;
15781609
15791610 if ( Platform . ios ) {
1580- await expectIOSUnsupportedFunctions ( ( ) => execute ( pipeline ) , [
1581- 'arrayFirst' ,
1582- 'arrayFirstN' ,
1583- 'arrayGet' ,
1584- ] ) ;
1611+ await expectIOSUnsupportedFunctions (
1612+ ( ) => execute ( pipeline ) ,
1613+ [ 'arrayFirst' , 'arrayFirstN' , 'arrayGet' ] ,
1614+ ) ;
15851615
15861616 const iosSnapshot = await execute (
15871617 db
@@ -1601,6 +1631,29 @@ describe('FirestorePipeline', function () {
16011631 arrayFilter ( 'scores' , 'score' , greaterThan ( variable ( 'score' ) , 15 ) ) . as (
16021632 'filteredItems' ,
16031633 ) ,
1634+ arrayFirst ( 'scores' ) . as ( 'firstScore' ) ,
1635+ arrayFirstN ( 'scores' , 2 ) . as ( 'firstTwoScores' ) ,
1636+ field ( 'scores' ) . arrayLast ( ) . as ( 'lastScore' ) ,
1637+ field ( 'scores' ) . arrayLastN ( 2 ) . as ( 'lastTwoScores' ) ,
1638+ arraySlice ( 'scores' , 1 , 2 ) . as ( 'middleScores' ) ,
1639+ arrayTransform ( 'scores' , 'score' , add ( variable ( 'score' ) , 1 ) ) . as (
1640+ 'incrementedScores' ,
1641+ ) ,
1642+ arrayTransformWithIndex (
1643+ 'scores' ,
1644+ 'score' ,
1645+ 'index' ,
1646+ add ( variable ( 'score' ) , variable ( 'index' ) ) ,
1647+ ) . as ( 'indexedScores' ) ,
1648+ arrayMaximum ( 'scores' ) . as ( 'maxScore' ) ,
1649+ arrayMaximumN ( 'scores' , 2 ) . as ( 'topTwoScores' ) ,
1650+ field ( 'scores' ) . arrayMinimum ( ) . as ( 'minScore' ) ,
1651+ arrayMinimumN ( 'scores' , 2 ) . as ( 'bottomTwoScores' ) ,
1652+ arrayIndexOf ( 'scores' , 20 ) . as ( 'firstTwentyIndex' ) ,
1653+ field ( 'scores' ) . arrayIndexOf ( 20 ) . as ( 'fluentFirstTwentyIndex' ) ,
1654+ arrayLastIndexOf ( 'scores' , 20 ) . as ( 'lastTwentyIndex' ) ,
1655+ field ( 'scores' ) . arrayLastIndexOf ( 20 ) . as ( 'fluentLastTwentyIndex' ) ,
1656+ arrayIndexOfAll ( 'scores' , 20 ) . as ( 'allTwentyIndexes' ) ,
16041657 arraySum ( field ( 'scores' ) ) . as ( 'totalScore' ) ,
16051658 ) ,
16061659 ) ;
@@ -1610,8 +1663,24 @@ describe('FirestorePipeline', function () {
16101663 iosData . fixedArr . should . eql ( [ 1 , 2 , 3 ] ) ;
16111664 iosData . tagCount . should . equal ( 2 ) ;
16121665 iosData . allTags . should . eql ( [ 'a' , 'b' , 'c' , 'd' ] ) ;
1613- iosData . filteredItems . should . eql ( [ 20 , 30 ] ) ;
1614- iosData . totalScore . should . equal ( 60 ) ;
1666+ iosData . filteredItems . should . eql ( [ 20 , 30 , 20 ] ) ;
1667+ iosData . firstScore . should . equal ( 10 ) ;
1668+ iosData . firstTwoScores . should . eql ( [ 10 , 20 ] ) ;
1669+ iosData . lastScore . should . equal ( 20 ) ;
1670+ iosData . lastTwoScores . should . eql ( [ 30 , 20 ] ) ;
1671+ iosData . middleScores . should . eql ( [ 20 , 30 ] ) ;
1672+ iosData . incrementedScores . should . eql ( [ 11 , 21 , 31 , 21 ] ) ;
1673+ iosData . indexedScores . should . eql ( [ 10 , 21 , 32 , 23 ] ) ;
1674+ iosData . maxScore . should . equal ( 30 ) ;
1675+ [ ...iosData . topTwoScores ] . sort ( ( a , b ) => a - b ) . should . eql ( [ 20 , 30 ] ) ;
1676+ iosData . minScore . should . equal ( 10 ) ;
1677+ [ ...iosData . bottomTwoScores ] . sort ( ( a , b ) => a - b ) . should . eql ( [ 10 , 20 ] ) ;
1678+ iosData . firstTwentyIndex . should . equal ( 1 ) ;
1679+ iosData . fluentFirstTwentyIndex . should . equal ( 1 ) ;
1680+ iosData . lastTwentyIndex . should . equal ( 3 ) ;
1681+ iosData . fluentLastTwentyIndex . should . equal ( 3 ) ;
1682+ iosData . allTwentyIndexes . should . eql ( [ 1 , 3 ] ) ;
1683+ iosData . totalScore . should . equal ( 80 ) ;
16151684 return ;
16161685 }
16171686
@@ -1625,8 +1694,24 @@ describe('FirestorePipeline', function () {
16251694 data . firstTwoItems . should . eql ( [ 'x' , 'y' ] ) ;
16261695 data . firstItem . should . equal ( 'x' ) ;
16271696 data . allTags . should . eql ( [ 'a' , 'b' , 'c' , 'd' ] ) ;
1628- data . filteredItems . should . eql ( [ 20 , 30 ] ) ;
1629- data . totalScore . should . equal ( 60 ) ;
1697+ data . filteredItems . should . eql ( [ 20 , 30 , 20 ] ) ;
1698+ data . firstScore . should . equal ( 10 ) ;
1699+ data . firstTwoScores . should . eql ( [ 10 , 20 ] ) ;
1700+ data . lastScore . should . equal ( 20 ) ;
1701+ data . lastTwoScores . should . eql ( [ 30 , 20 ] ) ;
1702+ data . middleScores . should . eql ( [ 20 , 30 ] ) ;
1703+ data . incrementedScores . should . eql ( [ 11 , 21 , 31 , 21 ] ) ;
1704+ data . indexedScores . should . eql ( [ 10 , 21 , 32 , 23 ] ) ;
1705+ data . maxScore . should . equal ( 30 ) ;
1706+ [ ...data . topTwoScores ] . sort ( ( a , b ) => a - b ) . should . eql ( [ 20 , 30 ] ) ;
1707+ data . minScore . should . equal ( 10 ) ;
1708+ [ ...data . bottomTwoScores ] . sort ( ( a , b ) => a - b ) . should . eql ( [ 10 , 20 ] ) ;
1709+ data . firstTwentyIndex . should . equal ( 1 ) ;
1710+ data . fluentFirstTwentyIndex . should . equal ( 1 ) ;
1711+ data . lastTwentyIndex . should . equal ( 3 ) ;
1712+ data . fluentLastTwentyIndex . should . equal ( 3 ) ;
1713+ data . allTwentyIndexes . should . eql ( [ 1 , 3 ] ) ;
1714+ data . totalScore . should . equal ( 80 ) ;
16301715 } ) ;
16311716 } ) ;
16321717
0 commit comments