Skip to content

Commit cea485c

Browse files
committed
Fixed validation deserialization
1 parent 2b7927f commit cea485c

File tree

3 files changed

+81
-2
lines changed

3 files changed

+81
-2
lines changed

crates/tmc-langs-framework/src/domain.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ pub struct StyleValidationError {
151151

152152
/// The result of a style check.
153153
#[derive(Debug, Deserialize, Serialize, PartialEq, Eq, JsonSchema)]
154-
#[serde(rename_all = "camelCase")]
155154
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
155+
#[serde(rename_all = "camelCase")]
156156
pub struct StyleValidationResult {
157157
pub strategy: StyleValidationStrategy,
158158
pub validation_errors: Option<HashMap<PathBuf, Vec<StyleValidationError>>>,

crates/tmc-langs-util/src/parse_util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn comma_separated_strings_either(i: &str) -> IResult<&str, Vec<&str>, Verbo
4545
fn comma_separated_things<'a>(
4646
thing_parser: impl FnMut(&'a str) -> IResult<&'a str, &'a str, VerboseError<&'a str>>,
4747
i: &'a str,
48-
) -> IResult<&str, Vec<&str>, VerboseError<&str>> {
48+
) -> IResult<&'a str, Vec<&'a str>, VerboseError<&'a str>> {
4949
multi::separated_list1(
5050
sequence::delimited(
5151
character::complete::multispace0,

crates/tmc-testmycode-client/src/response.rs

+79
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ pub struct Review {
576576
/// The result of a style check.
577577
#[derive(Debug, Deserialize, Serialize, PartialEq, Eq, JsonSchema)]
578578
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
579+
#[serde(rename_all = "camelCase")]
579580
pub struct TmcStyleValidationResult {
580581
pub strategy: TmcStyleValidationStrategy,
581582
pub validation_errors: Option<HashMap<PathBuf, Vec<TmcStyleValidationError>>>,
@@ -594,6 +595,7 @@ pub enum TmcStyleValidationStrategy {
594595
/// A style validation error.
595596
#[derive(Debug, Deserialize, Serialize, PartialEq, Eq, JsonSchema)]
596597
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
598+
#[serde(rename_all = "camelCase")]
597599
pub struct TmcStyleValidationError {
598600
pub column: u32,
599601
pub line: u32,
@@ -695,4 +697,81 @@ mod test {
695697
let json = serde_json::to_string(&original).unwrap();
696698
assert_eq!(json, r#"{"IntRange":{"lower":1,"upper":5}}"#);
697699
}
700+
701+
#[test]
702+
fn submission_response_with_validation_errors() {
703+
init();
704+
705+
let submission = serde_json::json!(
706+
{
707+
"api_version": 7,
708+
"all_tests_passed": false,
709+
"user_id": 12345,
710+
"login": "12345",
711+
"course": "course",
712+
"exercise_name": "exercise",
713+
"status": "fail",
714+
"points": [],
715+
"validations": {
716+
"strategy": "FAIL",
717+
"validationErrors": {
718+
"Main.java": [
719+
{
720+
"column": 1,
721+
"line": 1,
722+
"message": "Indentation incorrect. Expected 8, but was 12.",
723+
"sourceName": "com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck"
724+
},
725+
{
726+
"column": 2,
727+
"line": 2,
728+
"message": "Indentation incorrect. Expected 8, but was 12.",
729+
"sourceName": "com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck"
730+
}
731+
]
732+
}
733+
},
734+
"valgrind": "",
735+
"submission_url": "https://tmc.mooc.fi/submissions/12345",
736+
"solution_url": "https://tmc.mooc.fi/exercises/12345/solution",
737+
"submitted_at": "2025-01-01T01:01:01.001+01:01",
738+
"processing_time": 12345,
739+
"reviewed": false,
740+
"requests_review": false,
741+
"paste_url": null,
742+
"message_for_paste": null,
743+
"missing_review_points": [],
744+
"test_cases": [
745+
{
746+
"name": "FakeTest test",
747+
"successful": true,
748+
"message": "",
749+
"exception": [],
750+
"detailed_message": null
751+
},
752+
{
753+
"name": "FakeTest testTwo",
754+
"successful": true,
755+
"message": "",
756+
"exception": [],
757+
"detailed_message": null
758+
},
759+
{
760+
"name": "FakeTest testThree",
761+
"successful": true,
762+
"message": "",
763+
"exception": [],
764+
"detailed_message": null
765+
}
766+
]
767+
}
768+
);
769+
let submission = deserialize::json_from_value::<SubmissionFinished>(submission).unwrap();
770+
assert!(!submission
771+
.validations
772+
.unwrap()
773+
.validation_errors
774+
.unwrap()
775+
.is_empty());
776+
}
698777
}

0 commit comments

Comments
 (0)