From 55518ef65091ff6052d7e5506b79eab447c33c71 Mon Sep 17 00:00:00 2001 From: realaravinth Date: Thu, 12 May 2022 19:31:26 +0530 Subject: [PATCH] feat: define captcha_exists interface --- Makefile | 2 +- db/db-core/src/lib.rs | 7 +++++++ db/db-core/src/tests.rs | 8 +++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 026cfaeb..7745649b 100644 --- a/Makefile +++ b/Makefile @@ -96,7 +96,7 @@ test: frontend-test frontend ## Run all available tests cd db/db-sqlx-postgres &&\ DATABASE_URL=${POSTGRES_DATABASE_URL}\ cargo test --no-fail-fast - #./scripts/tests.sh + ./scripts/tests.sh # cargo test --all-features --no-fail-fast xml-test-coverage: migrate ## Generate code coverage report in XML format diff --git a/db/db-core/src/lib.rs b/db/db-core/src/lib.rs index 04016a12..963af8e3 100644 --- a/db/db-core/src/lib.rs +++ b/db/db-core/src/lib.rs @@ -144,6 +144,13 @@ pub trait MCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase { captcha_key: &str, levels: &[Level], ) -> DBResult<()>; + + /// check if captcha exists + async fn captcha_exists( + &self, + username: Option<&str>, + captcha_key: &str, + ) -> DBResult; } #[derive(Clone, Debug, Default, Deserialize, Serialize)] diff --git a/db/db-core/src/tests.rs b/db/db-core/src/tests.rs index 8a5f7c48..85b7e800 100644 --- a/db/db-core/src/tests.rs +++ b/db/db-core/src/tests.rs @@ -35,12 +35,12 @@ pub async fn database_works<'a, T: MCDatabase>( db.register(p).await.unwrap(); // 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"); // testing update secret: setting secret = username 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!( secret.secret, p.username, "user secret matches username; as set by previous step" @@ -131,6 +131,8 @@ pub async fn database_works<'a, T: MCDatabase>( "user was with empty email but email is set; so email should exsit" ); - db.create_captcha(&p.username, c).await.unwrap(); + db.create_captcha(p.username, c).await.unwrap(); + assert!(db.captcha_exists(None, c.key).await.unwrap()); + assert!(db.captcha_exists(Some(p.username), c.key).await.unwrap()); db.add_captcha_levels(p.username, c.key, l).await.unwrap(); }