|
| 1 | +use serde::{Deserialize, Serialize}; |
| 2 | +use super::{Commit, Contributor}; |
| 3 | + |
| 4 | +#[derive(Debug, Clone, Serialize, Deserialize)] |
| 5 | +pub struct Report { |
| 6 | + pub repository: String, |
| 7 | + pub period: String, |
| 8 | + pub total_commits: u32, |
| 9 | + pub total_contributors: u32, |
| 10 | + pub total_insertions: u32, |
| 11 | + pub total_deletions: u32, |
| 12 | + pub commits: Vec<Commit>, |
| 13 | + pub contributors: Vec<Contributor>, |
| 14 | + pub generated_at: String, |
| 15 | +} |
| 16 | + |
| 17 | +impl Report { |
| 18 | + pub fn new(repository: String, period: String) -> Self { |
| 19 | + Self { |
| 20 | + repository, |
| 21 | + period, |
| 22 | + total_commits: 0, |
| 23 | + total_contributors: 0, |
| 24 | + total_insertions: 0, |
| 25 | + total_deletions: 0, |
| 26 | + commits: Vec::new(), |
| 27 | + contributors: Vec::new(), |
| 28 | + generated_at: chrono::Utc::now().to_rfc3339(), |
| 29 | + } |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +#[cfg(test)] |
| 34 | +mod tests { |
| 35 | + use super::*; |
| 36 | + |
| 37 | + #[test] |
| 38 | + fn test_report_creation() { |
| 39 | + let report = Report::new("test-repo".to_string(), "week".to_string()); |
| 40 | + assert_eq!(report.repository, "test-repo"); |
| 41 | + assert_eq!(report.period, "week"); |
| 42 | + assert_eq!(report.total_commits, 0); |
| 43 | + } |
| 44 | + |
| 45 | + #[test] |
| 46 | + fn test_contributor_creation() { |
| 47 | + let contributor = Contributor::new("Test User".to_string(), "test@example.com".to_string()); |
| 48 | + assert_eq!(contributor.name, "Test User"); |
| 49 | + assert_eq!(contributor.commits, 0); |
| 50 | + } |
| 51 | + |
| 52 | + #[test] |
| 53 | + fn test_commit_creation() { |
| 54 | + let commit = Commit::new( |
| 55 | + "abc123".to_string(), |
| 56 | + "Test commit".to_string(), |
| 57 | + "Test Author".to_string(), |
| 58 | + "2024-01-01".to_string(), |
| 59 | + ); |
| 60 | + assert_eq!(commit.id, "abc123"); |
| 61 | + assert_eq!(commit.message, "Test commit"); |
| 62 | + } |
| 63 | +} |
0 commit comments