()
| 618 | // Test analytics operations |
| 619 | #[test] |
| 620 | fn 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 | } |
nothing calls this directly
no test coverage detected