Open source Nest implementation
mod common;
pub use common::*;

use nidobyte::database::Database;
use nidobyte::models::users::User;

#[tokio::test]
async fn user_from_basic_auth_test() {
    let client = common::testing_client().await;

    let mut req = client.get("/");
    let db: &rocket::State<Database> = req.guard().await.unwrap();

    let created_user = common::user(db).await;

    let credentials =
        http_auth_basic::Credentials::new(&created_user.name.clone(), common::TEST_USER_PASSWORD);
    req.add_header(rocket::http::Header::new(
        "Authorization",
        credentials.as_http_header(),
    ));

    use rocket::request::FromRequest;
    let user = User::from_request(&req).await;

    assert_eq!(created_user.id, user.unwrap().id);
}