Skip to content

Commit

Permalink
Refactor test_db.rs: Add create_new_stream function
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaiSch committed Feb 1, 2024
1 parent 30b5b07 commit e9b78d5
Showing 1 changed file with 14 additions and 129 deletions.
143 changes: 14 additions & 129 deletions tests/test_db.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::Error;
use chrono::NaiveDateTime;
use diesel::SqliteConnection;
use diesel::{sqlite::Sqlite, SqliteConnection};
use scraper::db::{
self,
helpers::{self, create_stream},
Expand All @@ -13,12 +14,8 @@ fn test_create_stream() -> Result<SqliteConnection, anyhow::Error> {
common::create_db()
}


#[test]
fn test_get_home_team() -> Result<(), anyhow::Error> {
let mut test_db = test_create_stream()?;

let new_stream = StreamNew {
fn create_new_stream(conn: &mut SqliteConnection) -> Result<(), Error> {
let stream = StreamNew {
home: "Arsenal",
away: "Chelsea",
sport: "Football",
Expand All @@ -29,7 +26,16 @@ fn test_get_home_team() -> Result<(), anyhow::Error> {
url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
};

create_stream(&mut test_db, &new_stream)?;
create_stream(conn, &stream)?;

Ok(())
}

#[test]
fn test_get_home_team() -> Result<(), anyhow::Error> {
let mut test_db = test_create_stream()?;

create_new_stream(&mut test_db)?;

let streams = dbg!(helpers::get_streams_by_home_team(&mut test_db, "Arsenal".to_string())?);

Expand All @@ -43,124 +49,3 @@ fn test_get_home_team() -> Result<(), anyhow::Error> {

Ok(())
}

// #[test]
// fn test_get_away_team() -> Result<(), anyhow::Error> {
// let mut test_db = test_create_stream()?;

// let new_stream = StreamNew {
// home: "Arsenal",
// away: "Chelsea",
// sport: "Football",
// start_time: NaiveDateTime::from_timestamp_opt(1612128000, 0).unwrap(),
// stream_link: "https://www.youtube.com/watch?v=dQw4w9WgXcQ,https://www.youtube.com/watch?v=dQw4w9WgXcQ",
// country: "England",
// league: "Premier League",
// url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
// };

// create_stream(&mut test_db, &new_stream)?;

// let streams = helpers::get_streams_by_away_team(&mut test_db, "Chelsea".to_string())?;

// assert_eq!(streams.len(), 1);


// assert_eq!(streams[0].away, "Chelsea");

// helpers::delete_all_streams(&mut test_db)?;

// assert_eq!(helpers::get_streams(&mut test_db)?.len(), 0);

// Ok(())
// }

// #[test]
// fn test_get_sport() -> Result<(), anyhow::Error> {
// let mut test_db = test_create_stream()?;

// let new_stream = StreamNew {
// home: "Arsenal",
// away: "Chelsea",
// sport: "Football",
// start_time: NaiveDateTime::from_timestamp_opt(1612128000, 0).unwrap(),
// stream_link: "https://www.youtube.com/watch?v=dQw4w9WgXcQ,https://www.youtube.com/watch?v=dQw4w9WgXcQ",
// country: "England",
// league: "Premier League",
// url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
// };

// create_stream(&mut test_db, &new_stream)?;

// let streams = helpers::get_streams_by_sport(&mut test_db, "Football".to_string())?;

// assert_eq!(streams.len(), 1);

// assert_eq!(streams[0].sport, "Football");

// helpers::delete_all_streams(&mut test_db)?;

// assert_eq!(helpers::get_streams(&mut test_db)?.len(), 0);

// Ok(())
// }

// #[test]
// fn test_get_streams() -> Result<(), anyhow::Error> {
// let mut test_db = test_create_stream()?;

// let new_stream = StreamNew {
// home: "Arsenal",
// away: "Chelsea",
// sport: "Football",
// start_time: NaiveDateTime::from_timestamp_opt(1612128000, 0).unwrap(),
// stream_link: "https://www.youtube.com/watch?v=dQw4w9WgXcQ,https://www.youtube.com/watch?v=dQw4w9WgXcQ",
// country: "England",
// league: "Premier League",
// url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
// };

// create_stream(&mut test_db, &new_stream)?;

// let streams = helpers::get_streams(&mut test_db)?;

// assert_eq!(streams.len(), 1);

// assert_eq!(streams[0].sport, "Football");

// helpers::delete_all_streams(&mut test_db)?;

// assert_eq!(helpers::get_streams(&mut test_db)?.len(), 0);

// Ok(())
// }

// #[test]
// fn test_get_streams_by_id() -> Result<(), anyhow::Error> {
// let mut test_db = test_create_stream()?;

// let new_stream = StreamNew {
// home: "Arsenal",
// away: "Chelsea",
// sport: "Football",
// start_time: NaiveDateTime::from_timestamp_opt(1612128000, 0).unwrap(),
// stream_link: "https://www.youtube.com/watch?v=dQw4w9WgXcQ,https://www.youtube.com/watch?v=dQw4w9WgXcQ",
// country: "England",
// league: "Premier League",
// url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
// };

// create_stream(&mut test_db, &new_stream)?;

// let streams = helpers::get_streams_by_id(&mut test_db, 1)?;

// assert_eq!(streams.len(), 1);

// assert_eq!(streams[0].sport, "Football");

// helpers::delete_all_streams(&mut test_db)?;

// assert_eq!(helpers::get_streams(&mut test_db)?.len(), 0);

// Ok(())
// }

0 comments on commit e9b78d5

Please sign in to comment.