MCPcopy Create free account
hub / github.com/Moosync/Moosync / test_analytics

Function test_analytics

src-tauri/database/src/test.rs:620–665  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

618// Test analytics operations
619#[test]
620fn test_analytics() {
621 let db_path = get_test_db_path();
622 let db = Database::new(db_path.clone());
623
624 // Insert a song
625 let songs = db
626 .insert_songs(vec![create_test_song(
627 "Analytics Test",
628 "/path/to/analytics.mp3",
629 )])
630 .unwrap();
631
632 let song_id = songs[0].song._id.clone().unwrap();
633
634 // Increment play count multiple times
635 for _ in 0..5 {
636 db.increment_play_count(song_id.clone()).unwrap();
637 }
638
639 // Add some play time
640 db.increment_play_time(song_id.clone(), 120.0).unwrap();
641 db.increment_play_time(song_id.clone(), 180.0).unwrap();
642
643 // Get top listened songs
644 let analytics = db.get_top_listened_songs().unwrap();
645
646 // Verify analytics contains songs
647 assert!(
648 !analytics.songs.is_empty(),
649 "Analytics should contain songs"
650 );
651
652 // Find our song in the analytics data
653 let song_analytics = analytics
654 .songs
655 .iter()
656 .find(|(song, _)| song.as_str() == song_id.as_str());
657
658 // Verify our song was found and has the expected play time
659 assert!(song_analytics.is_some(), "Song should be in analytics data");
660 if let Some((_, play_time)) = song_analytics {
661 assert!(*play_time > 0.0, "Play time should be recorded");
662 }
663
664 cleanup(&db_path);
665}

Callers

nothing calls this directly

Calls 7

get_test_db_pathFunction · 0.85
cleanupFunction · 0.85
cloneMethod · 0.80
insert_songsMethod · 0.80
increment_play_countMethod · 0.80
increment_play_timeMethod · 0.80

Tested by

no test coverage detected