use topcoat::context::Cx;
use super::*;
#[test]
fn tenant_extension_wins_over_scoped_value_and_defaults_to_none() {
let id = TenantId::from(uuid::Uuid::new_v4());
let other = TenantId::from(uuid::Uuid::new_v4());
let cx = Cx::default().with(Tenant(id));
assert_eq!(tenant_id(&cx), Some(id));
let cx = Cx::default()
.with({
let mut parts = http::Request::builder()
.uri("/")
.body(())
.unwrap()
.into_parts()
.0;
parts.extensions.insert(Tenant(id));
parts
})
.with(Tenant(other));
assert_eq!(tenant_id(&cx), Some(id));
let cx = Cx::default();
assert_eq!(tenant_id(&cx), None);
}
#[derive(Debug, Clone, toasty::Model)]
struct Scoped {
#[key]
#[auto]
id: uuid::Uuid,
tenant_id: TenantId,
name: String,
}