2026-07-18 18:58:20 +00:00
|
|
|
using Heimdall.Application.DTOs;
|
|
|
|
|
using Heimdall.Application.Validators;
|
|
|
|
|
|
|
|
|
|
namespace Heimdall.Application.Tests.Validators;
|
|
|
|
|
|
|
|
|
|
public class CreateAppSettingValidatorTests
|
|
|
|
|
{
|
|
|
|
|
private readonly CreateAppSettingValidator _sut = new();
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ValidRequest_PassesValidation()
|
|
|
|
|
{
|
|
|
|
|
var request = new CreateAppSettingRequest(
|
|
|
|
|
Key: "heartbeat.interval.seconds",
|
|
|
|
|
Value: "30",
|
|
|
|
|
Category: "Heartbeat",
|
|
|
|
|
Description: "Heartbeat interval in seconds",
|
|
|
|
|
ValueType: "int");
|
|
|
|
|
|
|
|
|
|
var result = _sut.TestValidate(request);
|
|
|
|
|
result.IsValid.ShouldBeTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void EmptyKey_FailsValidation()
|
|
|
|
|
{
|
|
|
|
|
var request = new CreateAppSettingRequest(
|
|
|
|
|
Key: "",
|
|
|
|
|
Value: "30",
|
|
|
|
|
Category: "General");
|
|
|
|
|
|
|
|
|
|
var result = _sut.TestValidate(request);
|
|
|
|
|
result.IsValid.ShouldBeFalse();
|
|
|
|
|
result.ShouldHaveValidationErrorFor(x => x.Key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void InvalidKeyFormat_FailsValidation()
|
|
|
|
|
{
|
|
|
|
|
var request = new CreateAppSettingRequest(
|
|
|
|
|
Key: "HEARTBEAT.Interval!", // uppercase + special char
|
|
|
|
|
Value: "30",
|
|
|
|
|
Category: "General");
|
|
|
|
|
|
|
|
|
|
var result = _sut.TestValidate(request);
|
|
|
|
|
result.IsValid.ShouldBeFalse();
|
|
|
|
|
result.ShouldHaveValidationErrorFor(x => x.Key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void InvalidValueType_FailsValidation()
|
|
|
|
|
{
|
|
|
|
|
var request = new CreateAppSettingRequest(
|
|
|
|
|
Key: "test.setting",
|
|
|
|
|
Value: "value",
|
|
|
|
|
Category: "General",
|
|
|
|
|
ValueType: "invalid");
|
|
|
|
|
|
|
|
|
|
var result = _sut.TestValidate(request);
|
|
|
|
|
result.IsValid.ShouldBeFalse();
|
|
|
|
|
result.ShouldHaveValidationErrorFor(x => x.ValueType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void EmptyCategory_FailsValidation()
|
|
|
|
|
{
|
|
|
|
|
var request = new CreateAppSettingRequest(
|
|
|
|
|
Key: "test.setting",
|
|
|
|
|
Value: "value",
|
|
|
|
|
Category: "");
|
|
|
|
|
|
|
|
|
|
var result = _sut.TestValidate(request);
|
|
|
|
|
result.IsValid.ShouldBeFalse();
|
|
|
|
|
result.ShouldHaveValidationErrorFor(x => x.Category);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ValidKeyWithDotsAndHyphens_PassesValidation()
|
|
|
|
|
{
|
|
|
|
|
var request = new CreateAppSettingRequest(
|
|
|
|
|
Key: "ai.detection.min-confidence",
|
|
|
|
|
Value: "0.75",
|
|
|
|
|
Category: "AI",
|
|
|
|
|
ValueType: "double");
|
|
|
|
|
|
|
|
|
|
var result = _sut.TestValidate(request);
|
|
|
|
|
result.IsValid.ShouldBeTrue();
|
|
|
|
|
}
|
2026-08-10 20:51:57 +02:00
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData("boolean")]
|
|
|
|
|
[InlineData("number")]
|
|
|
|
|
[InlineData("integer")]
|
|
|
|
|
[InlineData("dropdown")]
|
|
|
|
|
public void AliasValueTypes_PassesValidation(string valueType)
|
|
|
|
|
{
|
|
|
|
|
var request = new CreateAppSettingRequest(
|
|
|
|
|
Key: "test.alias",
|
|
|
|
|
Value: "value",
|
|
|
|
|
Category: "General",
|
|
|
|
|
ValueType: valueType);
|
|
|
|
|
|
|
|
|
|
var result = _sut.TestValidate(request);
|
|
|
|
|
result.IsValid.ShouldBeTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void AgentScoped_Default_IsTrue()
|
|
|
|
|
{
|
|
|
|
|
var request = new CreateAppSettingRequest(
|
|
|
|
|
Key: "test.agentscoped",
|
|
|
|
|
Value: "value",
|
|
|
|
|
Category: "General");
|
|
|
|
|
|
|
|
|
|
request.AgentScoped.ShouldBeTrue();
|
|
|
|
|
}
|
2026-07-18 18:58:20 +00:00
|
|
|
}
|