Skip to content

Commit

Permalink
Renamed differences errorcodes to more understandable codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lionqueen94 committed Jul 23, 2024
1 parent cf4c75c commit ed1c100
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
4 changes: 2 additions & 2 deletions backend/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,8 @@
"IncorrectCandidatesList",
"MissingRecounts",
"IncorrectDifference",
"WrongDifferences",
"NoDifference"
"ConflictingDifferences",
"NoDifferenceExpected"
]
},
"ValidationResults": {
Expand Down
20 changes: 10 additions & 10 deletions backend/src/polling_station/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl Validate for PollingStationResults {
format!("{field_name}.more_ballots_count"),
format!("{field_name}.fewer_ballots_count"),
],
code: ValidationResultCode::WrongDifferences,
code: ValidationResultCode::ConflictingDifferences,
});
}

Expand All @@ -175,13 +175,13 @@ impl Validate for PollingStationResults {
if self.differences_counts.more_ballots_count != 0 {
validation_results.warnings.push(ValidationResult {
fields: vec![format!("{field_name}.more_ballots_count")],
code: ValidationResultCode::NoDifference,
code: ValidationResultCode::NoDifferenceExpected,
});
}
if self.differences_counts.fewer_ballots_count != 0 {
validation_results.warnings.push(ValidationResult {
fields: vec![format!("{field_name}.fewer_ballots_count")],
code: ValidationResultCode::NoDifference,
code: ValidationResultCode::NoDifferenceExpected,
});
}
}
Expand Down Expand Up @@ -908,7 +908,7 @@ mod tests {

#[test]
fn test_polling_station_results_wrong_and_no_difference_validation() {
// test F.25 wrong differences
// test F.25 conflicting differences
let mut validation_results = ValidationResults::default();
let polling_station_results = PollingStationResults {
recounted: false,
Expand All @@ -926,8 +926,8 @@ mod tests {
},
voters_recounts: None,
differences_counts: DifferencesCounts {
more_ballots_count: 4, // F.25 wrong differences
fewer_ballots_count: 4, // F.25 wrong differences
more_ballots_count: 4, // F.25 conflicting differences
fewer_ballots_count: 4, // F.25 conflicting differences
unreturned_ballots_count: 1,
too_few_ballots_handed_out_count: 1,
too_many_ballots_handed_out_count: 2,
Expand All @@ -953,7 +953,7 @@ mod tests {
assert_eq!(validation_results.warnings.len(), 0);
assert_eq!(
validation_results.errors[0].code,
ValidationResultCode::WrongDifferences
ValidationResultCode::ConflictingDifferences
);
assert_eq!(
validation_results.errors[0].fields,
Expand All @@ -963,7 +963,7 @@ mod tests {
]
);

// test W.32 no difference and F.14 incorrect total
// test W.32 no difference expected and F.14 incorrect total
validation_results = ValidationResults::default();
let polling_station_results = PollingStationResults {
recounted: true,
Expand All @@ -987,7 +987,7 @@ mod tests {
}),
differences_counts: DifferencesCounts {
more_ballots_count: 0,
fewer_ballots_count: 4, // W.32 no difference
fewer_ballots_count: 4, // W.32 no difference expected
unreturned_ballots_count: 1,
too_few_ballots_handed_out_count: 1,
too_many_ballots_handed_out_count: 0,
Expand Down Expand Up @@ -1024,7 +1024,7 @@ mod tests {
);
assert_eq!(
validation_results.warnings[0].code,
ValidationResultCode::NoDifference
ValidationResultCode::NoDifferenceExpected
);
assert_eq!(
validation_results.warnings[0].fields,
Expand Down
8 changes: 4 additions & 4 deletions backend/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ pub enum ValidationResultCode {
IncorrectCandidatesList,
MissingRecounts,
IncorrectDifference,
WrongDifferences,
NoDifference,
ConflictingDifferences,
NoDifferenceExpected,
}

impl fmt::Display for ValidationResultCode {
Expand All @@ -53,8 +53,8 @@ impl fmt::Display for ValidationResultCode {
ValidationResultCode::IncorrectCandidatesList => write!(f, "Incorrect candidates list"),
ValidationResultCode::MissingRecounts => write!(f, "Missing recounts"),
ValidationResultCode::IncorrectDifference => write!(f, "Incorrect difference"),
ValidationResultCode::WrongDifferences => write!(f, "Wrong differences"),
ValidationResultCode::NoDifference => write!(f, "No difference"),
ValidationResultCode::ConflictingDifferences => write!(f, "Conflicting differences"),
ValidationResultCode::NoDifferenceExpected => write!(f, "No difference expected"),
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions frontend/lib/api/gen/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export interface PoliticalGroupVotes {
* Polling station of a certain [Election]
*/
export interface PollingStation {
election_id: number;
house_number: string;
house_number_addition?: string;
id: number;
Expand Down Expand Up @@ -200,8 +201,8 @@ export type ValidationResultCode =
| "IncorrectCandidatesList"
| "MissingRecounts"
| "IncorrectDifference"
| "WrongDifferences"
| "NoDifference";
| "ConflictingDifferences"
| "NoDifferenceExpected";

export interface ValidationResults {
errors: ValidationResult[];
Expand Down

0 comments on commit ed1c100

Please sign in to comment.