Update scheduling parameters and refactor channel endpoints: extend HorizonDays to 7 and RetentionDays to 90 in appsettings.json. Consolidate channel-related endpoint logic by removing obsolete files and enhancing the ShowEndpoints with audience and genre management capabilities. Improve error handling and streamline command handlers for channel operations.
This commit is contained in:
@@ -1,142 +1,88 @@
|
||||
using TeleWave.Application.Admin.Users.CreateUser;
|
||||
using TeleWave.Application.Admin.Users.ResetPassword;
|
||||
using TeleWave.Application.Broadcast;
|
||||
using TeleWave.Application.Broadcast.Bumpers;
|
||||
using TeleWave.Application.Broadcast.CreateOverride;
|
||||
using TeleWave.Application.Broadcast.UpdateChannelSettings;
|
||||
using TeleWave.Application.Broadcast.UpdateChannelShow;
|
||||
using TeleWave.Domain.Broadcast;
|
||||
using Xunit;
|
||||
|
||||
namespace TeleWave.Application.Tests.Validators;
|
||||
|
||||
public class ValidatorTests
|
||||
{
|
||||
[Fact]
|
||||
public void UpdateChannelShow_RejectsBadWeightMultiplierAndWindows()
|
||||
{
|
||||
var v = new UpdateChannelShowCommandValidator();
|
||||
|
||||
var good = new UpdateChannelShowCommand(
|
||||
Guid.NewGuid(),
|
||||
Guid.NewGuid(),
|
||||
5,
|
||||
BlockMode.Count,
|
||||
3,
|
||||
true,
|
||||
4,
|
||||
[new HourWindowInput(18, 23)]
|
||||
);
|
||||
Assert.True(v.Validate(good).IsValid);
|
||||
|
||||
var badMultiplier = good with { PreferredWeightMultiplier = 0 };
|
||||
Assert.False(v.Validate(badMultiplier).IsValid);
|
||||
|
||||
var badWindow = good with { PreferredHours = [new HourWindowInput(23, 20)] };
|
||||
Assert.False(v.Validate(badWindow).IsValid);
|
||||
|
||||
var badWeight = good with { Weight = 0 };
|
||||
Assert.False(v.Validate(badWeight).IsValid);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UpdateBumperTextVariant_ChecksLengthsAndWeight()
|
||||
{
|
||||
var v = new UpdateBumperTextVariantCommandValidator();
|
||||
|
||||
var good = new UpdateBumperTextVariantCommand(
|
||||
Guid.NewGuid(),
|
||||
Guid.NewGuid(),
|
||||
Guid.NewGuid(),
|
||||
"Name",
|
||||
BumperTextKind.NowNext,
|
||||
"NOW",
|
||||
"NEXT",
|
||||
"l1",
|
||||
"l2",
|
||||
BumperTrigger.Both,
|
||||
3
|
||||
);
|
||||
Assert.True(v.Validate(good).IsValid);
|
||||
|
||||
Assert.False(v.Validate(good with { Name = "" }).IsValid);
|
||||
Assert.False(v.Validate(good with { Weight = -1 }).IsValid);
|
||||
Assert.False(v.Validate(good with { Line1 = new string('x', 121) }).IsValid);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UpdateChannelSettings_ChecksRanges()
|
||||
{
|
||||
var v = new UpdateChannelSettingsCommandValidator();
|
||||
var bumper = new BumperSettingsInput(
|
||||
BumperFont.Sans,
|
||||
10,
|
||||
BumperSelection.Rotation,
|
||||
0.5,
|
||||
0.5
|
||||
);
|
||||
|
||||
var good = new UpdateChannelSettingsCommand(
|
||||
Guid.NewGuid(),
|
||||
"Name",
|
||||
true,
|
||||
AdInsertion.BetweenBlocks,
|
||||
2,
|
||||
true,
|
||||
bumper,
|
||||
null
|
||||
);
|
||||
Assert.True(v.Validate(good).IsValid);
|
||||
|
||||
Assert.False(v.Validate(good with { Name = "" }).IsValid);
|
||||
Assert.False(v.Validate(good with { AdsPerBreak = 99 }).IsValid);
|
||||
Assert.False(
|
||||
v.Validate(good with { Bumper = bumper with { ShowChangeChance = 2 } }).IsValid
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateOverride_RequiresShows_WithValidWeights()
|
||||
{
|
||||
var v = new CreateProgrammingOverrideCommandValidator();
|
||||
|
||||
var good = new CreateProgrammingOverrideCommand(
|
||||
Guid.NewGuid(),
|
||||
OverrideMode.Boost,
|
||||
OverrideRecurrence.OneTime,
|
||||
DateTimeOffset.UtcNow,
|
||||
DateTimeOffset.UtcNow.AddHours(1),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
[new OverrideShowInput(Guid.NewGuid(), 3)]
|
||||
);
|
||||
Assert.True(v.Validate(good).IsValid);
|
||||
|
||||
Assert.False(v.Validate(good with { Shows = [] }).IsValid);
|
||||
Assert.False(
|
||||
v.Validate(good with { Shows = [new OverrideShowInput(Guid.NewGuid(), 0)] }).IsValid
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResetUserPassword_RequiresMinLength()
|
||||
{
|
||||
var v = new ResetUserPasswordCommandValidator();
|
||||
|
||||
Assert.True(v.Validate(new ResetUserPasswordCommand(Guid.NewGuid(), "Password1")).IsValid);
|
||||
Assert.False(v.Validate(new ResetUserPasswordCommand(Guid.NewGuid(), "short")).IsValid);
|
||||
Assert.False(v.Validate(new ResetUserPasswordCommand(Guid.Empty, "Password1")).IsValid);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateUser_ChecksNameAndPassword()
|
||||
{
|
||||
var v = new CreateUserCommandValidator();
|
||||
|
||||
Assert.True(v.Validate(new CreateUserCommand("bob", "Password1", Guid.NewGuid())).IsValid);
|
||||
Assert.False(v.Validate(new CreateUserCommand("ab", "Password1", Guid.NewGuid())).IsValid);
|
||||
Assert.False(v.Validate(new CreateUserCommand("bob", "short", Guid.NewGuid())).IsValid);
|
||||
Assert.False(v.Validate(new CreateUserCommand("bob", "Password1", Guid.Empty)).IsValid);
|
||||
}
|
||||
}
|
||||
using TeleWave.Application.Admin.Users.CreateUser;
|
||||
using TeleWave.Application.Admin.Users.ResetPassword;
|
||||
using TeleWave.Application.Broadcast;
|
||||
using TeleWave.Application.Broadcast.Bumpers;
|
||||
using TeleWave.Application.Broadcast.UpdateChannelSettings;
|
||||
using TeleWave.Domain.Broadcast;
|
||||
using Xunit;
|
||||
|
||||
namespace TeleWave.Application.Tests.Validators;
|
||||
|
||||
public class ValidatorTests
|
||||
{
|
||||
|
||||
[Fact]
|
||||
public void UpdateBumperTextVariant_ChecksLengthsAndWeight()
|
||||
{
|
||||
var v = new UpdateBumperTextVariantCommandValidator();
|
||||
|
||||
var good = new UpdateBumperTextVariantCommand(
|
||||
Guid.NewGuid(),
|
||||
Guid.NewGuid(),
|
||||
Guid.NewGuid(),
|
||||
"Name",
|
||||
BumperTextKind.NowNext,
|
||||
"NOW",
|
||||
"NEXT",
|
||||
"l1",
|
||||
"l2",
|
||||
BumperTrigger.Both,
|
||||
3
|
||||
);
|
||||
Assert.True(v.Validate(good).IsValid);
|
||||
|
||||
Assert.False(v.Validate(good with { Name = "" }).IsValid);
|
||||
Assert.False(v.Validate(good with { Weight = -1 }).IsValid);
|
||||
Assert.False(v.Validate(good with { Line1 = new string('x', 121) }).IsValid);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UpdateChannelSettings_ChecksRanges()
|
||||
{
|
||||
var v = new UpdateChannelSettingsCommandValidator();
|
||||
var bumper = new BumperSettingsInput(
|
||||
BumperFont.Sans,
|
||||
10,
|
||||
BumperSelection.Rotation,
|
||||
0.5,
|
||||
0.5
|
||||
);
|
||||
|
||||
var good = new UpdateChannelSettingsCommand(
|
||||
Guid.NewGuid(),
|
||||
"Name",
|
||||
true,
|
||||
true,
|
||||
bumper,
|
||||
null
|
||||
);
|
||||
Assert.True(v.Validate(good).IsValid);
|
||||
|
||||
Assert.False(v.Validate(good with { Name = "" }).IsValid);
|
||||
Assert.False(
|
||||
v.Validate(good with { Bumper = bumper with { ShowChangeChance = 2 } }).IsValid
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void ResetUserPassword_RequiresMinLength()
|
||||
{
|
||||
var v = new ResetUserPasswordCommandValidator();
|
||||
|
||||
Assert.True(v.Validate(new ResetUserPasswordCommand(Guid.NewGuid(), "Password1")).IsValid);
|
||||
Assert.False(v.Validate(new ResetUserPasswordCommand(Guid.NewGuid(), "short")).IsValid);
|
||||
Assert.False(v.Validate(new ResetUserPasswordCommand(Guid.Empty, "Password1")).IsValid);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateUser_ChecksNameAndPassword()
|
||||
{
|
||||
var v = new CreateUserCommandValidator();
|
||||
|
||||
Assert.True(v.Validate(new CreateUserCommand("bob", "Password1", Guid.NewGuid())).IsValid);
|
||||
Assert.False(v.Validate(new CreateUserCommand("ab", "Password1", Guid.NewGuid())).IsValid);
|
||||
Assert.False(v.Validate(new CreateUserCommand("bob", "short", Guid.NewGuid())).IsValid);
|
||||
Assert.False(v.Validate(new CreateUserCommand("bob", "Password1", Guid.Empty)).IsValid);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user