// Functions which are only really useful for the unit tests but which show up 
// constantly in the tests themselves

#[cfg(test)]
pub fn get_pool() -> mysql_async::Pool {
    use dotenv::dotenv;
    use mysql_async::Pool;

    dotenv().ok();
    return Pool::new(&std::env::var("DATABASE_URL").unwrap())
}

#[cfg(test)]
pub fn hyper_resp() -> hyper::Response<hyper::Body> {
    use hyper::{Response, Body};

    Response::new(Body::empty())
}



#[cfg(test)]
pub async fn tmp_channel_params(p: &mysql_async::Pool, chan_name: &'static str) -> crate::channels::Channel {
    use crate::channels::{Channel, ChannelType};
    use mysql_async::{params, prelude::Queryable};

    let conn = p.get_conn().await.unwrap();
    let _ = conn.prep_exec(
        "INSERT INTO channels (name, description, kind) VALUES (:name, :description, :kind)", 
        params!{"name" => chan_name, "kind" => 0, "description" => "no description for testing"}).await;

    Channel {
        id: 0,
        name: chan_name.into(),
        kind: ChannelType::Text,
        description: "no description for testing".into()
    }
}
