lib_item enhancements and tests
@@ -2,7 +2,7 @@ use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
// @TODO: u64 vs u32
-#[derive(Serialize, Deserialize)]
+#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Ord, PartialOrd)]
#[serde(rename_all = "camelCase")]
pub struct LibItemState {
pub last_watched: Option<DateTime<Utc>>,
@@ -10,7 +10,8 @@ pub struct LibItemState {
pub time_offset: u64,
pub overall_time_watched: u64,
pub times_watched: u32,
- pub flagged_watched: bool,
+ // @TODO: consider bool that can be deserialized from an integer
+ pub flagged_watched: u32,
pub duration: u64,
#[serde(rename = "video_id")]
pub video_id: Option<String>,
@@ -19,7 +20,7 @@ pub struct LibItemState {
pub no_notif: bool,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Ord, PartialOrd)]
pub struct LibItem {
#[serde(rename = "_id")]
pub id: String,
@@ -42,3 +43,19 @@ pub struct LibItem {
pub logo: Option<String>,
pub year: Option<String>,
}
+
+#[cfg(test)]
+mod test {
+ use super::*;
+
+ #[test]
+ pub fn test_deser() {
+ // `serialized` is copy-pasted from Stremio v4.4
+ let serialized = r#"
+ {"state":{"lastWatched":"2016-06-03T08:36:42.494Z","timeWatched":0,"timeOffset":0,"overallTimeWatched":0,"timesWatched":0,"flaggedWatched":0,"duration":0,"video_id":"","watched":"","noNotif":false,"season":0,"episode":0,"watchedEpisodes":[]},"_id":"tt0004972","removed":true,"temp":true,"_ctime":"2016-06-03T08:29:46.612Z","_mtime":"2016-06-03T08:36:43.991Z","name":"The Birth of a Nation","type":"movie","poster":"https://images.metahub.space/poster/medium/tt0004972/img","background":"","logo":"","year":"","imdb_id":"tt0004972"}
+ "#;
+ let l: LibItem = serde_json::from_str(&serialized).unwrap();
+ //dbg!(&l);
+ // @TODO assertions
+ }
+}
