feat(db): Implement ReverseLookupInterface for MockDb (#2119)

This commit is contained in:
Hudson C. Dalprá
2023-09-12 21:46:18 +12:00
committed by GitHub
parent d52fe7f140
commit f2df2d6d01
3 changed files with 34 additions and 4 deletions

View File

@ -31,3 +31,14 @@ pub struct ReverseLookupNew {
pub sk_id: String,
pub source: String,
}
impl From<ReverseLookupNew> for ReverseLookup {
fn from(new: ReverseLookupNew) -> Self {
Self {
lookup_id: new.lookup_id,
sk_id: new.sk_id,
pk_id: new.pk_id,
source: new.source,
}
}
}

View File

@ -48,14 +48,31 @@ impl ReverseLookupInterface for Store {
impl ReverseLookupInterface for MockDb {
async fn insert_reverse_lookup(
&self,
_new: ReverseLookupNew,
new: ReverseLookupNew,
) -> CustomResult<ReverseLookup, errors::StorageError> {
Err(errors::StorageError::MockDbError.into())
let reverse_lookup_insert = ReverseLookup::from(new);
self.reverse_lookups
.lock()
.await
.push(reverse_lookup_insert.clone());
Ok(reverse_lookup_insert)
}
async fn get_lookup_by_lookup_id(
&self,
_id: &str,
lookup_id: &str,
) -> CustomResult<ReverseLookup, errors::StorageError> {
Err(errors::StorageError::MockDbError.into())
self.reverse_lookups
.lock()
.await
.iter()
.find(|reverse_lookup| reverse_lookup.lookup_id == lookup_id)
.ok_or(
errors::StorageError::ValueNotFound(format!(
"No reverse lookup found for lookup_id = {}",
lookup_id
))
.into(),
)
.cloned()
}
}

View File

@ -39,6 +39,7 @@ pub struct MockDb {
pub captures: Arc<Mutex<Vec<crate::store::capture::Capture>>>,
pub merchant_key_store: Arc<Mutex<Vec<crate::store::merchant_key_store::MerchantKeyStore>>>,
pub business_profiles: Arc<Mutex<Vec<crate::store::business_profile::BusinessProfile>>>,
pub reverse_lookups: Arc<Mutex<Vec<store::ReverseLookup>>>,
}
impl MockDb {
@ -70,6 +71,7 @@ impl MockDb {
captures: Default::default(),
merchant_key_store: Default::default(),
business_profiles: Default::default(),
reverse_lookups: Default::default(),
})
}
}