fix(mgmt): MV-10 review fixes (ElementDataType fixed-field in LockEnforcer; graceful bad-DataType error; message consistency)

This commit is contained in:
Joseph Doherty
2026-06-16 16:13:38 -04:00
parent 1525670fe7
commit 0164f8a0d6
5 changed files with 144 additions and 4 deletions
@@ -80,6 +80,64 @@ public class LockEnforcerTests
Assert.Null(result);
}
[Fact]
public void ValidateAttributeOverride_ElementDataTypeChanged_ReturnsError()
{
// MV-10 review fix: ElementDataType is the element scalar type of a List
// attribute and is fixed by the defining level, exactly like DataType.
// TemplateService.UpdateAttributeAsync never copies it onto the persisted
// row, so a mismatch must be rejected before the Value (validated against
// the real element type) is persisted against the wrong type.
var original = new TemplateAttribute("Tags")
{
DataType = DataType.List, ElementDataType = DataType.Int32, IsLocked = false
};
var proposed = new TemplateAttribute("Tags")
{
DataType = DataType.List, ElementDataType = DataType.String, IsLocked = false // changed!
};
var result = LockEnforcer.ValidateAttributeOverride(original, proposed);
Assert.NotNull(result);
Assert.Contains("ElementDataType", result);
}
[Fact]
public void ValidateAttributeOverride_ElementDataTypeMatches_ReturnsNull()
{
var original = new TemplateAttribute("Tags")
{
DataType = DataType.List, ElementDataType = DataType.Int32, IsLocked = false, Value = "[1]"
};
var proposed = new TemplateAttribute("Tags")
{
DataType = DataType.List, ElementDataType = DataType.Int32, IsLocked = false, Value = "[1,2]"
};
var result = LockEnforcer.ValidateAttributeOverride(original, proposed);
Assert.Null(result);
}
[Fact]
public void ValidateAttributeOverride_ElementDataTypeBothNull_ReturnsNull()
{
// Scalar attributes carry no element type on either side — not a change.
var original = new TemplateAttribute("Speed")
{
DataType = DataType.Float, ElementDataType = null, IsLocked = false, Value = "0"
};
var proposed = new TemplateAttribute("Speed")
{
DataType = DataType.Float, ElementDataType = null, IsLocked = false, Value = "100"
};
var result = LockEnforcer.ValidateAttributeOverride(original, proposed);
Assert.Null(result);
}
[Fact]
public void ValidateAlarmOverride_LockedAlarm_ReturnsError()
{