fix: moved integration tests,
fixed missing search video count, error on missing search channel description snipped, error on empty channel info link list,
This commit is contained in:
parent
4dfdb47cae
commit
1fb4a2664e
13 changed files with 998 additions and 864 deletions
|
|
@ -570,478 +570,13 @@ fn map_comment(
|
|||
mod tests {
|
||||
use std::{fs::File, io::BufReader, path::Path};
|
||||
|
||||
use chrono::Datelike;
|
||||
use rstest::rstest;
|
||||
|
||||
use crate::{
|
||||
client::{response, MapResponse, RustyPipe},
|
||||
model::{richtext::ToPlaintext, Verification},
|
||||
client::{response, MapResponse},
|
||||
param::Language,
|
||||
};
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_video_details() {
|
||||
let rp = RustyPipe::builder().strict().build();
|
||||
let details = rp.query().video_details("ZeerrnuLi5E").await.unwrap();
|
||||
|
||||
// dbg!(&details);
|
||||
|
||||
assert_eq!(details.id, "ZeerrnuLi5E");
|
||||
assert_eq!(details.title, "aespa 에스파 'Black Mamba' MV");
|
||||
let desc = details.description.to_plaintext();
|
||||
assert!(
|
||||
desc.contains("Listen and download aespa's debut single \"Black Mamba\""),
|
||||
"bad description: {}",
|
||||
desc
|
||||
);
|
||||
|
||||
assert_eq!(details.channel.id, "UCEf_Bc-KVd7onSeifS3py9g");
|
||||
assert_eq!(details.channel.name, "SMTOWN");
|
||||
assert!(!details.channel.avatar.is_empty(), "no channel avatars");
|
||||
assert_eq!(details.channel.verification, Verification::Verified);
|
||||
assert!(
|
||||
details.channel.subscriber_count.unwrap() > 30000000,
|
||||
"expected >30M subs, got {}",
|
||||
details.channel.subscriber_count.unwrap()
|
||||
);
|
||||
|
||||
assert!(
|
||||
details.view_count > 232000000,
|
||||
"expected > 232M views, got {}",
|
||||
details.view_count
|
||||
);
|
||||
assert!(
|
||||
details.like_count.unwrap() > 4000000,
|
||||
"expected > 4M likes, got {}",
|
||||
details.like_count.unwrap()
|
||||
);
|
||||
|
||||
let date = details.publish_date.unwrap();
|
||||
assert_eq!(date.year(), 2020);
|
||||
assert_eq!(date.month(), 11);
|
||||
assert_eq!(date.day(), 17);
|
||||
|
||||
assert!(!details.is_live);
|
||||
assert!(!details.is_ccommons);
|
||||
|
||||
assert!(!details.recommended.items.is_empty());
|
||||
assert!(!details.recommended.is_exhausted());
|
||||
|
||||
assert!(
|
||||
details.top_comments.count.unwrap() > 700000,
|
||||
"expected > 700K comments, got {}",
|
||||
details.top_comments.count.unwrap()
|
||||
);
|
||||
assert!(!details.top_comments.is_exhausted());
|
||||
assert!(!details.latest_comments.is_exhausted());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_video_details_music() {
|
||||
let rp = RustyPipe::builder().strict().build();
|
||||
let details = rp.query().video_details("XuM2onMGvTI").await.unwrap();
|
||||
|
||||
// dbg!(&details);
|
||||
|
||||
assert_eq!(details.id, "XuM2onMGvTI");
|
||||
assert_eq!(details.title, "Gäa");
|
||||
let desc = details.description.to_plaintext();
|
||||
assert!(desc.contains("Gäa · Oonagh"), "bad description: {}", desc);
|
||||
|
||||
assert_eq!(details.channel.id, "UCVGvnqB-5znqPSbMGlhF4Pw");
|
||||
assert_eq!(details.channel.name, "Sentamusic");
|
||||
assert!(!details.channel.avatar.is_empty(), "no channel avatars");
|
||||
assert_eq!(details.channel.verification, Verification::Artist);
|
||||
assert!(
|
||||
details.channel.subscriber_count.unwrap() > 33000,
|
||||
"expected >33K subs, got {}",
|
||||
details.channel.subscriber_count.unwrap()
|
||||
);
|
||||
|
||||
assert!(
|
||||
details.view_count > 20309,
|
||||
"expected > 20309 views, got {}",
|
||||
details.view_count
|
||||
);
|
||||
assert!(
|
||||
details.like_count.unwrap() > 145,
|
||||
"expected > 145 likes, got {}",
|
||||
details.like_count.unwrap()
|
||||
);
|
||||
|
||||
let date = details.publish_date.unwrap();
|
||||
assert_eq!(date.year(), 2020);
|
||||
assert_eq!(date.month(), 8);
|
||||
assert_eq!(date.day(), 6);
|
||||
|
||||
assert!(!details.is_live);
|
||||
assert!(!details.is_ccommons);
|
||||
|
||||
assert!(!details.recommended.items.is_empty());
|
||||
assert!(!details.recommended.is_exhausted());
|
||||
|
||||
// Comments are disabled for this video
|
||||
assert_eq!(details.top_comments.count, Some(0));
|
||||
assert_eq!(details.latest_comments.count, Some(0));
|
||||
assert!(details.top_comments.is_empty());
|
||||
assert!(details.latest_comments.is_empty());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_video_details_ccommons() {
|
||||
let rp = RustyPipe::builder().strict().build();
|
||||
let details = rp.query().video_details("0rb9CfOvojk").await.unwrap();
|
||||
|
||||
// dbg!(&details);
|
||||
|
||||
assert_eq!(details.id, "0rb9CfOvojk");
|
||||
assert_eq!(
|
||||
details.title,
|
||||
"BahnMining - Pünktlichkeit ist eine Zier (David Kriesel)"
|
||||
);
|
||||
let desc = details.description.to_plaintext();
|
||||
assert!(
|
||||
desc.contains("Seit Anfang 2019 hat David jeden einzelnen Halt jeder einzelnen Zugfahrt auf jedem einzelnen Fernbahnhof in ganz Deutschland"),
|
||||
"bad description: {}",
|
||||
desc
|
||||
);
|
||||
|
||||
assert_eq!(details.channel.id, "UC2TXq_t06Hjdr2g_KdKpHQg");
|
||||
assert_eq!(details.channel.name, "media.ccc.de");
|
||||
assert!(!details.channel.avatar.is_empty(), "no channel avatars");
|
||||
assert_eq!(details.channel.verification, Verification::None);
|
||||
assert!(
|
||||
details.channel.subscriber_count.unwrap() > 170000,
|
||||
"expected >170K subs, got {}",
|
||||
details.channel.subscriber_count.unwrap()
|
||||
);
|
||||
|
||||
assert!(
|
||||
details.view_count > 2517358,
|
||||
"expected > 2517358 views, got {}",
|
||||
details.view_count
|
||||
);
|
||||
assert!(
|
||||
details.like_count.unwrap() > 52330,
|
||||
"expected > 52330 likes, got {}",
|
||||
details.like_count.unwrap()
|
||||
);
|
||||
|
||||
let date = details.publish_date.unwrap();
|
||||
assert_eq!(date.year(), 2019);
|
||||
assert_eq!(date.month(), 12);
|
||||
assert_eq!(date.day(), 29);
|
||||
|
||||
assert!(!details.is_live);
|
||||
assert!(details.is_ccommons);
|
||||
|
||||
assert!(!details.recommended.items.is_empty());
|
||||
assert!(!details.recommended.is_exhausted());
|
||||
|
||||
assert!(
|
||||
details.top_comments.count.unwrap() > 2199,
|
||||
"expected > 2199 comments, got {}",
|
||||
details.top_comments.count.unwrap()
|
||||
);
|
||||
assert!(!details.top_comments.is_exhausted());
|
||||
assert!(!details.latest_comments.is_exhausted());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_video_details_chapters() {
|
||||
let rp = RustyPipe::builder().strict().build();
|
||||
let details = rp.query().video_details("nFDBxBUfE74").await.unwrap();
|
||||
|
||||
// dbg!(&details);
|
||||
|
||||
assert_eq!(details.id, "nFDBxBUfE74");
|
||||
assert_eq!(details.title, "The Prepper PC");
|
||||
let desc = details.description.to_plaintext();
|
||||
assert!(
|
||||
desc.contains("These days, you can game almost anywhere on the planet, anytime. But what if that planet was in the middle of an apocalypse"),
|
||||
"bad description: {}",
|
||||
desc
|
||||
);
|
||||
|
||||
assert_eq!(details.channel.id, "UCXuqSBlHAE6Xw-yeJA0Tunw");
|
||||
assert_eq!(details.channel.name, "Linus Tech Tips");
|
||||
assert!(!details.channel.avatar.is_empty(), "no channel avatars");
|
||||
assert_eq!(details.channel.verification, Verification::Verified);
|
||||
assert!(
|
||||
details.channel.subscriber_count.unwrap() > 14700000,
|
||||
"expected >14.7M subs, got {}",
|
||||
details.channel.subscriber_count.unwrap()
|
||||
);
|
||||
|
||||
assert!(
|
||||
details.view_count > 1157262,
|
||||
"expected > 1157262 views, got {}",
|
||||
details.view_count
|
||||
);
|
||||
assert!(
|
||||
details.like_count.unwrap() > 54670,
|
||||
"expected > 54670 likes, got {}",
|
||||
details.like_count.unwrap()
|
||||
);
|
||||
|
||||
let date = details.publish_date.unwrap();
|
||||
assert_eq!(date.year(), 2022);
|
||||
assert_eq!(date.month(), 9);
|
||||
assert_eq!(date.day(), 15);
|
||||
|
||||
assert!(!details.is_live);
|
||||
assert!(!details.is_ccommons);
|
||||
|
||||
insta::assert_ron_snapshot!(details.chapters, {
|
||||
"[].thumbnail" => insta::dynamic_redaction(move |value, _path| {
|
||||
assert!(!value.as_slice().unwrap().is_empty());
|
||||
"[ok]"
|
||||
}),
|
||||
}, @r###"
|
||||
[
|
||||
Chapter(
|
||||
title: "Intro",
|
||||
position: 0,
|
||||
thumbnail: "[ok]",
|
||||
),
|
||||
Chapter(
|
||||
title: "The PC Built for Super Efficiency",
|
||||
position: 42,
|
||||
thumbnail: "[ok]",
|
||||
),
|
||||
Chapter(
|
||||
title: "Our BURIAL ENCLOSURE?!",
|
||||
position: 161,
|
||||
thumbnail: "[ok]",
|
||||
),
|
||||
Chapter(
|
||||
title: "Our Power Solution (Thanks Jackery!)",
|
||||
position: 211,
|
||||
thumbnail: "[ok]",
|
||||
),
|
||||
Chapter(
|
||||
title: "Diggin\' Holes",
|
||||
position: 287,
|
||||
thumbnail: "[ok]",
|
||||
),
|
||||
Chapter(
|
||||
title: "Colonoscopy?",
|
||||
position: 330,
|
||||
thumbnail: "[ok]",
|
||||
),
|
||||
Chapter(
|
||||
title: "Diggin\' like a man",
|
||||
position: 424,
|
||||
thumbnail: "[ok]",
|
||||
),
|
||||
Chapter(
|
||||
title: "The world\'s worst woodsman",
|
||||
position: 509,
|
||||
thumbnail: "[ok]",
|
||||
),
|
||||
Chapter(
|
||||
title: "Backyard cable management",
|
||||
position: 543,
|
||||
thumbnail: "[ok]",
|
||||
),
|
||||
Chapter(
|
||||
title: "Time to bury this boy",
|
||||
position: 602,
|
||||
thumbnail: "[ok]",
|
||||
),
|
||||
Chapter(
|
||||
title: "Solar Power Generation",
|
||||
position: 646,
|
||||
thumbnail: "[ok]",
|
||||
),
|
||||
Chapter(
|
||||
title: "Issues",
|
||||
position: 697,
|
||||
thumbnail: "[ok]",
|
||||
),
|
||||
Chapter(
|
||||
title: "First Play Test",
|
||||
position: 728,
|
||||
thumbnail: "[ok]",
|
||||
),
|
||||
Chapter(
|
||||
title: "Conclusion",
|
||||
position: 800,
|
||||
thumbnail: "[ok]",
|
||||
),
|
||||
]
|
||||
"###);
|
||||
|
||||
assert!(!details.recommended.items.is_empty());
|
||||
assert!(!details.recommended.is_exhausted());
|
||||
|
||||
assert!(
|
||||
details.top_comments.count.unwrap() > 3199,
|
||||
"expected > 3199 comments, got {}",
|
||||
details.top_comments.count.unwrap()
|
||||
);
|
||||
assert!(!details.top_comments.is_exhausted());
|
||||
assert!(!details.latest_comments.is_exhausted());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_video_details_live() {
|
||||
let rp = RustyPipe::builder().strict().build();
|
||||
let details = rp.query().video_details("86YLFOog4GM").await.unwrap();
|
||||
|
||||
// dbg!(&details);
|
||||
|
||||
assert_eq!(details.id, "86YLFOog4GM");
|
||||
assert_eq!(
|
||||
details.title,
|
||||
"🌎 Nasa Live Stream - Earth From Space : Live Views from the ISS"
|
||||
);
|
||||
let desc = details.description.to_plaintext();
|
||||
assert!(
|
||||
desc.contains("Live NASA - Views Of Earth from Space"),
|
||||
"bad description: {}",
|
||||
desc
|
||||
);
|
||||
|
||||
assert_eq!(details.channel.id, "UCakgsb0w7QB0VHdnCc-OVEA");
|
||||
assert_eq!(details.channel.name, "Space Videos");
|
||||
assert!(!details.channel.avatar.is_empty(), "no channel avatars");
|
||||
assert_eq!(details.channel.verification, Verification::Verified);
|
||||
assert!(
|
||||
details.channel.subscriber_count.unwrap() > 5500000,
|
||||
"expected >5.5M subs, got {}",
|
||||
details.channel.subscriber_count.unwrap()
|
||||
);
|
||||
|
||||
assert!(
|
||||
details.view_count > 10,
|
||||
"expected > 10 views, got {}",
|
||||
details.view_count
|
||||
);
|
||||
assert!(
|
||||
details.like_count.unwrap() > 872290,
|
||||
"expected > 872290 likes, got {}",
|
||||
details.like_count.unwrap()
|
||||
);
|
||||
|
||||
let date = details.publish_date.unwrap();
|
||||
assert_eq!(date.year(), 2021);
|
||||
assert_eq!(date.month(), 9);
|
||||
assert_eq!(date.day(), 23);
|
||||
|
||||
assert!(details.is_live);
|
||||
assert!(!details.is_ccommons);
|
||||
|
||||
assert!(!details.recommended.items.is_empty());
|
||||
assert!(!details.recommended.is_exhausted());
|
||||
|
||||
// No comments because livestream
|
||||
assert_eq!(details.top_comments.count, Some(0));
|
||||
assert_eq!(details.latest_comments.count, Some(0));
|
||||
assert!(details.top_comments.is_empty());
|
||||
assert!(details.latest_comments.is_empty());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_video_details_agegate() {
|
||||
let rp = RustyPipe::builder().strict().build();
|
||||
let details = rp.query().video_details("HRKu0cvrr_o").await.unwrap();
|
||||
|
||||
// dbg!(&details);
|
||||
|
||||
assert_eq!(details.id, "HRKu0cvrr_o");
|
||||
assert_eq!(
|
||||
details.title,
|
||||
"AlphaOmegaSin Fanboy Logic: Likes/Dislikes Disabled = Point Invalid Lol wtf?"
|
||||
);
|
||||
insta::assert_ron_snapshot!(details.description, @"RichText([])");
|
||||
|
||||
assert_eq!(details.channel.id, "UCQT2yul0lr6Ie9qNQNmw-sg");
|
||||
assert_eq!(details.channel.name, "PrinceOfFALLEN");
|
||||
assert!(!details.channel.avatar.is_empty(), "no channel avatars");
|
||||
assert_eq!(details.channel.verification, Verification::None);
|
||||
assert!(
|
||||
details.channel.subscriber_count.unwrap() > 1400,
|
||||
"expected >1400 subs, got {}",
|
||||
details.channel.subscriber_count.unwrap()
|
||||
);
|
||||
|
||||
assert!(
|
||||
details.view_count > 200,
|
||||
"expected > 200 views, got {}",
|
||||
details.view_count
|
||||
);
|
||||
assert!(details.like_count.is_none(), "like count not hidden");
|
||||
|
||||
let date = details.publish_date.unwrap();
|
||||
assert_eq!(date.year(), 2019);
|
||||
assert_eq!(date.month(), 1);
|
||||
assert_eq!(date.day(), 2);
|
||||
|
||||
assert!(!details.is_live);
|
||||
assert!(!details.is_ccommons);
|
||||
|
||||
// No recommendations because agegate
|
||||
assert_eq!(details.recommended.count, Some(0));
|
||||
assert!(details.recommended.items.is_empty());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_video_recommendations() {
|
||||
let rp = RustyPipe::builder().strict().build();
|
||||
let details = rp.query().video_details("ZeerrnuLi5E").await.unwrap();
|
||||
let next_recommendations = details.recommended.next(rp.query()).await.unwrap().unwrap();
|
||||
dbg!(&next_recommendations);
|
||||
|
||||
assert!(
|
||||
next_recommendations.items.len() > 10,
|
||||
"expected > 10 next recommendations, got {}",
|
||||
next_recommendations.items.len()
|
||||
);
|
||||
assert!(!next_recommendations.is_exhausted());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_video_comments() {
|
||||
let rp = RustyPipe::builder().strict().build();
|
||||
let details = rp.query().video_details("ZeerrnuLi5E").await.unwrap();
|
||||
|
||||
let top_comments = details
|
||||
.top_comments
|
||||
.next(rp.query())
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert!(
|
||||
top_comments.items.len() > 10,
|
||||
"expected > 10 next comments, got {}",
|
||||
top_comments.items.len()
|
||||
);
|
||||
assert!(!top_comments.is_exhausted());
|
||||
|
||||
let n_comments = top_comments.count.unwrap();
|
||||
assert!(
|
||||
n_comments > 700000,
|
||||
"expected > 700k comments, got {}",
|
||||
n_comments
|
||||
);
|
||||
// Comment count should be exact after fetching first page
|
||||
assert!(n_comments % 1000 != 0);
|
||||
|
||||
let latest_comments = details
|
||||
.latest_comments
|
||||
.next(rp.query())
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert!(
|
||||
latest_comments.items.len() > 10,
|
||||
"expected > 10 next comments, got {}",
|
||||
latest_comments.items.len()
|
||||
);
|
||||
assert!(!latest_comments.is_exhausted());
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[case::mv("mv", "ZeerrnuLi5E")]
|
||||
#[case::music("music", "XuM2onMGvTI")]
|
||||
|
|
|
|||
Reference in a new issue