feat: db: pg: adapter to delete verification secret
This commit is contained in:
parent
1da8f791b4
commit
fbb5435d3c
1 changed files with 76 additions and 0 deletions
|
@ -0,0 +1,76 @@
|
||||||
|
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
use super::DBOutPostgresAdapter;
|
||||||
|
use crate::identity::application::port::output::db::{delete_verification_secret::*, errors::*};
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
impl DeleteVerificationSecretOutDBPort for DBOutPostgresAdapter {
|
||||||
|
async fn delete_verification_secret(&self, msg: &DeleteSecretMsg) -> OutDBPortResult<()> {
|
||||||
|
sqlx::query!(
|
||||||
|
"DELETE FROM
|
||||||
|
verification_otp
|
||||||
|
WHERE
|
||||||
|
username = $1
|
||||||
|
AND
|
||||||
|
purpose = $2
|
||||||
|
AND
|
||||||
|
secret = $3;",
|
||||||
|
msg.username,
|
||||||
|
REGISTRATION_SECRET_PURPOSE,
|
||||||
|
msg.secret,
|
||||||
|
)
|
||||||
|
.execute(&self.pool)
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use crate::identity::application::port::output::db::{
|
||||||
|
create_verification_secret::*, verification_secret_exists::*,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn test_postgres_delete_verification_secret() {
|
||||||
|
let username = "batman";
|
||||||
|
let secret = "bsdasdf";
|
||||||
|
let settings = crate::settings::tests::get_settings().await;
|
||||||
|
let db = super::DBOutPostgresAdapter::new(
|
||||||
|
sqlx::postgres::PgPool::connect(&settings.database.url)
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
let msg = VerifySecretExistsMsgBuilder::default()
|
||||||
|
.username(username.into())
|
||||||
|
.secret(secret.into())
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
// state doesn't exist
|
||||||
|
assert!(!db.verification_secret_exists(&msg).await.unwrap());
|
||||||
|
|
||||||
|
let create_msg = CreateSecretMsgBuilder::default()
|
||||||
|
.secret(secret.into())
|
||||||
|
.username(username.into())
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
db.create_verification_secret(create_msg).await.unwrap();
|
||||||
|
|
||||||
|
// state exists
|
||||||
|
assert!(db.verification_secret_exists(&msg).await.unwrap());
|
||||||
|
|
||||||
|
// delete secret
|
||||||
|
db.delete_verification_secret(&msg.clone().into())
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
// state doens't exist
|
||||||
|
assert!(!db.verification_secret_exists(&msg).await.unwrap());
|
||||||
|
|
||||||
|
settings.drop_db().await;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue