Bug: [FEATURE] Implement `EventInterface` for `MockDb`



Spin out from https://github.com/juspay/hyperswitch/issues/172. Please refer to that issue for more information.
diff --git a/crates/router/src/db.rs b/crates/router/src/db.rs
index ee9cd03e692..a260f016dc8 100644
--- a/crates/router/src/db.rs
+++ b/crates/router/src/db.rs
@@ -85,6 +85,7 @@ pub struct MockDb {
     redis: Arc<redis_interface::RedisConnectionPool>,
     api_keys: Arc<Mutex<Vec<storage::ApiKey>>>,
     cards_info: Arc<Mutex<Vec<storage::CardInfo>>>,
+    events: Arc<Mutex<Vec<storage::Event>>>,
 }
 
 impl MockDb {
@@ -102,6 +103,7 @@ impl MockDb {
             redis: Arc::new(crate::connection::redis_connection(redis).await),
             api_keys: Default::default(),
             cards_info: Default::default(),
+            events: Default::default(),
         }
     }
 }
diff --git a/crates/router/src/db/events.rs b/crates/router/src/db/events.rs
index aed2f285bfb..8148f2a8a8b 100644
--- a/crates/router/src/db/events.rs
+++ b/crates/router/src/db/events.rs
@@ -46,16 +46,94 @@ impl EventInterface for Store {
 impl EventInterface for MockDb {
     async fn insert_event(
         &self,
-        _event: storage::EventNew,
+        event: storage::EventNew,
     ) -> CustomResult<storage::Event, errors::StorageError> {
-        // [#172]: Implement function for `MockDb`
-        Err(errors::StorageError::MockDbError)?
+        let mut locked_events = self.events.lock().await;
+        let now = common_utils::date_time::now();
+
+        let stored_event = storage::Event {
+            #[allow(clippy::as_conversions)]
+            id: locked_events.len() as i32,
+            event_id: event.event_id,
+            event_type: event.event_type,
+            event_class: event.event_class,
+            is_webhook_notified: event.is_webhook_notified,
+            intent_reference_id: event.intent_reference_id,
+            primary_object_id: event.primary_object_id,
+            primary_object_type: event.primary_object_type,
+            created_at: now,
+        };
+
+        locked_events.push(stored_event.clone());
+
+        Ok(stored_event)
     }
     async fn update_event(
         &self,
-        _event_id: String,
-        _event: storage::EventUpdate,
+        event_id: String,
+        event: storage::EventUpdate,
     ) -> CustomResult<storage::Event, errors::StorageError> {
-        Err(errors::StorageError::MockDbError)?
+        let mut locked_events = self.events.lock().await;
+        let mut event_to_update = locked_events
+            .iter_mut()
+            .find(|e| e.event_id == event_id)
+            .ok_or(errors::StorageError::MockDbError)?;
+
+        match event {
+            storage::EventUpdate::UpdateWebhookNotified {
+                is_webhook_notified,
+            } => {
+                if let Some(is_webhook_notified) = is_webhook_notified {
+                    event_to_update.is_webhook_notified = is_webhook_notified;
+                }
+            }
+        }
+
+        Ok(event_to_update.clone())
+    }
+}
+
+#[cfg(test)]
+mod tests {
+    use storage_models::enums;
+
+    use crate::{
+        db::{events::EventInterface, MockDb},
+        types::storage,
+    };
+
+    #[allow(clippy::unwrap_used)]
+    #[tokio::test]
+    async fn test_mockdb_event_interface() {
+        let mockdb = MockDb::new(&Default::default()).await;
+
+        let event1 = mockdb
+            .insert_event(storage::EventNew {
+                event_id: "test_event_id".into(),
+                event_type: enums::EventType::PaymentSucceeded,
+                event_class: enums::EventClass::Payments,
+                is_webhook_notified: false,
+                intent_reference_id: Some("test".into()),
+                primary_object_id: "primary_object_tet".into(),
+                primary_object_type: enums::EventObjectType::PaymentDetails,
+            })
+            .await
+            .unwrap();
+
+        assert_eq!(event1.id, 0);
+
+        let updated_event = mockdb
+            .update_event(
+                "test_event_id".into(),
+                storage::EventUpdate::UpdateWebhookNotified {
+                    is_webhook_notified: Some(true),
+                },
+            )
+            .await
+            .unwrap();
+
+        assert!(updated_event.is_webhook_notified);
+        assert_eq!(updated_event.primary_object_id, "primary_object_tet");
+        assert_eq!(updated_event.id, 0);
     }
 }

## Type of Change
<!-- Put an `x` in the boxes that apply -->

- [ ] Bugfix
- [ ] New feature
- [x] Enhancement
- [ ] Refactoring
- [ ] Dependency updates
- [ ] Documentation
- [ ] CI/CD

## Description
<!-- Describe your changes in detail -->


### Additional Changes

- [ ] This PR modifies the API contract
- [ ] This PR modifies the database schema
- [ ] This PR modifies application configuration/environment variables

<!-- 
Provide links to the files with corresponding changes.

Following are the paths where you can find config files:
1. `config`
2. `crates/router/src/configs`
3. `loadtest/config`
-->


## Motivation and Context
<!--
Why is this change required? What problem does it solve?
If it fixes an open issue, please link to the issue here.

If you don't have an issue, we'd recommend starting with one first so the PR
can focus on the implementation (unless its an obvious bug or documentation fix
that will have little conversation).
-->
Closes #1116.

## How did you test it?
<!--
Did you write an integration/unit/API test to verify the code changes?
Or did you test this change manually (provide relevant screenshots)?
-->


## Checklist
<!-- Put an `x` in the boxes that apply -->

- [x] I formatted the code `cargo +nightly fmt --all`
- [x] I addressed lints thrown by `cargo clippy`
- [x] I reviewed submitted code
- [x] I added unit tests for my changes where possible
- [ ] I added a [CHANGELOG](/CHANGELOG.md) entry if applicable
