@@ -470,7 +470,7 @@ - (void)testConditionBaseCaseDeserializationWithAndContainer {
470
470
@" value" : @" attributeValue" ,
471
471
@" type" : @" custom_attribute" };
472
472
NSArray *andConditionArray = @[@" and" , conditionInfo];
473
- NSArray *conditions = [OPTLYCondition deserializeJSONArray : andConditionArray];
473
+ NSArray *conditions = [OPTLYCondition deserializeJSON : andConditionArray];
474
474
XCTAssertNotNil (conditions);
475
475
XCTAssertTrue (conditions.count == 1 );
476
476
XCTAssertTrue ([conditions[0 ] isKindOfClass: [OPTLYAndCondition class ]]);
@@ -488,7 +488,7 @@ - (void)testConditionBaseCaseDeserializationWithOrContainer {
488
488
@" value" : @" attributeValue" ,
489
489
@" type" : @" custom_attribute" };
490
490
NSArray *andConditionArray = @[@" or" , conditionInfo];
491
- NSArray *conditions = [OPTLYCondition deserializeJSONArray : andConditionArray];
491
+ NSArray *conditions = [OPTLYCondition deserializeJSON : andConditionArray];
492
492
XCTAssertNotNil (conditions);
493
493
XCTAssertTrue (conditions.count == 1 );
494
494
XCTAssertTrue ([conditions[0 ] isKindOfClass: [OPTLYOrCondition class ]]);
@@ -501,11 +501,27 @@ - (void)testConditionBaseCaseDeserializationWithOrContainer {
501
501
XCTAssertEqualObjects (condition.type , @" custom_attribute" );
502
502
}
503
503
504
+ - (void )testConditionBaseCaseDeserializationWithLeafCondition {
505
+ NSDictionary *conditionInfo = @{@" name" : @" someAttributeKey" ,
506
+ @" value" : @" attributeValue" ,
507
+ @" type" : @" custom_attribute" };
508
+ NSArray *conditions = [OPTLYCondition deserializeJSON: conditionInfo];
509
+ XCTAssertNotNil (conditions);
510
+ XCTAssertTrue (conditions.count == 1 );
511
+ XCTAssertTrue ([conditions[0 ] isKindOfClass: [OPTLYOrCondition class ]]);
512
+ OPTLYAndCondition *andCondition = conditions[0 ];
513
+ XCTAssertTrue (andCondition.subConditions .count == 1 );
514
+ XCTAssertTrue ([andCondition.subConditions[0 ] isKindOfClass: [OPTLYBaseCondition class ]]);
515
+ OPTLYBaseCondition *condition = (OPTLYBaseCondition *)andCondition.subConditions [0 ];
516
+ XCTAssertEqualObjects (condition.name , @" someAttributeKey" );
517
+ XCTAssertEqualObjects (condition.value , @" attributeValue" );
518
+ XCTAssertEqualObjects (condition.type , @" custom_attribute" );
519
+ }
504
520
505
521
- (void )testDeserializeConditions {
506
522
NSString *conditionString = @" [\" and\" , [\" or\" , [\" or\" , {\" name\" : \" browser_type\" , \" type\" : \" custom_attribute\" , \" value\" : \" chrome\" }]]]" ;
507
523
NSArray *conditionStringJSONArray = [conditionString getValidConditionsArray ];
508
- NSArray *conditionsArray = [OPTLYCondition deserializeJSONArray : conditionStringJSONArray];
524
+ NSArray *conditionsArray = [OPTLYCondition deserializeJSON : conditionStringJSONArray];
509
525
XCTAssertNotNil (conditionsArray);
510
526
XCTAssertTrue ([conditionsArray[0 ] isKindOfClass: [OPTLYAndCondition class ]]);
511
527
OPTLYAndCondition *andCondition = conditionsArray[0 ];
@@ -527,21 +543,21 @@ - (void)testDeserializeConditionsNoValue {
527
543
NSString *conditionString = @" [\" and\" , [\" or\" , [\" or\" , {\" name\" : \" browser_type\" , \" invalid\" : \" custom_attribute\" }]]]" ;
528
544
NSArray *conditionStringJSONArray = [conditionString getValidConditionsArray ];
529
545
NSError *error = nil ;
530
- NSArray *conditionsArray = [OPTLYCondition deserializeJSONArray : conditionStringJSONArray error: &error];
546
+ NSArray *conditionsArray = [OPTLYCondition deserializeJSON : conditionStringJSONArray error: &error];
531
547
XCTAssertTrue (conditionsArray);
532
548
}
533
549
534
550
- (void )testDeserializeConditionsEmptyConditions {
535
551
NSString *conditionString = @" " ;
536
552
NSArray *conditionStringJSONArray = [conditionString getValidConditionsArray ];
537
553
NSError *error = nil ;
538
- NSArray *conditionsArray = [OPTLYCondition deserializeJSONArray : conditionStringJSONArray error: &error];
554
+ NSArray *conditionsArray = [OPTLYCondition deserializeJSON : conditionStringJSONArray error: &error];
539
555
XCTAssertNil (conditionsArray);
540
556
}
541
557
542
558
- (void )testDeserializeConditionsNilConditions {
543
559
NSError *error = nil ;
544
- NSArray *conditionsArray = [OPTLYCondition deserializeJSONArray :nil error: &error];
560
+ NSArray *conditionsArray = [OPTLYCondition deserializeJSON :nil error: &error];
545
561
XCTAssertNil (conditionsArray);
546
562
}
547
563
@@ -674,7 +690,7 @@ - (void)testShouldReturnOrOperatorWhenNoOperatorIsProvided {
674
690
NSString *noOperatorConditionString = @" [{\" name\" : \" browser_type\" , \" type\" : \" custom_attribute\" , \" value\" : \" android\" }]" ;
675
691
NSArray *conditionStringJSONArray = [noOperatorConditionString getValidConditionsArray ];
676
692
NSError *error = nil ;
677
- NSArray *conditionsArray = [OPTLYCondition deserializeJSONArray : conditionStringJSONArray error: &error];
693
+ NSArray *conditionsArray = [OPTLYCondition deserializeJSON : conditionStringJSONArray error: &error];
678
694
XCTAssertNotNil (conditionsArray);
679
695
XCTAssertTrue ([conditionsArray[0 ] isKindOfClass: [OPTLYOrCondition class ]]);
680
696
@@ -718,7 +734,7 @@ - (OPTLYBaseCondition *)mockBaseConditionAlwaysNull {
718
734
// /MARK:- Helper Methods
719
735
720
736
- (OPTLYCondition *)getFirstConditionFromArray : (NSArray *)array {
721
- NSArray *conditionArray = [OPTLYCondition deserializeJSONArray : array];
737
+ NSArray *conditionArray = [OPTLYCondition deserializeJSON : array];
722
738
return conditionArray[0 ];
723
739
}
724
740
0 commit comments