@@ -406,4 +406,77 @@ mod tests {
406406 assert_eq ! ( s1. kv_key( ) , s2. kv_key( ) ) ;
407407 assert_eq ! ( s1. kv_key( ) , "gmail:conn_x" ) ;
408408 }
409+
410+ #[ test]
411+ fn sync_state_budget_exhausted_delegates ( ) {
412+ let mut state = SyncState :: new ( "test" , "conn" ) ;
413+ assert ! ( !state. budget_exhausted( ) ) ;
414+ state
415+ . daily_budget
416+ . record_requests ( DEFAULT_DAILY_REQUEST_LIMIT ) ;
417+ assert ! ( state. budget_exhausted( ) ) ;
418+ }
419+
420+ #[ test]
421+ fn sync_state_budget_remaining_delegates ( ) {
422+ let state = SyncState :: new ( "test" , "conn" ) ;
423+ assert_eq ! ( state. budget_remaining( ) , DEFAULT_DAILY_REQUEST_LIMIT ) ;
424+ }
425+
426+ #[ test]
427+ fn sync_state_record_requests_delegates ( ) {
428+ let mut state = SyncState :: new ( "test" , "conn" ) ;
429+ state. record_requests ( 5 ) ;
430+ assert_eq ! ( state. budget_remaining( ) , DEFAULT_DAILY_REQUEST_LIMIT - 5 ) ;
431+ }
432+
433+ #[ test]
434+ fn extract_item_id_skips_empty_strings ( ) {
435+ let item = serde_json:: json!( { "id" : " " , "fallback" : "ok" } ) ;
436+ assert_eq ! (
437+ extract_item_id( & item, & [ "id" , "fallback" ] ) ,
438+ Some ( "ok" . to_string( ) )
439+ ) ;
440+ }
441+
442+ #[ test]
443+ fn extract_item_id_deeply_nested ( ) {
444+ let item = serde_json:: json!( { "a" : { "b" : { "c" : "deep" } } } ) ;
445+ assert_eq ! ( extract_item_id( & item, & [ "a.b.c" ] ) , Some ( "deep" . to_string( ) ) ) ;
446+ }
447+
448+ #[ test]
449+ fn extract_item_id_returns_none_for_non_string_leaf ( ) {
450+ let item = serde_json:: json!( { "id" : 42 } ) ;
451+ assert_eq ! ( extract_item_id( & item, & [ "id" ] ) , None ) ;
452+ }
453+
454+ #[ test]
455+ fn extract_item_id_trims_whitespace ( ) {
456+ let item = serde_json:: json!( { "id" : " trimmed " } ) ;
457+ assert_eq ! ( extract_item_id( & item, & [ "id" ] ) , Some ( "trimmed" . to_string( ) ) ) ;
458+ }
459+
460+ #[ test]
461+ fn daily_budget_record_request_increments_by_one ( ) {
462+ let mut b = DailyBudget :: default ( ) ;
463+ b. record_request ( ) ;
464+ assert_eq ! ( b. requests_used, 1 ) ;
465+ b. record_request ( ) ;
466+ assert_eq ! ( b. requests_used, 2 ) ;
467+ }
468+
469+ #[ test]
470+ fn default_daily_request_limit_is_500 ( ) {
471+ assert_eq ! ( DEFAULT_DAILY_REQUEST_LIMIT , 500 ) ;
472+ }
473+
474+ #[ test]
475+ fn today_str_format ( ) {
476+ let today = today_str ( ) ;
477+ // Should be YYYY-MM-DD
478+ assert_eq ! ( today. len( ) , 10 ) ;
479+ assert_eq ! ( today. chars( ) . nth( 4 ) , Some ( '-' ) ) ;
480+ assert_eq ! ( today. chars( ) . nth( 7 ) , Some ( '-' ) ) ;
481+ }
409482}
0 commit comments