Skip to content

Commit

Permalink
fix(sonarr): Pass events alongside all GetLogs events when publishing…
Browse files Browse the repository at this point in the history
… to the networking channel
  • Loading branch information
Dark-Alex-17 committed Dec 18, 2024
1 parent 64ecc38 commit 924f8d5
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 81 deletions.
2 changes: 1 addition & 1 deletion src/app/sonarr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 148,7 @@ impl<'a> App<'a> {
.dispatch_network_event(SonarrEvent::GetQueuedEvents.into())
.await;
self
.dispatch_network_event(SonarrEvent::GetLogs(None).into())
.dispatch_network_event(SonarrEvent::GetLogs(500).into())
.await;
}
ActiveSonarrBlock::AddSeriesSearchResults => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/sonarr/sonarr_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 465,7 @@ mod tests {
);
assert_eq!(
sync_network_rx.recv().await.unwrap(),
SonarrEvent::GetLogs(None).into()
SonarrEvent::GetLogs(500).into()
);
assert!(!app.data.sonarr_data.prompt_confirm);
assert_eq!(app.tick_count, 0);
Expand Down
2 changes: 1 addition & 1 deletion src/cli/sonarr/list_command_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 208,7 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrListCommand> for SonarrListCommandH
} => {
let logs = self
.network
.handle_network_event(SonarrEvent::GetLogs(Some(events)).into())
.handle_network_event(SonarrEvent::GetLogs(events).into())
.await?;

if output_in_log_format {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/sonarr/list_command_handler_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 407,7 @@ mod tests {
mock_network
.expect_handle_network_event()
.with(eq::<NetworkEvent>(
SonarrEvent::GetLogs(Some(expected_events)).into(),
SonarrEvent::GetLogs(expected_events).into(),
))
.times(1)
.returning(|_| {
Expand Down
9 changes: 3 additions & 6 deletions src/network/sonarr_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 64,7 @@ pub enum SonarrEvent {
GetEpisodeFiles(i64),
GetEpisodeHistory(i64),
GetLanguageProfiles,
GetLogs(Option<u64>),
GetLogs(u64),
GetDiskSpace,
GetQualityProfiles,
GetQueuedEvents,
Expand Down Expand Up @@ -1502,14 1502,11 @@ impl<'a, 'b> Network<'a, 'b> {
.await
}

async fn get_sonarr_logs(&mut self, events: Option<u64>) -> Result<LogResponse> {
async fn get_sonarr_logs(&mut self, events: u64) -> Result<LogResponse> {
info!("Fetching Sonarr logs");
let event = SonarrEvent::GetLogs(events);

let params = format!(
"pageSize={}&sortDirection=descending&sortKey=time",
events.unwrap_or(500)
);
let params = format!("pageSize={}&sortDirection=descending&sortKey=time", events);
let request_props = self
.request_props_from(event, RequestMethod::Get, None::<()>, None, Some(params))
.await;
Expand Down
74 changes: 3 additions & 71 deletions src/network/sonarr_network_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 280,7 @@ mod test {
#[case(SonarrEvent::GetBlocklist, "/blocklist?page=1&pageSize=10000")]
#[case(SonarrEvent::GetDiskSpace, "/diskspace")]
#[case(SonarrEvent::GetLanguageProfiles, "/language")]
#[case(SonarrEvent::GetLogs(Some(500)), "/log")]
#[case(SonarrEvent::GetLogs(500), "/log")]
#[case(SonarrEvent::GetQualityProfiles, "/qualityprofile")]
#[case(SonarrEvent::GetStatus, "/system/status")]
#[case(SonarrEvent::GetTasks, "/system/task")]
Expand Down Expand Up @@ -3188,83 3188,15 @@ mod test {
None,
Some(logs_response_json),
None,
SonarrEvent::GetLogs(None),
SonarrEvent::GetLogs(500),
None,
Some("pageSize=500&sortDirection=descending&sortKey=time"),
)
.await;
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());

if let SonarrSerdeable::LogResponse(logs) = network
.handle_sonarr_event(SonarrEvent::GetLogs(None))
.await
.unwrap()
{
async_server.assert_async().await;
assert_eq!(
app_arc.lock().await.data.sonarr_data.logs.items,
expected_logs
);
assert!(app_arc
.lock()
.await
.data
.sonarr_data
.logs
.current_selection()
.text
.contains("INFO"));
assert_eq!(logs, response);
}
}

#[tokio::test]
async fn test_handle_get_sonarr_logs_event_uses_provided_events() {
let expected_logs = vec![
HorizontallyScrollableText::from(
"2023-05-20 21:29:16 UTC|FATAL|SonarrError|Some.Big.Bad.Exception|test exception",
),
HorizontallyScrollableText::from("2023-05-20 21:29:16 UTC|INFO|TestLogger|test message"),
];
let logs_response_json = json!({
"page": 1,
"pageSize": 1000,
"sortKey": "time",
"sortDirection": "descending",
"totalRecords": 2,
"records": [
{
"time": "2023-05-20T21:29:16Z",
"level": "info",
"logger": "TestLogger",
"message": "test message",
"id": 1
},
{
"time": "2023-05-20T21:29:16Z",
"level": "fatal",
"logger": "SonarrError",
"exception": "test exception",
"exceptionType": "Some.Big.Bad.Exception",
"id": 2
}
]
});
let response: LogResponse = serde_json::from_value(logs_response_json.clone()).unwrap();
let (async_server, app_arc, _server) = mock_servarr_api(
RequestMethod::Get,
None,
Some(logs_response_json),
None,
SonarrEvent::GetLogs(Some(1000)),
None,
Some("pageSize=1000&sortDirection=descending&sortKey=time"),
)
.await;
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());

if let SonarrSerdeable::LogResponse(logs) = network
.handle_sonarr_event(SonarrEvent::GetLogs(Some(1000)))
.handle_sonarr_event(SonarrEvent::GetLogs(500))
.await
.unwrap()
{
Expand Down

0 comments on commit 924f8d5

Please sign in to comment.