@@ -103,6 +103,40 @@ describe("createReplaneClient", () => {
103103 expect ( ( ) => client . get ( "nonexistent" ) ) . toThrow ( "Config not found: nonexistent" ) ;
104104 } ) ;
105105
106+ it ( "should return default value when config not found and default is provided" , async ( ) => {
107+ clientPromise = createClient ( ) ;
108+ const connection = await mockServer . acceptConnection ( ) ;
109+ await connection . push ( {
110+ type : "init" ,
111+ configs : [ { name : "config1" , overrides : [ ] , value : "value1" } ] ,
112+ } ) ;
113+
114+ const client = await clientPromise ;
115+ await sync ( ) ;
116+
117+ expect ( client . get ( "nonexistent" , { default : "fallback" } ) ) . toBe ( "fallback" ) ;
118+ expect ( client . get ( "nonexistent" , { default : 42 } ) ) . toBe ( 42 ) ;
119+ expect ( client . get ( "nonexistent" , { default : null } ) ) . toBe ( null ) ;
120+ expect ( client . get ( "nonexistent" , { default : false } ) ) . toBe ( false ) ;
121+ expect ( client . get ( "nonexistent" , { default : { nested : "value" } } ) ) . toEqual ( {
122+ nested : "value" ,
123+ } ) ;
124+ } ) ;
125+
126+ it ( "should return actual value when config exists even if default is provided" , async ( ) => {
127+ clientPromise = createClient ( ) ;
128+ const connection = await mockServer . acceptConnection ( ) ;
129+ await connection . push ( {
130+ type : "init" ,
131+ configs : [ { name : "config1" , overrides : [ ] , value : "actual" } ] ,
132+ } ) ;
133+
134+ const client = await clientPromise ;
135+ await sync ( ) ;
136+
137+ expect ( client . get ( "config1" , { default : "fallback" } ) ) . toBe ( "actual" ) ;
138+ } ) ;
139+
106140 it ( "should handle config values of different types" , async ( ) => {
107141 clientPromise = createClient ( ) ;
108142 const connection = await mockServer . acceptConnection ( ) ;
@@ -1900,6 +1934,28 @@ describe("createInMemoryReplaneClient", () => {
19001934 expect ( ( ) => client . get ( "nonexistent" as never ) ) . toThrow ( "Config not found: nonexistent" ) ;
19011935 } ) ;
19021936
1937+ it ( "should return default value when config not found and default is provided" , ( ) => {
1938+ const client = createInMemoryReplaneClient ( {
1939+ config1 : "value1" ,
1940+ } ) ;
1941+
1942+ expect ( client . get ( "nonexistent" as never , { default : "fallback" as never } ) ) . toBe ( "fallback" ) ;
1943+ expect ( client . get ( "nonexistent" as never , { default : 42 as never } ) ) . toBe ( 42 ) ;
1944+ expect ( client . get ( "nonexistent" as never , { default : null as never } ) ) . toBe ( null ) ;
1945+ expect ( client . get ( "nonexistent" as never , { default : false as never } ) ) . toBe ( false ) ;
1946+ expect ( client . get ( "nonexistent" as never , { default : { nested : "value" } as never } ) ) . toEqual ( {
1947+ nested : "value" ,
1948+ } ) ;
1949+ } ) ;
1950+
1951+ it ( "should return actual value when config exists even if default is provided" , ( ) => {
1952+ const client = createInMemoryReplaneClient ( {
1953+ config1 : "actual" ,
1954+ } ) ;
1955+
1956+ expect ( client . get ( "config1" , { default : "fallback" } ) ) . toBe ( "actual" ) ;
1957+ } ) ;
1958+
19031959 it ( "should handle complex values" , ( ) => {
19041960 const client = createInMemoryReplaneClient ( {
19051961 array : [ 1 , 2 , 3 ] ,
@@ -2007,6 +2063,32 @@ describe("restoreReplaneClient", () => {
20072063 expect ( ( ) => client . get ( "nonexistent" ) ) . toThrow ( "Config not found: nonexistent" ) ;
20082064 } ) ;
20092065
2066+ it ( "should return default value when config not found and default is provided" , ( ) => {
2067+ const snapshot : ReplaneSnapshot < Record < string , unknown > > = {
2068+ configs : [ { name : "config1" , value : "value1" , overrides : [ ] } ] ,
2069+ } ;
2070+
2071+ const client = restoreReplaneClient ( { snapshot } ) ;
2072+
2073+ expect ( client . get ( "nonexistent" , { default : "fallback" } ) ) . toBe ( "fallback" ) ;
2074+ expect ( client . get ( "nonexistent" , { default : 42 } ) ) . toBe ( 42 ) ;
2075+ expect ( client . get ( "nonexistent" , { default : null } ) ) . toBe ( null ) ;
2076+ expect ( client . get ( "nonexistent" , { default : false } ) ) . toBe ( false ) ;
2077+ expect ( client . get ( "nonexistent" , { default : { nested : "value" } } ) ) . toEqual ( {
2078+ nested : "value" ,
2079+ } ) ;
2080+ } ) ;
2081+
2082+ it ( "should return actual value when config exists even if default is provided" , ( ) => {
2083+ const snapshot : ReplaneSnapshot < Record < string , unknown > > = {
2084+ configs : [ { name : "config1" , value : "actual" , overrides : [ ] } ] ,
2085+ } ;
2086+
2087+ const client = restoreReplaneClient ( { snapshot } ) ;
2088+
2089+ expect ( client . get ( "config1" , { default : "fallback" } ) ) . toBe ( "actual" ) ;
2090+ } ) ;
2091+
20102092 it ( "should have a no-op close method" , ( ) => {
20112093 const snapshot : ReplaneSnapshot < Record < string , unknown > > = {
20122094 configs : [ { name : "config1" , value : "value1" , overrides : [ ] } ] ,
@@ -2230,7 +2312,9 @@ describe("restoreReplaneClient", () => {
22302312 overrides : [
22312313 {
22322314 name : "non-na-override" ,
2233- conditions : [ { operator : "not_in" , property : "country" , value : [ "US" , "CA" , "MX" ] } ] ,
2315+ conditions : [
2316+ { operator : "not_in" , property : "country" , value : [ "US" , "CA" , "MX" ] } ,
2317+ ] ,
22342318 value : "non-na-value" ,
22352319 } ,
22362320 ] ,
0 commit comments