@@ -469,7 +469,177 @@ class ProviderTests: XCTestCase {
469
469
XCTAssertEqual ( details2. variant, " variantB " )
470
470
}
471
471
472
- /*
473
- should test all types
474
- */
472
+ func testShouldReturnAValidEvaluationForBool( ) async {
473
+ let mockService = MockNetworkingService ( mockStatus: 200 )
474
+ let options = GoFeatureFlagProviderOptions (
475
+ endpoint: " http://localhost:1031/ " ,
476
+ networkService: mockService
477
+ )
478
+ let provider = GoFeatureFlagProvider ( options: options)
479
+
480
+ let api = OpenFeatureAPI ( )
481
+ await api. setProviderAndWait ( provider: provider, initialContext: defaultEvaluationContext)
482
+ let expectation = XCTestExpectation ( description: " waiting 1st event " )
483
+ _ = api. observe ( ) . sink { event in
484
+ if ( event != ProviderEvent . ready) {
485
+ XCTFail ( " If OFREP API returns a 200 we should receive a ready event, received: \( event) " )
486
+ }
487
+ expectation. fulfill ( )
488
+ }
489
+ await fulfillment ( of: [ expectation] , timeout: 3 )
490
+
491
+ let client = api. getClient ( )
492
+ let details = client. getBooleanDetails ( key: " bool-flag " , defaultValue: false )
493
+ XCTAssertEqual ( details. errorCode, nil )
494
+ XCTAssertEqual ( details. errorMessage, nil )
495
+ XCTAssertEqual ( details. value, true )
496
+ XCTAssertEqual ( details. flagKey, " bool-flag " )
497
+ XCTAssertEqual ( details. reason, " TARGETING_MATCH " )
498
+ XCTAssertEqual ( details. variant, " variantA " )
499
+ }
500
+
501
+ func testShouldReturnAValidEvaluationForInt( ) async {
502
+ let mockService = MockNetworkingService ( mockStatus: 200 )
503
+ let options = GoFeatureFlagProviderOptions (
504
+ endpoint: " http://localhost:1031/ " ,
505
+ networkService: mockService
506
+ )
507
+ let provider = GoFeatureFlagProvider ( options: options)
508
+
509
+ let api = OpenFeatureAPI ( )
510
+ await api. setProviderAndWait ( provider: provider, initialContext: defaultEvaluationContext)
511
+ let expectation = XCTestExpectation ( description: " waiting 1st event " )
512
+ _ = api. observe ( ) . sink { event in
513
+ if ( event != ProviderEvent . ready) {
514
+ XCTFail ( " If OFREP API returns a 200 we should receive a ready event, received: \( event) " )
515
+ }
516
+ expectation. fulfill ( )
517
+ }
518
+ await fulfillment ( of: [ expectation] , timeout: 3 )
519
+
520
+ let client = api. getClient ( )
521
+ let details = client. getIntegerDetails ( key: " int-flag " , defaultValue: 1 )
522
+ XCTAssertEqual ( details. errorCode, nil )
523
+ XCTAssertEqual ( details. errorMessage, nil )
524
+ XCTAssertEqual ( details. value, 1234 )
525
+ XCTAssertEqual ( details. flagKey, " int-flag " )
526
+ XCTAssertEqual ( details. reason, " TARGETING_MATCH " )
527
+ XCTAssertEqual ( details. variant, " variantA " )
528
+ }
529
+
530
+ func testShouldReturnAValidEvaluationForDouble( ) async {
531
+ let mockService = MockNetworkingService ( mockStatus: 200 )
532
+ let options = GoFeatureFlagProviderOptions (
533
+ endpoint: " http://localhost:1031/ " ,
534
+ networkService: mockService
535
+ )
536
+ let provider = GoFeatureFlagProvider ( options: options)
537
+
538
+ let api = OpenFeatureAPI ( )
539
+ await api. setProviderAndWait ( provider: provider, initialContext: defaultEvaluationContext)
540
+ let expectation = XCTestExpectation ( description: " waiting 1st event " )
541
+ _ = api. observe ( ) . sink { event in
542
+ if ( event != ProviderEvent . ready) {
543
+ XCTFail ( " If OFREP API returns a 200 we should receive a ready event, received: \( event) " )
544
+ }
545
+ expectation. fulfill ( )
546
+ }
547
+ await fulfillment ( of: [ expectation] , timeout: 3 )
548
+
549
+ let client = api. getClient ( )
550
+ let details = client. getDoubleDetails ( key: " double-flag " , defaultValue: 1.1 )
551
+ XCTAssertEqual ( details. errorCode, nil )
552
+ XCTAssertEqual ( details. errorMessage, nil )
553
+ XCTAssertEqual ( details. value, 12.34 )
554
+ XCTAssertEqual ( details. flagKey, " double-flag " )
555
+ XCTAssertEqual ( details. reason, " TARGETING_MATCH " )
556
+ XCTAssertEqual ( details. variant, " variantA " )
557
+ }
558
+
559
+ func testShouldReturnAValidEvaluationForString( ) async {
560
+ let mockService = MockNetworkingService ( mockStatus: 200 )
561
+ let options = GoFeatureFlagProviderOptions (
562
+ endpoint: " http://localhost:1031/ " ,
563
+ networkService: mockService
564
+ )
565
+ let provider = GoFeatureFlagProvider ( options: options)
566
+
567
+ let api = OpenFeatureAPI ( )
568
+ await api. setProviderAndWait ( provider: provider, initialContext: defaultEvaluationContext)
569
+ let expectation = XCTestExpectation ( description: " waiting 1st event " )
570
+ _ = api. observe ( ) . sink { event in
571
+ if ( event != ProviderEvent . ready) {
572
+ XCTFail ( " If OFREP API returns a 200 we should receive a ready event, received: \( event) " )
573
+ }
574
+ expectation. fulfill ( )
575
+ }
576
+ await fulfillment ( of: [ expectation] , timeout: 3 )
577
+
578
+ let client = api. getClient ( )
579
+ let details = client. getStringDetails ( key: " string-flag " , defaultValue: " 1 " )
580
+ XCTAssertEqual ( details. errorCode, nil )
581
+ XCTAssertEqual ( details. errorMessage, nil )
582
+ XCTAssertEqual ( details. value, " 1234value " )
583
+ XCTAssertEqual ( details. flagKey, " string-flag " )
584
+ XCTAssertEqual ( details. reason, " TARGETING_MATCH " )
585
+ XCTAssertEqual ( details. variant, " variantA " )
586
+ }
587
+
588
+ func testShouldReturnAValidEvaluationForArray( ) async {
589
+ let mockService = MockNetworkingService ( mockStatus: 200 )
590
+ let options = GoFeatureFlagProviderOptions (
591
+ endpoint: " http://localhost:1031/ " ,
592
+ networkService: mockService
593
+ )
594
+ let provider = GoFeatureFlagProvider ( options: options)
595
+
596
+ let api = OpenFeatureAPI ( )
597
+ await api. setProviderAndWait ( provider: provider, initialContext: defaultEvaluationContext)
598
+ let expectation = XCTestExpectation ( description: " waiting 1st event " )
599
+ _ = api. observe ( ) . sink { event in
600
+ if ( event != ProviderEvent . ready) {
601
+ XCTFail ( " If OFREP API returns a 200 we should receive a ready event, received: \( event) " )
602
+ }
603
+ expectation. fulfill ( )
604
+ }
605
+ await fulfillment ( of: [ expectation] , timeout: 3 )
606
+
607
+ let client = api. getClient ( )
608
+ let details = client. getObjectDetails ( key: " array-flag " , defaultValue: Value . list ( [ Value . string ( " 1 " ) ] ) )
609
+ XCTAssertEqual ( details. errorCode, nil )
610
+ XCTAssertEqual ( details. errorMessage, nil )
611
+ XCTAssertEqual ( details. value, Value . list ( [ Value . integer ( 1234 ) , Value . integer ( 5678 ) ] ) )
612
+ XCTAssertEqual ( details. flagKey, " array-flag " )
613
+ XCTAssertEqual ( details. reason, " TARGETING_MATCH " )
614
+ XCTAssertEqual ( details. variant, " variantA " )
615
+ }
616
+
617
+ func testShouldReturnAValidEvaluationForObject( ) async {
618
+ let mockService = MockNetworkingService ( mockStatus: 200 )
619
+ let options = GoFeatureFlagProviderOptions (
620
+ endpoint: " http://localhost:1031/ " ,
621
+ networkService: mockService
622
+ )
623
+ let provider = GoFeatureFlagProvider ( options: options)
624
+
625
+ let api = OpenFeatureAPI ( )
626
+ await api. setProviderAndWait ( provider: provider, initialContext: defaultEvaluationContext)
627
+ let expectation = XCTestExpectation ( description: " waiting 1st event " )
628
+ _ = api. observe ( ) . sink { event in
629
+ if ( event != ProviderEvent . ready) {
630
+ XCTFail ( " If OFREP API returns a 200 we should receive a ready event, received: \( event) " )
631
+ }
632
+ expectation. fulfill ( )
633
+ }
634
+ await fulfillment ( of: [ expectation] , timeout: 3 )
635
+
636
+ let client = api. getClient ( )
637
+ let details = client. getObjectDetails ( key: " object-flag " , defaultValue: Value . list ( [ Value . string ( " 1 " ) ] ) )
638
+ XCTAssertEqual ( details. errorCode, nil )
639
+ XCTAssertEqual ( details. errorMessage, nil )
640
+ XCTAssertEqual ( details. value, Value . structure ( [ " testValue " : Value . structure ( [ " toto " : Value . integer ( 1234 ) ] ) ] ) )
641
+ XCTAssertEqual ( details. flagKey, " object-flag " )
642
+ XCTAssertEqual ( details. reason, " TARGETING_MATCH " )
643
+ XCTAssertEqual ( details. variant, " variantA " )
644
+ }
475
645
}
0 commit comments