mirror of
https://github.com/Cleanuparr/Cleanuparr.git
synced 2026-10-28 10:48:49 -04:00
added quiet hours to seeker config api
This commit is contained in:
1 parent
176e2da5e5
commit
e060ee237b
4 files changed
+95
No files matched your search
@@ -1,6 +1,8 @@
|
||||
using System.Text.Json;
|
||||
using Cleanuparr.Api.Features.Seeker.Contracts.Requests;
|
||||
using Cleanuparr.Api.Features.Seeker.Contracts.Responses;
|
||||
using Cleanuparr.Api.Features.Seeker.Controllers;
|
||||
using Cleanuparr.Api.Json;
|
||||
using Cleanuparr.Api.Tests.Features.Seeker.TestHelpers;
|
||||
using Cleanuparr.Domain.Enums;
|
||||
using Cleanuparr.Domain.Exceptions;
|
||||
@@ -158,6 +160,25 @@ public class SeekerConfigControllerTests : IDisposable
|
||||
response.Instances.ShouldHaveSingleItem().SonarrSearchMode.ShouldBe(SonarrSearchMode.Episode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetSeekerConfig_WithQuietHours_ReturnsStoredValues()
|
||||
{
|
||||
SeekerTestDataFactory.AddRadarrInstance(_dataContext);
|
||||
SeekerConfig config = await _dataContext.SeekerConfigs.FirstAsync();
|
||||
config.QuietHoursEnabled = true;
|
||||
config.QuietHoursStart = new TimeOnly(22, 30);
|
||||
config.QuietHoursEnd = new TimeOnly(6, 15);
|
||||
await _dataContext.SaveChangesAsync();
|
||||
|
||||
IActionResult result = await _controller.GetSeekerConfig();
|
||||
OkObjectResult okResult = result.ShouldBeOfType<OkObjectResult>();
|
||||
SeekerConfigResponse response = okResult.Value.ShouldBeOfType<SeekerConfigResponse>();
|
||||
|
||||
response.QuietHoursEnabled.ShouldBeTrue();
|
||||
response.QuietHoursStart.ShouldBe(new TimeOnly(22, 30));
|
||||
response.QuietHoursEnd.ShouldBe(new TimeOnly(6, 15));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetSeekerConfig_OnlyReturnsSonarrAndRadarrInstances()
|
||||
{
|
||||
@@ -201,6 +222,62 @@ public class SeekerConfigControllerTests : IDisposable
|
||||
await Should.ThrowAsync<CustomValidationException>(() => _controller.UpdateSeekerConfig(request));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateSeekerConfig_WithQuietHours_PersistsValues()
|
||||
{
|
||||
ArrInstance radarr = SeekerTestDataFactory.AddRadarrInstance(_dataContext);
|
||||
UpdateSeekerConfigRequest request = new()
|
||||
{
|
||||
SearchEnabled = true,
|
||||
SearchInterval = 5,
|
||||
QuietHoursEnabled = true,
|
||||
QuietHoursStart = new TimeOnly(21, 0),
|
||||
QuietHoursEnd = new TimeOnly(8, 45),
|
||||
Instances = [new UpdateSeekerInstanceConfigRequest { ArrInstanceId = radarr.Id, Enabled = true }]
|
||||
};
|
||||
|
||||
await _controller.UpdateSeekerConfig(request);
|
||||
|
||||
SeekerConfig saved = await _dataContext.SeekerConfigs.AsNoTracking().FirstAsync();
|
||||
saved.QuietHoursEnabled.ShouldBeTrue();
|
||||
saved.QuietHoursStart.ShouldBe(new TimeOnly(21, 0));
|
||||
saved.QuietHoursEnd.ShouldBe(new TimeOnly(8, 45));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateSeekerConfig_WithEqualQuietHours_ThrowsValidationException()
|
||||
{
|
||||
ArrInstance radarr = SeekerTestDataFactory.AddRadarrInstance(_dataContext);
|
||||
UpdateSeekerConfigRequest request = new()
|
||||
{
|
||||
SearchEnabled = true,
|
||||
SearchInterval = 5,
|
||||
QuietHoursEnabled = true,
|
||||
QuietHoursStart = new TimeOnly(7, 0),
|
||||
QuietHoursEnd = new TimeOnly(7, 0),
|
||||
Instances = [new UpdateSeekerInstanceConfigRequest { ArrInstanceId = radarr.Id, Enabled = true }]
|
||||
};
|
||||
|
||||
await Should.ThrowAsync<CustomValidationException>(() => _controller.UpdateSeekerConfig(request));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("23:00")]
|
||||
[InlineData("23:00:00")]
|
||||
public void UpdateSeekerConfigRequest_DeserializesQuietHoursWithOrWithoutSeconds(string time)
|
||||
{
|
||||
JsonSerializerOptions options = new();
|
||||
CleanuparrJsonConfiguration.ConfigureApiInbound(options);
|
||||
|
||||
UpdateSeekerConfigRequest? request = JsonSerializer.Deserialize<UpdateSeekerConfigRequest>(
|
||||
$"{{\"quietHoursEnabled\":true,\"quietHoursStart\":\"{time}\",\"quietHoursEnd\":\"07:00\"}}",
|
||||
options);
|
||||
|
||||
request.ShouldNotBeNull();
|
||||
request.QuietHoursStart.ShouldBe(new TimeOnly(23, 0));
|
||||
request.QuietHoursEnd.ShouldBe(new TimeOnly(7, 0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateSeekerConfig_WhenIntervalChanges_ReschedulesSeeker()
|
||||
{
|
||||
|
||||
+9
@@ -17,6 +17,12 @@ public sealed record UpdateSeekerConfigRequest
|
||||
|
||||
public int PostReleaseGraceHours { get; init; } = 6;
|
||||
|
||||
public bool QuietHoursEnabled { get; init; }
|
||||
|
||||
public TimeOnly QuietHoursStart { get; init; } = new(23, 0);
|
||||
|
||||
public TimeOnly QuietHoursEnd { get; init; } = new(7, 0);
|
||||
|
||||
public List<UpdateSeekerInstanceConfigRequest> Instances { get; init; } = [];
|
||||
|
||||
public SeekerConfig ApplyTo(SeekerConfig config)
|
||||
@@ -27,6 +33,9 @@ public sealed record UpdateSeekerConfigRequest
|
||||
config.SelectionStrategy = SelectionStrategy;
|
||||
config.UseRoundRobin = UseRoundRobin;
|
||||
config.PostReleaseGraceHours = PostReleaseGraceHours;
|
||||
config.QuietHoursEnabled = QuietHoursEnabled;
|
||||
config.QuietHoursStart = QuietHoursStart;
|
||||
config.QuietHoursEnd = QuietHoursEnd;
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
+6
@@ -16,5 +16,11 @@ public sealed record SeekerConfigResponse
|
||||
|
||||
public int PostReleaseGraceHours { get; init; }
|
||||
|
||||
public bool QuietHoursEnabled { get; init; }
|
||||
|
||||
public TimeOnly QuietHoursStart { get; init; }
|
||||
|
||||
public TimeOnly QuietHoursEnd { get; init; }
|
||||
|
||||
public List<SeekerInstanceConfigResponse> Instances { get; init; } = [];
|
||||
}
|
||||
@@ -85,6 +85,9 @@ public sealed class SeekerConfigController : ControllerBase
|
||||
SelectionStrategy = config.SelectionStrategy,
|
||||
UseRoundRobin = config.UseRoundRobin,
|
||||
PostReleaseGraceHours = config.PostReleaseGraceHours,
|
||||
QuietHoursEnabled = config.QuietHoursEnabled,
|
||||
QuietHoursStart = config.QuietHoursStart,
|
||||
QuietHoursEnd = config.QuietHoursEnd,
|
||||
Instances = instanceResponses,
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user