You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
recyclarr/tests/Recyclarr.Cli.IntegrationTests/CustomFormatTransactionPhas...

487 lines
12 KiB

using Recyclarr.Cli.Cache;
using Recyclarr.Cli.Pipelines.CustomFormat;
using Recyclarr.Cli.Pipelines.CustomFormat.Models;
using Recyclarr.Cli.Pipelines.CustomFormat.PipelinePhases;
using Recyclarr.Tests.TestLibrary;
using Recyclarr.TrashGuide.CustomFormat;
namespace Recyclarr.Cli.IntegrationTests;
[TestFixture]
[Parallelizable(ParallelScope.All)]
internal class CustomFormatTransactionPhaseTest : CliIntegrationFixture
{
[Test]
public void Add_new_cf()
{
var sut = Resolve<CustomFormatTransactionPhase>();
var guideCfs = new[]
{
NewCf.Data("one", "cf1")
};
var serviceData = Array.Empty<CustomFormatData>();
var cache = new CustomFormatCache();
var config = NewConfig.Radarr();
var result = sut.Execute(config, guideCfs, serviceData, cache);
result.Should().BeEquivalentTo(new CustomFormatTransactionData
{
NewCustomFormats =
{
NewCf.Data("one", "cf1")
}
});
}
[Test]
public void Update_cf_by_matching_name()
{
var sut = Resolve<CustomFormatTransactionPhase>();
var guideCfs = new[]
{
new CustomFormatData
{
Name = "one",
TrashId = "cf1",
// Only set the below value to make it different from the service CF
IncludeCustomFormatWhenRenaming = true
}
};
var serviceData = new[]
{
new CustomFormatData {Name = "one"}
};
var cache = new CustomFormatCache();
var config = NewConfig.Radarr();
var result = sut.Execute(config, guideCfs, serviceData, cache);
result.Should().BeEquivalentTo(new CustomFormatTransactionData
{
UpdatedCustomFormats =
{
NewCf.Data("one", "cf1") with
{
IncludeCustomFormatWhenRenaming = true
}
}
});
}
[Test]
public void Update_cf_by_matching_id_different_names()
{
var sut = Resolve<CustomFormatTransactionPhase>();
var guideCfs = new[]
{
new CustomFormatData
{
Name = "different1",
TrashId = "cf1",
// Only set the below value to make it different from the service CF
IncludeCustomFormatWhenRenaming = true
}
};
var serviceData = new[]
{
new CustomFormatData {Name = "different2", Id = 2}
};
var cache = new CustomFormatCache
{
TrashIdMappings = new[]
{
new TrashIdMapping("cf1", "", 2)
}
};
var config = NewConfig.Radarr();
var result = sut.Execute(config, guideCfs, serviceData, cache);
result.Should().BeEquivalentTo(new CustomFormatTransactionData
{
UpdatedCustomFormats =
{
NewCf.Data("different1", "cf1", 2) with
{
IncludeCustomFormatWhenRenaming = true
}
}
});
}
[Test]
public void Update_cf_by_matching_id_same_names()
{
var sut = Resolve<CustomFormatTransactionPhase>();
var guideCfs = new[]
{
new CustomFormatData
{
Name = "different1",
TrashId = "cf1",
// Only set the below value to make it different from the service CF
IncludeCustomFormatWhenRenaming = true
}
};
var serviceData = new[]
{
new CustomFormatData {Name = "different1", Id = 2}
};
var cache = new CustomFormatCache();
var config = NewConfig.Radarr() with
{
ReplaceExistingCustomFormats = true
};
var result = sut.Execute(config, guideCfs, serviceData, cache);
result.Should().BeEquivalentTo(new CustomFormatTransactionData
{
UpdatedCustomFormats =
{
NewCf.Data("different1", "cf1", 2) with
{
IncludeCustomFormatWhenRenaming = true
}
}
});
}
[Test]
public void Conflicting_cf_when_new_cf_has_name_of_existing()
{
var sut = Resolve<CustomFormatTransactionPhase>();
var guideCfs = new[]
{
NewCf.Data("one", "cf1")
};
var serviceData = new[]
{
new CustomFormatData {Name = "one", Id = 2},
new CustomFormatData {Name = "two", Id = 1}
};
var cache = new CustomFormatCache();
var config = NewConfig.Radarr() with
{
ReplaceExistingCustomFormats = false
};
var result = sut.Execute(config, guideCfs, serviceData, cache);
result.Should().BeEquivalentTo(new CustomFormatTransactionData
{
ConflictingCustomFormats =
{
new ConflictingCustomFormat(guideCfs[0], 2)
}
});
}
[Test]
public void Conflicting_cf_when_cached_cf_has_name_of_existing()
{
var sut = Resolve<CustomFormatTransactionPhase>();
var guideCfs = new[]
{
NewCf.Data("one", "cf1")
};
var serviceData = new[]
{
new CustomFormatData {Name = "one", Id = 2},
new CustomFormatData {Name = "two", Id = 1}
};
var cache = new CustomFormatCache
{
TrashIdMappings = new[]
{
new TrashIdMapping("cf1", "one", 1)
}
};
var config = NewConfig.Radarr() with
{
ReplaceExistingCustomFormats = false
};
var result = sut.Execute(config, guideCfs, serviceData, cache);
result.Should().BeEquivalentTo(new CustomFormatTransactionData
{
ConflictingCustomFormats =
{
new ConflictingCustomFormat(guideCfs[0], 2)
}
});
}
[Test]
public void Updated_cf_with_matching_name_and_id()
{
var sut = Resolve<CustomFormatTransactionPhase>();
var guideCfs = new[]
{
new CustomFormatData
{
Name = "one",
TrashId = "cf1",
// Only set the below value to make it different from the service CF
IncludeCustomFormatWhenRenaming = true
}
};
var serviceData = new[]
{
new CustomFormatData {Name = "two", Id = 2},
new CustomFormatData {Name = "one", Id = 1}
};
var cache = new CustomFormatCache
{
TrashIdMappings = new[]
{
new TrashIdMapping("cf1", "one", 1)
}
};
var config = NewConfig.Radarr() with
{
ReplaceExistingCustomFormats = false
};
var result = sut.Execute(config, guideCfs, serviceData, cache);
result.Should().BeEquivalentTo(new CustomFormatTransactionData
{
UpdatedCustomFormats =
{
NewCf.Data("one", "cf1", 1) with {IncludeCustomFormatWhenRenaming = true}
}
});
}
[Test]
public void Unchanged_cfs_with_replace_enabled()
{
var sut = Resolve<CustomFormatTransactionPhase>();
var guideCfs = new[]
{
NewCf.Data("one", "cf1")
};
var serviceData = new[]
{
new CustomFormatData {Name = "one", Id = 1}
};
var cache = new CustomFormatCache();
var config = NewConfig.Radarr() with
{
ReplaceExistingCustomFormats = true
};
var result = sut.Execute(config, guideCfs, serviceData, cache);
result.Should().BeEquivalentTo(new CustomFormatTransactionData
{
UnchangedCustomFormats = {guideCfs[0]}
});
}
[Test]
public void Unchanged_cfs_without_replace()
{
var sut = Resolve<CustomFormatTransactionPhase>();
var guideCfs = new[]
{
NewCf.Data("one", "cf1")
};
var serviceData = new[]
{
new CustomFormatData {Name = "one", Id = 1}
};
var cache = new CustomFormatCache
{
TrashIdMappings = new[]
{
new TrashIdMapping("cf1", "one", 1)
}
};
var config = NewConfig.Radarr() with
{
ReplaceExistingCustomFormats = false
};
var result = sut.Execute(config, guideCfs, serviceData, cache);
result.Should().BeEquivalentTo(new CustomFormatTransactionData
{
UnchangedCustomFormats = {guideCfs[0]}
});
}
[Test]
public void Deleted_cfs_when_enabled()
{
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 = true
};
var result = sut.Execute(config, guideCfs, serviceData, cache);
result.Should().BeEquivalentTo(new CustomFormatTransactionData
{
DeletedCustomFormats =
{
new TrashIdMapping("cf2", "two", 2)
}
});
}
[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()
{
var sut = Resolve<CustomFormatTransactionPhase>();
var guideCfs = new[]
{
NewCf.Data("two", "cf2", 2)
};
var serviceData = new[]
{
new CustomFormatData {Name = "two", Id = 2}
};
var cache = new CustomFormatCache
{
TrashIdMappings = new[]
{
new TrashIdMapping("cf2", "two", 2)
}
};
var config = NewConfig.Radarr();
var result = sut.Execute(config, guideCfs, serviceData, cache);
result.DeletedCustomFormats.Should().BeEmpty();
}
[Test]
public void Add_new_cf_when_in_cache_but_not_in_service()
{
var sut = Resolve<CustomFormatTransactionPhase>();
var guideCfs = new[]
{
NewCf.Data("two", "cf2", 2)
};
var serviceData = Array.Empty<CustomFormatData>();
var cache = new CustomFormatCache
{
TrashIdMappings = new[]
{
new TrashIdMapping("cf2", "two", 200)
}
};
var config = NewConfig.Radarr();
var result = sut.Execute(config, guideCfs, serviceData, cache);
result.Should().BeEquivalentTo(new CustomFormatTransactionData
{
NewCustomFormats =
{
new CustomFormatData
{
Name = "two",
TrashId = "cf2",
Id = 200
}
}
});
}
}