fix: Do not unconditionally show deleted custom formats

When `delete_old_custom_formats` is `false`, we should not show deleted
custom formats.
pull/201/head
Robert Dailey 11 months ago
parent d799da385e
commit 2a28130599

@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Address regression causing `reset_unmatched_scores: false` to not be respected.
- Do not show deleted custom formats in console output when `delete_old_custom_formats` is set to
`false`.
## [5.0.0] - 2023-06-22

@ -28,12 +28,9 @@ public class CustomFormatApiPersistencePhase
await _api.UpdateCustomFormat(config, dto);
}
if (config.DeleteOldCustomFormats)
foreach (var map in transactions.DeletedCustomFormats)
{
foreach (var map in transactions.DeletedCustomFormats)
{
await _api.DeleteCustomFormat(config, map.CustomFormatId);
}
await _api.DeleteCustomFormat(config, map.CustomFormatId);
}
}
}

@ -52,11 +52,14 @@ public class CustomFormatTransactionPhase
}
}
transactions.DeletedCustomFormats.AddRange(cache.TrashIdMappings
// Custom format must be in the cache but NOT in the user's config
.Where(map => guideCfs.All(cf => cf.TrashId != map.TrashId))
// Also, that cache-only CF must exist in the service (otherwise there is nothing to delete)
.Where(map => serviceData.Any(cf => cf.Id == map.CustomFormatId)));
if (config.DeleteOldCustomFormats)
{
transactions.DeletedCustomFormats.AddRange(cache.TrashIdMappings
// Custom format must be in the cache but NOT in the user's config
.Where(map => guideCfs.All(cf => cf.TrashId != map.TrashId))
// Also, that cache-only CF must exist in the service (otherwise there is nothing to delete)
.Where(map => serviceData.Any(cf => cf.Id == map.CustomFormatId)));
}
return transactions;
}

@ -352,7 +352,7 @@ public class CustomFormatTransactionPhaseTest : CliIntegrationFixture
}
[Test]
public void Deleted_cfs()
public void Deleted_cfs_when_enabled()
{
var sut = Resolve<CustomFormatTransactionPhase>();
@ -371,7 +371,10 @@ public class CustomFormatTransactionPhaseTest : CliIntegrationFixture
}
};
var config = NewConfig.Radarr();
var config = NewConfig.Radarr() with
{
DeleteOldCustomFormats = true
};
var result = sut.Execute(config, guideCfs, serviceData, cache);
@ -384,6 +387,36 @@ public class CustomFormatTransactionPhaseTest : CliIntegrationFixture
});
}
[Test]
public void No_deleted_cfs_when_disabled()
{
var sut = Resolve<CustomFormatTransactionPhase>();
var guideCfs = Array.Empty<CustomFormatData>();
var serviceData = new[]
{
new CustomFormatData {Name = "two", Id = 2}
};
var cache = new CustomFormatCache
{
TrashIdMappings = new[]
{
new TrashIdMapping("cf2", "two", 2)
}
};
var config = NewConfig.Radarr() with
{
DeleteOldCustomFormats = false
};
var result = sut.Execute(config, guideCfs, serviceData, cache);
result.Should().BeEquivalentTo(new CustomFormatTransactionData());
}
[Test]
public void Do_not_delete_cfs_in_config()
{

Loading…
Cancel
Save