diff --git a/src/domain/answer_image.rs b/src/domain/answer_image.rs index 25d4035..49780a2 100644 --- a/src/domain/answer_image.rs +++ b/src/domain/answer_image.rs @@ -229,7 +229,10 @@ mod tests { .upsert(&db) .await .unwrap(); - assert_eq!(AnswerImage::list_for_exam(&exam, &db).await.unwrap().len(), 2); + assert_eq!( + AnswerImage::list_for_exam(&exam, &db).await.unwrap().len(), + 2 + ); assert!( AnswerImage::read(&question, &user, &db) .await diff --git a/src/domain/homework_submission.rs b/src/domain/homework_submission.rs index ba8924e..aed6932 100644 --- a/src/domain/homework_submission.rs +++ b/src/domain/homework_submission.rs @@ -206,8 +206,10 @@ impl HomeworkSubmission { .await? .check()?; // BEGIN is slot 0, the file wipe slot 1; the submission's DELETE is slot 2. - let deleted: Option = - result.take::>(2)?.into_iter().next(); + let deleted: Option = result + .take::>(2)? + .into_iter() + .next(); deleted.ok_or(AppError::NotFound) } } diff --git a/src/web/exams.rs b/src/web/exams.rs index 78e3a00..c089edd 100644 --- a/src/web/exams.rs +++ b/src/web/exams.rs @@ -2570,9 +2570,9 @@ async fn store_answer_image( data.len() as i64, ); let path = blob_path(&st.files_path, image.get_file()); - tokio::fs::write(&path, data) - .await - .map_err(|err| AppError::Internal(format!("failed to store the answer image blob: {err}")))?; + tokio::fs::write(&path, data).await.map_err(|err| { + AppError::Internal(format!("failed to store the answer image blob: {err}")) + })?; match image.upsert(&st.db).await { Ok(stored) => { if let Some(replaced) = replaced { @@ -2639,8 +2639,15 @@ async fn upload_answer_image( ensure_enrolled(&exam, attempt.get_user(), &st.db).await?; check_rejoin(&exam, &attempt)?; let question = question_of_exam(exam.get_id(), &qid, &st.db).await?; - let stored = - store_answer_image(&st, &exam, &question, user.get_id(), content_type, &upload.data).await?; + let stored = store_answer_image( + &st, + &exam, + &question, + user.get_id(), + content_type, + &upload.data, + ) + .await?; // A drawing-only answer (drew, typed nothing) still needs an ExamAnswer row, // or the drawing never surfaces in the sitting/grading views — answer_image // rides the answer payload. Create a blank text answer when absent, without @@ -2654,7 +2661,10 @@ async fn upload_answer_image( { ExamAnswer::save(&question, user.get_id(), None, Some(String::new()), &st.db).await?; } - Ok((StatusCode::CREATED, Json(ImageMetaResponse::from_answer(&stored)))) + Ok(( + StatusCode::CREATED, + Json(ImageMetaResponse::from_answer(&stored)), + )) } /// Clear the caller's drawn answer to a question. Same writable-attempt gate diff --git a/tests/integration.rs b/tests/integration.rs index 8a9ebcc..2b4bb89 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -10887,8 +10887,13 @@ async fn student_answer_images_serve_and_cascade() { // peek: the write path 404s (no attempt), the own-read 404s too. let (status, _) = post_image(&app, &student, &own, "image/png", png).await; assert_eq!(status, StatusCode::NOT_FOUND, "no attempt yet"); - let (status, _, _) = common::send_raw(&app, "GET", &own, Some(&student), None, Vec::new()).await; - assert_eq!(status, StatusCode::NOT_FOUND, "no early peek before the attempt"); + let (status, _, _) = + common::send_raw(&app, "GET", &own, Some(&student), None, Vec::new()).await; + assert_eq!( + status, + StatusCode::NOT_FOUND, + "no early peek before the attempt" + ); // The student sits the exam. let res = send( @@ -10954,7 +10959,10 @@ async fn student_answer_images_serve_and_cascade() { ) .await; assert_eq!(res.status, StatusCode::OK); - assert_eq!(res.body[0]["answer"]["answer_image"]["content_type"], "image/webp"); + assert_eq!( + res.body[0]["answer"]["answer_image"]["content_type"], + "image/webp" + ); // The teacher grading sheet carries the drawing meta and serves the bytes // via the teacher route; the sheet row also exposes the flag. @@ -10968,14 +10976,31 @@ async fn student_answer_images_serve_and_cascade() { ) .await; assert_eq!(res.status, StatusCode::OK, "{}", res.body); - assert_eq!(res.body["answers"][0]["answer_image"]["content_type"], "image/webp"); - let (status, _, bytes) = - common::send_raw(&app, "GET", &teacher_bytes, Some(&teacher), None, Vec::new()).await; + assert_eq!( + res.body["answers"][0]["answer_image"]["content_type"], + "image/webp" + ); + let (status, _, bytes) = common::send_raw( + &app, + "GET", + &teacher_bytes, + Some(&teacher), + None, + Vec::new(), + ) + .await; assert_eq!(status, StatusCode::OK); assert_eq!(bytes, png); // An outsider student can't read the teacher grading route (not a teacher). - let (status, _, _) = - common::send_raw(&app, "GET", &teacher_bytes, Some(&outsider), None, Vec::new()).await; + let (status, _, _) = common::send_raw( + &app, + "GET", + &teacher_bytes, + Some(&outsider), + None, + Vec::new(), + ) + .await; assert_eq!(status, StatusCode::FORBIDDEN); // A retake wipes the student's sheet — the answer-image row *and* its @@ -11068,16 +11093,33 @@ async fn answer_image_surfaces_for_a_drawing_only_answer() { .await; // Sit, then upload a drawing WITHOUT ever saving a text answer. - let res = send(&app, "POST", &format!("/exams/{exam}/attempt"), Some(&student), None).await; + let res = send( + &app, + "POST", + &format!("/exams/{exam}/attempt"), + Some(&student), + None, + ) + .await; assert_eq!(res.status, StatusCode::CREATED, "{}", res.body); let own = format!("/exams/{exam}/attempt/answers/{question}/image"); let (status, body) = post_image(&app, &student, &own, "image/png", b"tri").await; assert_eq!(status, StatusCode::CREATED, "{body}"); // The sitting view carries the drawing meta with an empty typed answer. - let res = send(&app, "GET", &format!("/exams/{exam}/attempt/questions"), Some(&student), None).await; + let res = send( + &app, + "GET", + &format!("/exams/{exam}/attempt/questions"), + Some(&student), + None, + ) + .await; assert_eq!(res.status, StatusCode::OK); - assert_eq!(res.body[0]["answer"]["answer_image"]["content_type"], "image/png"); + assert_eq!( + res.body[0]["answer"]["answer_image"]["content_type"], + "image/png" + ); assert_eq!(res.body[0]["answer"]["text"], ""); // The teacher grading sheet shows it too. @@ -11090,15 +11132,29 @@ async fn answer_image_surfaces_for_a_drawing_only_answer() { ) .await; assert_eq!(res.status, StatusCode::OK, "{}", res.body); - assert_eq!(res.body["answers"][0]["answer_image"]["content_type"], "image/png"); + assert_eq!( + res.body["answers"][0]["answer_image"]["content_type"], + "image/png" + ); // Removing the drawing drops the blank answer row it created — the question // stops showing as answered rather than lingering as an empty text answer. - let (status, _, _) = common::send_raw(&app, "DELETE", &own, Some(&student), None, Vec::new()).await; + let (status, _, _) = + common::send_raw(&app, "DELETE", &own, Some(&student), None, Vec::new()).await; assert_eq!(status, StatusCode::NO_CONTENT); - let res = send(&app, "GET", &format!("/exams/{exam}/attempt/questions"), Some(&student), None).await; + let res = send( + &app, + "GET", + &format!("/exams/{exam}/attempt/questions"), + Some(&student), + None, + ) + .await; assert_eq!(res.status, StatusCode::OK); - assert!(res.body[0]["answer"].is_null(), "blank answer row dropped with its drawing"); + assert!( + res.body[0]["answer"].is_null(), + "blank answer row dropped with its drawing" + ); } /// The authoring edits that reshape a question also groom its images: a