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.
486 lines
12 KiB
486 lines
12 KiB
2 years ago
|
using Recyclarr.Cli.Cache;
|
||
2 years ago
|
using Recyclarr.Cli.Pipelines.CustomFormat;
|
||
|
using Recyclarr.Cli.Pipelines.CustomFormat.Models;
|
||
|
using Recyclarr.Cli.Pipelines.CustomFormat.PipelinePhases;
|
||
1 year ago
|
using Recyclarr.Tests.TestLibrary;
|
||
1 year ago
|
using Recyclarr.TrashGuide.CustomFormat;
|
||
2 years ago
|
|
||
1 year ago
|
namespace Recyclarr.Cli.IntegrationTests;
|
||
2 years ago
|
|
||
|
[TestFixture]
|
||
1 year ago
|
internal class CustomFormatTransactionPhaseTest : CliIntegrationFixture
|
||
2 years ago
|
{
|
||
|
[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();
|
||
|
|
||
2 years ago
|
var config = NewConfig.Radarr();
|
||
2 years ago
|
|
||
|
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();
|
||
|
|
||
2 years ago
|
var config = NewConfig.Radarr();
|
||
2 years ago
|
|
||
|
var result = sut.Execute(config, guideCfs, serviceData, cache);
|
||
|
|
||
|
result.Should().BeEquivalentTo(new CustomFormatTransactionData
|
||
|
{
|
||
|
UpdatedCustomFormats =
|
||
|
{
|
||
2 years ago
|
NewCf.Data("one", "cf1") with
|
||
2 years ago
|
{
|
||
|
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)
|
||
|
}
|
||
|
};
|
||
|
|
||
2 years ago
|
var config = NewConfig.Radarr();
|
||
2 years ago
|
|
||
|
var result = sut.Execute(config, guideCfs, serviceData, cache);
|
||
|
|
||
|
result.Should().BeEquivalentTo(new CustomFormatTransactionData
|
||
|
{
|
||
|
UpdatedCustomFormats =
|
||
|
{
|
||
2 years ago
|
NewCf.Data("different1", "cf1", 2) with
|
||
2 years ago
|
{
|
||
|
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();
|
||
|
|
||
2 years ago
|
var config = NewConfig.Radarr() with
|
||
2 years ago
|
{
|
||
|
ReplaceExistingCustomFormats = true
|
||
|
};
|
||
2 years ago
|
|
||
|
var result = sut.Execute(config, guideCfs, serviceData, cache);
|
||
|
|
||
|
result.Should().BeEquivalentTo(new CustomFormatTransactionData
|
||
|
{
|
||
|
UpdatedCustomFormats =
|
||
|
{
|
||
2 years ago
|
NewCf.Data("different1", "cf1", 2) with
|
||
2 years ago
|
{
|
||
|
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();
|
||
|
|
||
2 years ago
|
var config = NewConfig.Radarr() with
|
||
2 years ago
|
{
|
||
|
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)
|
||
|
}
|
||
|
};
|
||
|
|
||
2 years ago
|
var config = NewConfig.Radarr() with
|
||
2 years ago
|
{
|
||
|
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)
|
||
|
}
|
||
|
};
|
||
|
|
||
2 years ago
|
var config = NewConfig.Radarr() with
|
||
2 years ago
|
{
|
||
|
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]
|
||
2 years ago
|
public void Unchanged_cfs_with_replace_enabled()
|
||
2 years ago
|
{
|
||
|
var sut = Resolve<CustomFormatTransactionPhase>();
|
||
|
|
||
|
var guideCfs = new[]
|
||
|
{
|
||
|
NewCf.Data("one", "cf1")
|
||
|
};
|
||
|
|
||
|
var serviceData = new[]
|
||
|
{
|
||
|
new CustomFormatData {Name = "one", Id = 1}
|
||
|
};
|
||
|
|
||
|
var cache = new CustomFormatCache();
|
||
|
|
||
2 years ago
|
var config = NewConfig.Radarr() with
|
||
2 years ago
|
{
|
||
|
ReplaceExistingCustomFormats = true
|
||
|
};
|
||
2 years ago
|
|
||
|
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)
|
||
|
}
|
||
|
};
|
||
|
|
||
2 years ago
|
var config = NewConfig.Radarr() with
|
||
2 years ago
|
{
|
||
|
ReplaceExistingCustomFormats = false
|
||
|
};
|
||
|
|
||
|
var result = sut.Execute(config, guideCfs, serviceData, cache);
|
||
|
|
||
|
result.Should().BeEquivalentTo(new CustomFormatTransactionData
|
||
|
{
|
||
|
UnchangedCustomFormats = {guideCfs[0]}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
2 years ago
|
public void Deleted_cfs_when_enabled()
|
||
2 years ago
|
{
|
||
|
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)
|
||
|
}
|
||
|
};
|
||
|
|
||
2 years ago
|
var config = NewConfig.Radarr() with
|
||
|
{
|
||
|
DeleteOldCustomFormats = true
|
||
|
};
|
||
2 years ago
|
|
||
|
var result = sut.Execute(config, guideCfs, serviceData, cache);
|
||
|
|
||
|
result.Should().BeEquivalentTo(new CustomFormatTransactionData
|
||
|
{
|
||
|
DeletedCustomFormats =
|
||
|
{
|
||
|
new TrashIdMapping("cf2", "two", 2)
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
2 years ago
|
[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());
|
||
|
}
|
||
|
|
||
2 years ago
|
[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)
|
||
|
}
|
||
|
};
|
||
|
|
||
2 years ago
|
var config = NewConfig.Radarr();
|
||
2 years ago
|
|
||
|
var result = sut.Execute(config, guideCfs, serviceData, cache);
|
||
|
|
||
|
result.DeletedCustomFormats.Should().BeEmpty();
|
||
|
}
|
||
2 years ago
|
|
||
|
[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
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
2 years ago
|
}
|