feat: Added support for a system-wide notification popup mechanism that works across Servarrs
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use crate::models::servarr_data::Notification;
|
||||
use crate::models::sonarr_models::SonarrReleaseDownloadBody;
|
||||
use crate::network::sonarr_network::SonarrEvent;
|
||||
use crate::network::{Network, RequestMethod};
|
||||
@@ -31,8 +32,26 @@ impl Network<'_, '_> {
|
||||
)
|
||||
.await;
|
||||
|
||||
self
|
||||
.handle_request::<SonarrReleaseDownloadBody, Value>(request_props, |_, _| ())
|
||||
.await
|
||||
let result = self
|
||||
.handle_request::<SonarrReleaseDownloadBody, 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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::models::servarr_data::Notification;
|
||||
use crate::models::sonarr_models::SonarrReleaseDownloadBody;
|
||||
use crate::network::network_tests::test_utils::{MockServarrApi, test_network};
|
||||
use crate::network::network_tests::test_utils::{test_network, MockServarrApi};
|
||||
use crate::network::sonarr_network::SonarrEvent;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::json;
|
||||
|
||||
#[tokio::test]
|
||||
@@ -33,5 +35,54 @@ 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_sonarr_release_event_sets_failure_notification_on_error() {
|
||||
let params = SonarrReleaseDownloadBody {
|
||||
guid: "1234".to_owned(),
|
||||
indexer_id: 2,
|
||||
series_id: Some(1),
|
||||
..SonarrReleaseDownloadBody::default()
|
||||
};
|
||||
|
||||
let (mock, app, _server) = MockServarrApi::post()
|
||||
.with_request_body(json!({
|
||||
"guid": "1234",
|
||||
"indexerId": 2,
|
||||
"seriesId": 1,
|
||||
}))
|
||||
.returns(json!({}))
|
||||
.status(500)
|
||||
.build_for(SonarrEvent::DownloadRelease(params.clone()))
|
||||
.await;
|
||||
|
||||
app.lock().await.server_tabs.next();
|
||||
let mut network = test_network(&app);
|
||||
|
||||
let result = network
|
||||
.handle_sonarr_event(SonarrEvent::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,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user