@@ -586,6 +586,45 @@ class PipelineIntegrationTests: FSTIntegrationTestCase {
586
586
587
587
TestHelper . compare ( pipelineResult: snapshot. results. first!, expected: expectedResultsMap)
588
588
}
589
+
590
+
591
+ func testFailed( ) async throws {
592
+ let db = firestore ( )
593
+ let randomCol = collectionRef ( ) // Ensure a unique collection for the test
594
+
595
+ // Add a dummy document to the collection.
596
+ // A pipeline query with .select against an empty collection might not behave as expected.
597
+ try await randomCol. document ( " dummyDoc " ) . setData ( [ " field " : " value " ] )
598
+
599
+ let constantsFirst : [ Selectable ] = [
600
+ //Constant([1, 2, 3, 4, 5, 6, 7, 0] as [UInt8]).as("bytes"),
601
+ Constant ( [ 1 , 2 , 3 ] ) . as ( " arrayValue " ) , // Treated as an array of numbers
602
+ ]
603
+
604
+ // let constantsSecond: [Selectable] = [
605
+ // ArrayExpression([
606
+ // [11, 22, 33] as [UInt8]
607
+ // ]).as("array")
608
+ // ]
609
+
610
+ let expectedResultsMap : [ String : Sendable ? ] = [
611
+ // "bytes": [1, 2, 3, 4, 5, 6, 7, 0] as [UInt8],
612
+ // "array": [
613
+ // [11, 22, 33] as [UInt8]
614
+ // ],
615
+ " arrayValue " : [ 1 , 2 , 3 ]
616
+ ]
617
+
618
+ let pipeline = db. pipeline ( )
619
+ . collection ( randomCol. path)
620
+ . limit ( 1 )
621
+ . select (
622
+ constantsFirst
623
+ )
624
+ let snapshot = try await pipeline. execute ( )
625
+
626
+ TestHelper . compare ( pipelineResult: snapshot. results. first!, expected: expectedResultsMap)
627
+ }
589
628
590
629
func testAcceptsAndReturnsNil( ) async throws {
591
630
let db = firestore ( )
@@ -595,8 +634,6 @@ class PipelineIntegrationTests: FSTIntegrationTestCase {
595
634
// A pipeline query with .select against an empty collection might not behave as expected.
596
635
try await randomCol. document ( " dummyDoc " ) . setData ( [ " field " : " value " ] )
597
636
598
- let refDate = Date ( timeIntervalSince1970: 1_678_886_400 )
599
-
600
637
let constantsFirst : [ Selectable ] = [
601
638
Constant . nil. as ( " nil " ) ,
602
639
]
@@ -2595,4 +2632,117 @@ class PipelineIntegrationTests: FSTIntegrationTestCase {
2595
2632
XCTFail ( " No document retrieved for testSupportsTimestampConversions " )
2596
2633
}
2597
2634
}
2635
+
2636
+ func testSupportsTimestampMath( ) async throws {
2637
+ let db = firestore ( )
2638
+ let randomCol = collectionRef ( )
2639
+ try await randomCol. document ( " dummyDoc " ) . setData ( [ " field " : " value " ] )
2640
+
2641
+ let initialTimestamp = Timestamp ( seconds: 1_741_380_235 , nanoseconds: 0 )
2642
+
2643
+ let pipeline = db. pipeline ( )
2644
+ . collection ( randomCol. path)
2645
+ . limit ( 1 )
2646
+ . select (
2647
+ Constant ( initialTimestamp) . as ( " timestamp " )
2648
+ )
2649
+ . select (
2650
+ Field ( " timestamp " ) . timestampAdd ( . day, 10 ) . as ( " plus10days " ) ,
2651
+ Field ( " timestamp " ) . timestampAdd ( . hour, 10 ) . as ( " plus10hours " ) ,
2652
+ Field ( " timestamp " ) . timestampAdd ( . minute, 10 ) . as ( " plus10minutes " ) ,
2653
+ Field ( " timestamp " ) . timestampAdd ( . second, 10 ) . as ( " plus10seconds " ) ,
2654
+ Field ( " timestamp " ) . timestampAdd ( . microsecond, 10 ) . as ( " plus10micros " ) ,
2655
+ Field ( " timestamp " ) . timestampAdd ( . millisecond, 10 ) . as ( " plus10millis " ) ,
2656
+ Field ( " timestamp " ) . timestampSub ( . day, 10 ) . as ( " minus10days " ) ,
2657
+ Field ( " timestamp " ) . timestampSub ( . hour, 10 ) . as ( " minus10hours " ) ,
2658
+ Field ( " timestamp " ) . timestampSub ( . minute, 10 ) . as ( " minus10minutes " ) ,
2659
+ Field ( " timestamp " ) . timestampSub ( . second, 10 ) . as ( " minus10seconds " ) ,
2660
+ Field ( " timestamp " ) . timestampSub ( . microsecond, 10 ) . as ( " minus10micros " ) ,
2661
+ Field ( " timestamp " ) . timestampSub ( . millisecond, 10 ) . as ( " minus10millis " )
2662
+ )
2663
+
2664
+ let snapshot = try await pipeline. execute ( )
2665
+
2666
+ let expectedResults : [ String : Timestamp ] = [
2667
+ " plus10days " : Timestamp ( seconds: 1_742_244_235 , nanoseconds: 0 ) ,
2668
+ " plus10hours " : Timestamp ( seconds: 1_741_416_235 , nanoseconds: 0 ) ,
2669
+ " plus10minutes " : Timestamp ( seconds: 1_741_380_835 , nanoseconds: 0 ) ,
2670
+ " plus10seconds " : Timestamp ( seconds: 1_741_380_245 , nanoseconds: 0 ) ,
2671
+ " plus10micros " : Timestamp ( seconds: 1_741_380_235 , nanoseconds: 10_000 ) ,
2672
+ " plus10millis " : Timestamp ( seconds: 1_741_380_235 , nanoseconds: 10_000_000 ) ,
2673
+ " minus10days " : Timestamp ( seconds: 1_740_516_235 , nanoseconds: 0 ) ,
2674
+ " minus10hours " : Timestamp ( seconds: 1_741_344_235 , nanoseconds: 0 ) ,
2675
+ " minus10minutes " : Timestamp ( seconds: 1_741_379_635 , nanoseconds: 0 ) ,
2676
+ " minus10seconds " : Timestamp ( seconds: 1_741_380_225 , nanoseconds: 0 ) ,
2677
+ " minus10micros " : Timestamp ( seconds: 1_741_380_234 , nanoseconds: 999_990_000 ) ,
2678
+ " minus10millis " : Timestamp ( seconds: 1_741_380_234 , nanoseconds: 990_000_000 )
2679
+ ]
2680
+
2681
+ XCTAssertEqual ( snapshot. results. count, 1 , " Should retrieve one document " )
2682
+ if let resultDoc = snapshot. results. first {
2683
+ TestHelper . compare ( pipelineResult: resultDoc, expected: expectedResults)
2684
+ } else {
2685
+ XCTFail ( " No document retrieved for timestamp math test " )
2686
+ }
2687
+ }
2688
+
2689
+ func testSupportsByteLength( ) async throws {
2690
+ let db = firestore ( )
2691
+ let randomCol = collectionRef ( )
2692
+ try await randomCol. document ( " dummyDoc " ) . setData ( [ " field " : " value " ] )
2693
+
2694
+ let bytes : [ UInt8 ] = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 0 ]
2695
+
2696
+ let pipeline = db. pipeline ( )
2697
+ . collection ( randomCol. path)
2698
+ . limit ( 1 )
2699
+ . select (
2700
+ Constant ( bytes) . as ( " bytes " )
2701
+ )
2702
+ . select (
2703
+ Field ( " bytes " ) . byteLength ( ) . as ( " byteLength " )
2704
+ )
2705
+
2706
+ let snapshot = try await pipeline. execute ( )
2707
+
2708
+ let expectedResults : [ String : Sendable ] = [
2709
+ " byteLength " : 8
2710
+ ]
2711
+
2712
+ XCTAssertEqual ( snapshot. results. count, 1 , " Should retrieve one document " )
2713
+ if let resultDoc = snapshot. results. first {
2714
+ TestHelper . compare ( pipelineResult: resultDoc, expected: expectedResults. mapValues { $0 as Sendable } )
2715
+ } else {
2716
+ XCTFail ( " No document retrieved for byte length test " )
2717
+ }
2718
+ }
2719
+
2720
+ func testSupportsNot( ) async throws {
2721
+ let db = firestore ( )
2722
+ let randomCol = collectionRef ( )
2723
+ try await randomCol. document ( " dummyDoc " ) . setData ( [ " field " : " value " ] )
2724
+
2725
+ let pipeline = db. pipeline ( )
2726
+ . collection ( randomCol. path)
2727
+ . limit ( 1 )
2728
+ . select ( Constant ( true ) . as ( " trueField " ) )
2729
+ . select (
2730
+ Field ( " trueField " ) ,
2731
+ ( !( Field ( " trueField " ) . eq ( true ) ) ) . as ( " falseField " )
2732
+ )
2733
+
2734
+ let snapshot = try await pipeline. execute ( )
2735
+
2736
+ let expectedResults : [ String : Bool ] = [
2737
+ " trueField " : true ,
2738
+ " falseField " : false
2739
+ ]
2740
+
2741
+ XCTAssertEqual ( snapshot. results. count, 1 , " Should retrieve one document " )
2742
+ if let resultDoc = snapshot. results. first {
2743
+ TestHelper . compare ( pipelineResult: resultDoc, expected: expectedResults)
2744
+ } else {
2745
+ XCTFail ( " No document retrieved for not operator test " )
2746
+ }
2747
+ }
2598
2748
}
0 commit comments