From 63b5aee577c8766a70ebf50493593d271ca6f26a Mon Sep 17 00:00:00 2001 From: Tim Date: Thu, 12 Oct 2023 17:27:18 +0200 Subject: [PATCH] test(uninstall_addon): use basic function instead of implementing them --- src/unit_tests/ctx/uninstall_addon.rs | 92 ++++++++++++--------------- 1 file changed, 42 insertions(+), 50 deletions(-) diff --git a/src/unit_tests/ctx/uninstall_addon.rs b/src/unit_tests/ctx/uninstall_addon.rs index 5caa78b41..5c1f4a8e8 100644 --- a/src/unit_tests/ctx/uninstall_addon.rs +++ b/src/unit_tests/ctx/uninstall_addon.rs @@ -19,56 +19,48 @@ use std::any::Any; use stremio_derive::Model; use url::Url; -type Addon = Descriptor; - -impl Addon { - fn new(transport_url: &str) -> Self { - Self { - manifest: Manifest { - id: "id".to_owned(), - version: Version::new(0, 0, 1), - name: "name".to_owned(), - contact_email: None, - description: None, - logo: None, - background: None, - types: vec![], - resources: vec![], - id_prefixes: None, - catalogs: vec![], - addon_catalogs: vec![], - behavior_hints: Default::default(), - }, - transport_url: Url::parse(transport_url).unwrap(), - flags: Default::default(), - } +fn create_addon_descriptor(transport_url: &str) -> Descriptor { + Descriptor { + manifest: Manifest { + id: "id".to_owned(), + version: Version::new(0, 0, 1), + name: "name".to_owned(), + contact_email: None, + description: None, + logo: None, + background: None, + types: vec![], + resources: vec![], + id_prefixes: None, + catalogs: vec![], + addon_catalogs: vec![], + behavior_hints: Default::default(), + }, + transport_url: Url::parse(transport_url).unwrap(), + flags: Default::default(), } } -type AddonStreamsItem = StreamsItem; - -impl AddonStreamsItem { - fn new(addon: &Addon) -> Self { - let stream = Stream { - source: StreamSource::Url { - url: "https://source_url".parse().unwrap(), - }, - name: None, - description: None, - thumbnail: None, - subtitles: vec![], - behavior_hints: StreamBehaviorHints::default(), - }; +fn create_addon_streams_item(addon: &Descriptor) -> StreamsItem { + let stream = Stream { + source: StreamSource::Url { + url: "https://source_url".parse().unwrap(), + }, + name: None, + description: None, + thumbnail: None, + subtitles: vec![], + behavior_hints: StreamBehaviorHints::default(), + }; - Self { - stream, - r#type: "movie".to_owned(), - meta_id: "tt123456".to_owned(), - video_id: "tt123456:1:0".to_owned(), - meta_transport_url: addon.transport_url.clone(), - stream_transport_url: addon.transport_url.clone(), - mtime: TestEnv::now(), - } + StreamsItem { + stream, + r#type: "movie".to_owned(), + meta_id: "tt123456".to_owned(), + video_id: "tt123456:1:0".to_owned(), + meta_transport_url: addon.transport_url.clone(), + stream_transport_url: addon.transport_url.clone(), + mtime: TestEnv::now(), } } @@ -433,8 +425,8 @@ fn actionctx_uninstalladdon_streams_bucket() { ctx: Ctx, } - let addon = Addon::new("https://transport_url"); - let addon_2 = Addon::new("https://transport_url_2"); + let addon = create_addon_descriptor("https://transport_url"); + let addon_2 = create_addon_descriptor("https://transport_url_2"); let profile = Profile { addons: vec![addon.to_owned()], @@ -456,8 +448,8 @@ fn actionctx_uninstalladdon_streams_bucket() { video_id: "tt123456:1:1".to_owned(), }; - let stream_item = AddonStreamsItem::new(&addon); - let stream_item_2 = AddonStreamsItem::new(&addon_2); + let stream_item = create_addon_streams_item(&addon); + let stream_item_2 = create_addon_streams_item(&addon_2); let mut streams = StreamsBucket::default(); streams.items.insert(streams_item_key.clone(), stream_item);