From ee576400ce9c9e4f5d4ce420987ffd3ebe8ff5e0 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Fri, 23 Aug 2024 18:26:25 +0200 Subject: test(storage/setters): Assert the video status in `set_video_watched` --- src/storage/video_database/setters.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/storage/video_database/setters.rs b/src/storage/video_database/setters.rs index fcafcd4..c160138 100644 --- a/src/storage/video_database/setters.rs +++ b/src/storage/video_database/setters.rs @@ -12,7 +12,7 @@ use anyhow::Result; use chrono::Utc; -use log::debug; +use log::{debug, info}; use sqlx::query; use tokio::fs; @@ -116,6 +116,8 @@ pub async fn set_video_watched(app: &App, video: &Video) -> Result<()> { let video_hash = video.extractor_hash.hash().to_string(); let new_status = VideoStatus::Watched.as_db_integer(); + info!("Will set video watched: '{}'", video.title); + let old = query!( r#" SELECT status, priority @@ -127,9 +129,15 @@ pub async fn set_video_watched(app: &App, video: &Video) -> Result<()> { .fetch_one(&app.database) .await?; - if old.status == new_status { - unreachable!("The video should not be marked as watched already.") - } + assert_ne!( + old.status, new_status, + "The video should not be marked as watched already." + ); + assert_eq!( + old.status, + VideoStatus::Cached.as_db_integer(), + "The video should have been marked cached" + ); let now = Utc::now().timestamp(); @@ -180,7 +188,7 @@ pub async fn set_state_change( pub async fn set_video_options( app: &App, - hash: ExtractorHash, + hash: &ExtractorHash, video_options: &VideoOptions, ) -> Result<()> { let video_extractor_hash = hash.hash().to_string(); -- cgit 1.4.1