feat: Added support for a system-wide notification popup mechanism that works across Servarrs
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::models::lidarr_models::LidarrReleaseDownloadBody;
|
||||
use crate::models::servarr_data::Notification;
|
||||
use crate::network::lidarr_network::LidarrEvent;
|
||||
use crate::network::network_tests::test_utils::{MockServarrApi, test_network};
|
||||
use crate::network::network_tests::test_utils::{test_network, MockServarrApi};
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::json;
|
||||
|
||||
#[tokio::test]
|
||||
@@ -30,5 +32,51 @@ mod tests {
|
||||
|
||||
mock.assert_async().await;
|
||||
assert_ok!(result);
|
||||
assert_eq!(
|
||||
app.lock().await.notification,
|
||||
Some(Notification::new(
|
||||
"Download Result".to_owned(),
|
||||
"Download request sent successfully".to_owned(),
|
||||
true,
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_handle_download_lidarr_release_event_sets_failure_notification_on_error() {
|
||||
let params = LidarrReleaseDownloadBody {
|
||||
guid: "1234".to_owned(),
|
||||
indexer_id: 2,
|
||||
};
|
||||
|
||||
let (mock, app, _server) = MockServarrApi::post()
|
||||
.with_request_body(json!({
|
||||
"guid": "1234",
|
||||
"indexerId": 2,
|
||||
}))
|
||||
.returns(json!({}))
|
||||
.status(500)
|
||||
.build_for(LidarrEvent::DownloadRelease(params.clone()))
|
||||
.await;
|
||||
|
||||
app.lock().await.server_tabs.set_index(2);
|
||||
let mut network = test_network(&app);
|
||||
|
||||
let result = network
|
||||
.handle_lidarr_event(LidarrEvent::DownloadRelease(params))
|
||||
.await;
|
||||
|
||||
mock.assert_async().await;
|
||||
assert_err!(result);
|
||||
let app = app.lock().await;
|
||||
assert_is_empty!(app.error.text);
|
||||
assert_some_eq_x!(
|
||||
&app.notification,
|
||||
&Notification::new(
|
||||
"Download Failed".to_owned(),
|
||||
"Download request failed. Check the logs for more details.".to_owned(),
|
||||
false,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::models::lidarr_models::LidarrReleaseDownloadBody;
|
||||
use crate::models::servarr_data::Notification;
|
||||
use crate::network::lidarr_network::LidarrEvent;
|
||||
use crate::network::{Network, RequestMethod};
|
||||
use anyhow::Result;
|
||||
@@ -31,8 +32,26 @@ impl Network<'_, '_> {
|
||||
)
|
||||
.await;
|
||||
|
||||
self
|
||||
.handle_request::<LidarrReleaseDownloadBody, Value>(request_props, |_, _| ())
|
||||
.await
|
||||
let result = self
|
||||
.handle_request::<LidarrReleaseDownloadBody, Value>(request_props, |_, mut app| {
|
||||
app.notification = Some(Notification::new(
|
||||
"Download Result".to_owned(),
|
||||
"Download request sent successfully".to_owned(),
|
||||
true,
|
||||
));
|
||||
})
|
||||
.await;
|
||||
|
||||
if result.is_err() {
|
||||
let mut app = self.app.lock().await;
|
||||
std::mem::take(&mut app.error.text);
|
||||
app.notification = Some(Notification::new(
|
||||
"Download Failed".to_owned(),
|
||||
"Download request failed. Check the logs for more details.".to_owned(),
|
||||
false,
|
||||
));
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user