yt_transcript_rs/tests/
test_utils.rs

1#[cfg(not(feature = "ci"))]
2use reqwest::Client;
3use std::sync::Once;
4
5use crate::api::YouTubeTranscriptApi;
6
7static INIT: Once = Once::new();
8
9/// Setup function that runs once before all tests
10pub fn setup() {
11    INIT.call_once(|| {
12        // Initialize any global settings here
13    });
14}
15
16/// Create a test instance of the YouTubeTranscriptApi
17///
18/// When in GitHub Actions or other CI environments, this will use mock data
19/// instead of making real API calls to YouTube
20#[cfg(feature = "ci")]
21pub fn create_api() -> YouTubeTranscriptApi {
22    // When running in CI, use the mock client
23    let client = super::mocks::create_mock_client();
24
25    YouTubeTranscriptApi::new(None, None, Some(client)).unwrap()
26}
27
28#[cfg(not(feature = "ci"))]
29pub fn create_api() -> YouTubeTranscriptApi {
30    // For local development, use a real client
31    let client = Client::builder()
32        .user_agent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36")
33        .build()
34        .unwrap();
35
36    YouTubeTranscriptApi::new(None, None, Some(client)).unwrap()
37}
38
39/// Video ID with transcripts available in multiple languages
40pub const MULTILANG_VIDEO_ID: &str = "arj7oStGLkU"; // Ted talk with multiple languages
41
42/// Video ID with only auto-generated transcripts
43pub const AUTOGENERATED_VIDEO_ID: &str = "";
44
45/// Video ID with manually created transcripts
46pub const MANUAL_VIDEO_ID: &str = "";
47
48/// Non-existing video ID
49pub const NON_EXISTENT_VIDEO_ID: &str = "xxxxxxxxxxx";
50
51/// Age-restricted video ID
52pub const AGE_RESTRICTED_VIDEO_ID: &str = "";
53
54/// Video ID with disabled transcripts
55pub const DISABLED_TRANSCRIPTS_VIDEO_ID: &str = "";