use topcoat::context::Cx;
pub(crate) fn cx() -> Cx {
Cx::default()
}
pub(crate) fn cx_with_cookie(name: &str, value: Option<&str>) -> Cx {
let mut parts = http::Request::builder()
.uri("/")
.body(())
.unwrap()
.into_parts()
.0;
if let Some(value) = value {
parts.headers.insert(
http::header::COOKIE,
format!("{name}={value}").parse().unwrap(),
);
}
Cx::default()
.with(parts)
.with(topcoat::cookie::CookieJarCell::new())
}
#[derive(Debug, Clone, toasty::Model, crate::ModelColumns)]
pub(crate) struct User {
#[key]
#[auto]
pub(crate) id: uuid::Uuid,
pub(crate) name: String,
}
#[derive(Debug, Clone, toasty::Model)]
pub(crate) struct DummyUser {
#[key]
#[auto]
pub(crate) id: uuid::Uuid,
pub(crate) name: String,
#[unique]
pub(crate) email: String,
}
pub(crate) fn panel_cx<R: crate::Resource>(db: &toasty::Db) -> Cx {
crate::Panel::new("admin")
.resource::<R>()
.handle(db)
.expect("panel builds")
.context()
}
pub(crate) fn mounted<R: crate::Resource>() -> std::sync::Arc<crate::resource::Mounted<R>> {
std::sync::Arc::new(crate::resource::Mounted::new(R::declare(), "/admin"))
}
pub(crate) async fn memory_db(models: toasty::schema::ModelSet) -> toasty::Db {
let db = toasty::Db::builder()
.models(models)
.connect("sqlite::memory:")
.await
.expect("connect to in-memory sqlite");
db.push_schema().await.expect("push the schema");
db
}
pub(crate) async fn tableless_db(models: toasty::schema::ModelSet) -> toasty::Db {
toasty::Db::builder()
.models(models)
.connect("sqlite::memory:")
.await
.expect("connect to in-memory sqlite")
}