feat: add checks to verify the DB error situations

This commit is contained in:
realaravinth 2022-07-23 15:50:25 +05:30
parent d5b17ac00e
commit 337a378b08
No known key found for this signature in database
GPG Key ID: AD9F0F08E855ED88

View File

@ -28,6 +28,7 @@ pub async fn database_works<'a, T: MCDatabase>(
an: &AddNotification<'a>, an: &AddNotification<'a>,
) { ) {
assert!(db.ping().await, "ping test"); assert!(db.ping().await, "ping test");
if db.username_exists(p.username).await.unwrap() { if db.username_exists(p.username).await.unwrap() {
db.delete_user(p.username).await.unwrap(); db.delete_user(p.username).await.unwrap();
assert!( assert!(
@ -35,14 +36,23 @@ pub async fn database_works<'a, T: MCDatabase>(
"user is deleted so username shouldn't exsit" "user is deleted so username shouldn't exsit"
); );
} }
assert!(matches!(
db.get_secret(&p.username).await,
Err(DBError::AccountNotFound)
));
db.register(p).await.unwrap(); db.register(p).await.unwrap();
assert!(matches!(db.register(&p).await, Err(DBError::UsernameTaken)));
// testing get secret // testing get secret
let secret = db.get_secret(p.username).await.unwrap(); let secret = db.get_secret(p.username).await.unwrap();
assert_eq!(secret.secret, p.secret, "user secret matches"); assert_eq!(secret.secret, p.secret, "user secret matches");
// testing update secret: setting secret = username // testing update secret: setting secret = username
db.update_secret(p.username, p.username).await.unwrap(); db.update_secret(p.username, p.username).await.unwrap();
let secret = db.get_secret(p.username).await.unwrap(); let secret = db.get_secret(p.username).await.unwrap();
assert_eq!( assert_eq!(
secret.secret, p.username, secret.secret, p.username,