@@ -845,7 +845,7 @@ mod tests {
845845 use hyper:: client:: HttpConnector ;
846846 use launchdarkly_server_sdk_evaluation:: Reason ;
847847 use std:: collections:: HashMap ;
848-
848+ use assert_json_diff :: assert_json_eq ;
849849 use tokio:: time:: Instant ;
850850
851851 use crate :: data_source:: MockDataSource ;
@@ -854,10 +854,7 @@ mod tests {
854854 use crate :: events:: event:: { OutputEvent , VariationKey } ;
855855 use crate :: events:: processor_builders:: EventProcessorBuilder ;
856856 use crate :: stores:: store_types:: { PatchTarget , StorageItem } ;
857- use crate :: test_common:: {
858- self , basic_flag, basic_flag_with_prereq, basic_int_flag, basic_migration_flag,
859- basic_off_flag,
860- } ;
857+ use crate :: test_common:: { self , basic_flag, basic_flag_with_prereq, basic_flag_with_prereqs_and_visibility, basic_int_flag, basic_migration_flag, basic_off_flag} ;
861858 use crate :: { ConfigBuilder , MigratorBuilder , Operation , Origin } ;
862859 use test_case:: test_case;
863860
@@ -965,6 +962,137 @@ mod tests {
965962 ) ) ;
966963 }
967964
965+ #[ test]
966+ fn all_flags_detail_is_invalid_when_offline ( ) {
967+ let ( client, _event_rx) = make_mocked_offline_client ( ) ;
968+ client. start_with_default_executor ( ) ;
969+
970+ let context = ContextBuilder :: new ( "bob" )
971+ . build ( )
972+ . expect ( "Failed to create context" ) ;
973+
974+ let all_flags = client. all_flags_detail ( & context, FlagDetailConfig :: new ( ) ) ;
975+ assert_json_eq ! ( all_flags, json!( { "$valid" : false , "$flagsState" : { } } ) ) ;
976+ }
977+
978+ #[ test]
979+ fn all_flags_detail_is_invalid_when_not_initialized ( ) {
980+ let ( client, _event_rx) = make_mocked_client ( ) ;
981+
982+ let context = ContextBuilder :: new ( "bob" )
983+ . build ( )
984+ . expect ( "Failed to create context" ) ;
985+
986+ let all_flags = client. all_flags_detail ( & context, FlagDetailConfig :: new ( ) ) ;
987+ assert_json_eq ! ( all_flags, json!( { "$valid" : false , "$flagsState" : { } } ) ) ;
988+ }
989+
990+
991+ #[ test]
992+ fn all_flags_detail_returns_flag_states ( ) {
993+ let ( client, _event_rx) = make_mocked_client ( ) ;
994+ client. start_with_default_executor ( ) ;
995+ client
996+ . data_store
997+ . write ( )
998+ . upsert (
999+ "myFlag1" ,
1000+ PatchTarget :: Flag ( StorageItem :: Item ( basic_flag ( "myFlag1" ) ) ) ,
1001+ )
1002+ . expect ( "patch should apply" ) ;
1003+ client
1004+ . data_store
1005+ . write ( )
1006+ . upsert (
1007+ "myFlag2" ,
1008+ PatchTarget :: Flag ( StorageItem :: Item ( basic_flag ( "myFlag2" ) ) ) ,
1009+ )
1010+ . expect ( "patch should apply" ) ;
1011+ let context = ContextBuilder :: new ( "bob" )
1012+ . build ( )
1013+ . expect ( "Failed to create context" ) ;
1014+
1015+ let all_flags = client. all_flags_detail ( & context, FlagDetailConfig :: new ( ) ) ;
1016+
1017+ client. close ( ) ;
1018+
1019+ assert_json_eq ! ( all_flags, json!( {
1020+ "myFlag1" : true ,
1021+ "myFlag2" : true ,
1022+ "$flagsState" : {
1023+ "myFlag1" : {
1024+ "version" : 42 ,
1025+ "variation" : 1
1026+ } ,
1027+ "myFlag2" : {
1028+ "version" : 42 ,
1029+ "variation" : 1
1030+ } ,
1031+ } ,
1032+ "$valid" : true
1033+ } ) ) ;
1034+ }
1035+
1036+
1037+ #[ test]
1038+ fn all_flags_detail_returns_prerequisite_relations ( ) {
1039+ let ( client, _event_rx) = make_mocked_client ( ) ;
1040+ client. start_with_default_executor ( ) ;
1041+ client
1042+ . data_store
1043+ . write ( )
1044+ . upsert (
1045+ "prereq1" ,
1046+ PatchTarget :: Flag ( StorageItem :: Item ( basic_flag ( "prereq1" ) ) ) ,
1047+ )
1048+ . expect ( "patch should apply" ) ;
1049+ client
1050+ . data_store
1051+ . write ( )
1052+ . upsert (
1053+ "prereq2" ,
1054+ PatchTarget :: Flag ( StorageItem :: Item ( basic_flag ( "prereq2" ) ) ) ,
1055+ )
1056+ . expect ( "patch should apply" ) ;
1057+
1058+ client. data_store
1059+ . write ( )
1060+ . upsert (
1061+ "toplevel" ,
1062+ PatchTarget :: Flag ( StorageItem :: Item ( basic_flag_with_prereqs_and_visibility ( "toplevel" , & [ "prereq1" , "prereq2" ] , false ) ) ) ,
1063+ )
1064+ . expect ( "patch should apply" ) ;
1065+
1066+ let context = ContextBuilder :: new ( "bob" )
1067+ . build ( )
1068+ . expect ( "Failed to create context" ) ;
1069+
1070+ let all_flags = client. all_flags_detail ( & context, FlagDetailConfig :: new ( ) ) ;
1071+
1072+ client. close ( ) ;
1073+
1074+ assert_json_eq ! ( all_flags, json!( {
1075+ "prereq1" : true ,
1076+ "prereq2" : true ,
1077+ "toplevel" : true ,
1078+ "$flagsState" : {
1079+ "toplevel" : {
1080+ "version" : 42 ,
1081+ "variation" : 1 ,
1082+ "prerequisites" : [ "prereq1" , "prereq2" ]
1083+ } ,
1084+ "prereq1" : {
1085+ "version" : 42 ,
1086+ "variation" : 1
1087+ } ,
1088+ "prereq2" : {
1089+ "version" : 42 ,
1090+ "variation" : 1
1091+ } ,
1092+ } ,
1093+ "$valid" : true
1094+ } ) ) ;
1095+ }
9681096 #[ test]
9691097 fn variation_tracks_events_correctly ( ) {
9701098 let ( client, event_rx) = make_mocked_client ( ) ;
0 commit comments