feat: add_user and user_exists with accompanying test suites
DESCRIPTION add_user Adds new user to DB. Implementers must ensure username uniqueness scoped at forge instance level. When applicable, HTML link to profile photo may be stored as we.. user_exists Checks if a user exists in database. Optionally provide hostname of forge instance to get forge-specific results.
This commit is contained in:
parent
b8be794c19
commit
5102531a70
2 changed files with 31 additions and 2 deletions
|
@ -40,6 +40,7 @@ pub mod ops;
|
||||||
#[cfg(feature = "test")]
|
#[cfg(feature = "test")]
|
||||||
pub mod tests;
|
pub mod tests;
|
||||||
|
|
||||||
|
use dev::*;
|
||||||
pub use ops::GetConnection;
|
pub use ops::GetConnection;
|
||||||
|
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
|
@ -65,7 +66,20 @@ pub struct CreateForge<'a> {
|
||||||
pub forge_type: ForgeImplementation,
|
pub forge_type: ForgeImplementation,
|
||||||
}
|
}
|
||||||
|
|
||||||
use dev::*;
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
/// add new user to database
|
||||||
|
pub struct AddUser<'a> {
|
||||||
|
/// hostname of the forge instance: with scheme but remove trailing slash
|
||||||
|
/// hostname can be derived from html_link also, but used to link to user's forge instance
|
||||||
|
pub hostname: &'a str,
|
||||||
|
/// username of the user
|
||||||
|
pub username: &'a str,
|
||||||
|
/// html link to the user profile
|
||||||
|
pub html_link: &'a str,
|
||||||
|
/// OPTIONAL: html link to the user's profile photo
|
||||||
|
pub profile_photo: Option<&'a str>,
|
||||||
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
/// Starchart's database requirements. To implement support for $Database, kindly implement this
|
/// Starchart's database requirements. To implement support for $Database, kindly implement this
|
||||||
/// trait.
|
/// trait.
|
||||||
|
@ -84,6 +98,13 @@ pub trait SCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase {
|
||||||
|
|
||||||
/// check if forge type exists
|
/// check if forge type exists
|
||||||
async fn forge_type_exists(&self, forge_type: &ForgeImplementation) -> DBResult<bool>;
|
async fn forge_type_exists(&self, forge_type: &ForgeImplementation) -> DBResult<bool>;
|
||||||
|
|
||||||
|
/// add new user to database
|
||||||
|
async fn add_user(&self, u: &AddUser) -> DBResult<()>;
|
||||||
|
|
||||||
|
/// check if an user exists. When hostname of a forge instace is provided, username search is
|
||||||
|
/// done only on that forge
|
||||||
|
async fn user_exists(&self, username: &str, hostname: Option<&str>) -> DBResult<bool>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Trait to clone SCDatabase
|
/// Trait to clone SCDatabase
|
||||||
|
|
|
@ -19,13 +19,21 @@
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
/// adding forge works
|
/// adding forge works
|
||||||
pub async fn adding_forge_works<T: SCDatabase>(db: &T, create_forge_msg: CreateForge<'static>) {
|
pub async fn adding_forge_works<T: SCDatabase>(
|
||||||
|
db: &T,
|
||||||
|
create_forge_msg: CreateForge<'static>,
|
||||||
|
add_user_msg: AddUser<'static>,
|
||||||
|
add_user_msg2: AddUser<'static>,
|
||||||
|
) {
|
||||||
let _ = db.delete_forge_instance(&create_forge_msg.hostname).await;
|
let _ = db.delete_forge_instance(&create_forge_msg.hostname).await;
|
||||||
db.create_forge_isntance(&create_forge_msg).await.unwrap();
|
db.create_forge_isntance(&create_forge_msg).await.unwrap();
|
||||||
assert!(
|
assert!(
|
||||||
db.forge_exists(create_forge_msg.hostname).await.unwrap(),
|
db.forge_exists(create_forge_msg.hostname).await.unwrap(),
|
||||||
"forge creation failed, forge existance check failure"
|
"forge creation failed, forge existance check failure"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
db.add_user(&add_user_msg).await.unwrap();
|
||||||
|
db.add_user(&add_user_msg2).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// test if all forge type implementations are loaded into DB
|
/// test if all forge type implementations are loaded into DB
|
||||||
|
|
Loading…
Reference in a new issue