@@ -236,7 +236,10 @@ fn movie_is_manual_match_different_director_fails() {
|
||||
#[test]
|
||||
fn profile_fields_validates_max_count() {
|
||||
let fields: Vec<ProfileField> = (0..5)
|
||||
.map(|i| ProfileField { name: format!("f{i}"), value: format!("v{i}") })
|
||||
.map(|i| ProfileField {
|
||||
name: format!("f{i}"),
|
||||
value: format!("v{i}"),
|
||||
})
|
||||
.collect();
|
||||
assert!(UserProfile::validate_custom_fields(&fields).is_err());
|
||||
}
|
||||
@@ -244,7 +247,10 @@ fn profile_fields_validates_max_count() {
|
||||
#[test]
|
||||
fn profile_fields_allows_four() {
|
||||
let fields: Vec<ProfileField> = (0..4)
|
||||
.map(|i| ProfileField { name: format!("f{i}"), value: format!("v{i}") })
|
||||
.map(|i| ProfileField {
|
||||
name: format!("f{i}"),
|
||||
value: format!("v{i}"),
|
||||
})
|
||||
.collect();
|
||||
assert!(UserProfile::validate_custom_fields(&fields).is_ok());
|
||||
}
|
||||
|
||||
@@ -35,7 +35,9 @@ pub struct UserProfile {
|
||||
impl UserProfile {
|
||||
pub const MAX_CUSTOM_FIELDS: usize = 4;
|
||||
|
||||
pub fn validate_custom_fields(fields: &[ProfileField]) -> Result<(), crate::errors::DomainError> {
|
||||
pub fn validate_custom_fields(
|
||||
fields: &[ProfileField],
|
||||
) -> Result<(), crate::errors::DomainError> {
|
||||
if fields.len() > Self::MAX_CUSTOM_FIELDS {
|
||||
Err(crate::errors::DomainError::ValidationError(
|
||||
"Maximum 4 profile fields allowed".into(),
|
||||
|
||||
@@ -63,7 +63,11 @@ fn avg_rating_is_correct() {
|
||||
|
||||
#[test]
|
||||
fn rating_distribution_counts_correctly() {
|
||||
let rows = vec![row("A", 5, "2024-01"), row("B", 5, "2024-02"), row("C", 3, "2024-03")];
|
||||
let rows = vec![
|
||||
row("A", 5, "2024-01"),
|
||||
row("B", 5, "2024-02"),
|
||||
row("C", 3, "2024-03"),
|
||||
];
|
||||
let report = build_report(WrapUpScope::Global, range(), &rows);
|
||||
assert_eq!(report.rating_distribution[4], 2);
|
||||
assert_eq!(report.rating_distribution[2], 1);
|
||||
@@ -71,9 +75,17 @@ fn rating_distribution_counts_correctly() {
|
||||
|
||||
#[test]
|
||||
fn movies_per_month_sorted_chronologically() {
|
||||
let rows = vec![row("A", 3, "2024-03"), row("B", 3, "2024-01"), row("C", 3, "2024-02")];
|
||||
let rows = vec![
|
||||
row("A", 3, "2024-03"),
|
||||
row("B", 3, "2024-01"),
|
||||
row("C", 3, "2024-02"),
|
||||
];
|
||||
let report = build_report(WrapUpScope::Global, range(), &rows);
|
||||
let yms: Vec<&str> = report.movies_per_month.iter().map(|m| m.year_month.as_str()).collect();
|
||||
let yms: Vec<&str> = report
|
||||
.movies_per_month
|
||||
.iter()
|
||||
.map(|m| m.year_month.as_str())
|
||||
.collect();
|
||||
assert_eq!(yms, ["2024-01", "2024-02", "2024-03"]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user