feat: define interface for updating captcha metadata

This commit is contained in:
realaravinth 2022-05-12 20:09:18 +05:30
parent c458e4a233
commit 1e6a259d57
No known key found for this signature in database
GPG key ID: AD9F0F08E855ED88
2 changed files with 13 additions and 0 deletions

View file

@ -137,6 +137,13 @@ pub trait MCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase {
/// create new captcha
async fn create_captcha(&self, username: &str, p: &CreateCaptcha) -> DBResult<()>;
/// update captcha metadata; doesn't change captcha key
async fn update_captcha_metadata(
&self,
username: &str,
p: &CreateCaptcha,
) -> DBResult<()>;
/// Add levels to captcha
async fn add_captcha_levels(
&self,

View file

@ -142,6 +142,12 @@ pub async fn database_works<'a, T: MCDatabase>(
// delete captcha levels
db.delete_captcha_levels(p.username, c.key).await.unwrap();
// update captcha; set description = username and duration *= duration;
let mut c2 = c.clone();
c2.duration *= c2.duration;
c2.description = p.username;
db.update_captcha_metadata(p.username, &c2).await.unwrap();
// delete captcha
db.delete_captcha(p.username, c.key).await.unwrap();
assert!(!db.captcha_exists(Some(p.username), c.key).await.unwrap());