Skip to content

Commit

Permalink
resolve test failings
Browse files Browse the repository at this point in the history
  • Loading branch information
george-misan committed May 31, 2024
1 parent 75acd3f commit 95ed490
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
9 changes: 9 additions & 0 deletions services/headless-lms/models/src/course_instances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -921,4 +921,13 @@ mod test {
);
tx.rollback().await;
}

#[tokio::test]
async fn gets_course_average_duration_with_empty_database() {
insert_data!(:tx, :user, :org, :course, :instance);
let duration = get_course_average_duration(tx.as_mut(), instance.id)
.await
.unwrap();
assert!(duration.is_none())
}
}
31 changes: 17 additions & 14 deletions services/headless-lms/models/src/library/progressing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,23 @@ pub async fn update_automatic_completion_status_and_grant_if_eligible(
)
.await?;

let thresholds = suspected_cheaters::get_thresholds_by_id(conn, course_instance_id).await?;
let average_duration_seconds =
course_instances::get_course_average_duration(conn, course_instance_id).await?;
if let Some(thresholds) = suspected_cheaters::get_thresholds_by_id(conn, course_instance_id)
.await
.optional()?
{
let average_duration_seconds =
course_instances::get_course_average_duration(conn, course_instance_id).await?;

check_and_insert_suspected_cheaters(
conn,
user_id,
course_instance_id,
&thresholds,
average_duration_seconds,
completion,
)
.await?;
check_and_insert_suspected_cheaters(
conn,
user_id,
course_instance_id,
&thresholds,
average_duration_seconds,
completion,
)
.await?;
}
}
Ok(())
}
Expand Down Expand Up @@ -895,6 +899,7 @@ mod tests {
use crate::test_helper::*;

mod grant_automatic_completion_if_eligible {
use super::*;
use crate::{
chapters::NewChapter,
course_modules::{
Expand All @@ -905,8 +910,6 @@ mod tests {
user_exercise_states::{self, ReviewingStage, UserExerciseStateUpdate},
};

use super::*;

#[tokio::test]
async fn grants_automatic_completion_but_no_prerequisite_for_default_module() {
insert_data!(:tx);
Expand Down
12 changes: 6 additions & 6 deletions services/headless-lms/server/tests/study_registry_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ async fn insert_data(
)
.await
.unwrap();
let course_module_completion_id = headless_lms_models::course_module_completions::insert(
let course_module_completion = headless_lms_models::course_module_completions::insert(
conn,
PKeyPolicy::Generate,
&NewCourseModuleCompletion {
Expand All @@ -194,12 +194,12 @@ async fn insert_data(
.unwrap();
headless_lms_models::course_module_completions::update_prerequisite_modules_completed(
conn,
course_module_completion_id,
course_module_completion.id,
true,
)
.await
.unwrap();
let course_module_completion_2_id = headless_lms_models::course_module_completions::insert(
let course_module_completion_2 = headless_lms_models::course_module_completions::insert(
conn,
PKeyPolicy::Generate,
&NewCourseModuleCompletion {
Expand All @@ -221,7 +221,7 @@ async fn insert_data(
.unwrap();
headless_lms_models::course_module_completions::update_prerequisite_modules_completed(
conn,
course_module_completion_2_id,
course_module_completion_2.id,
true,
)
.await
Expand All @@ -231,7 +231,7 @@ async fn insert_data(
org,
course.id,
course_module.id,
course_module_completion_id,
course_module_completion_2_id,
course_module_completion.id,
course_module_completion_2.id,
)
}

0 comments on commit 95ed490

Please sign in to comment.