Refine timestamp filter validation feedback

This commit is contained in:
Sipke Schoorstra 2026-05-21 01:49:44 +02:00
parent 008e5a3f21
commit 25b1ee11ef
No known key found for this signature in database
GPG key ID: 5C10502B28A4268F
4 changed files with 12 additions and 13 deletions

View file

@ -218,16 +218,16 @@ public class WorkflowInstanceFilter
if (timestampFilters == null)
yield break;
foreach (var timestampFilter in timestampFilters)
foreach (var (timestampFilter, index) in timestampFilters.Select((value, index) => (value, index)))
{
if (timestampFilter == null)
{
yield return "Timestamp filter must be specified.";
yield return $"Timestamp filter at index {index} must be specified.";
continue;
}
if (!TryNormalizeTimestampFilterColumn(timestampFilter.Column, out _, out var error))
yield return error;
yield return $"Timestamp filter at index {index}: {error}";
}
}
@ -251,7 +251,7 @@ public class WorkflowInstanceFilter
if (normalizedColumn != null)
return true;
error = $"Invalid timestamp filter column '{column}'. Allowed columns are: {string.Join(", ", TimestampFilterColumns)}.";
error = $"Invalid timestamp filter column. Allowed columns are: {string.Join(", ", TimestampFilterColumns)}.";
return false;
}

View file

@ -97,7 +97,7 @@ public class AlterationsApiTimestampFilterTests : IAsyncLifetime
var body = await response.Content.ReadAsStringAsync();
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
Assert.Contains("Timestamp filter must be specified.", body);
Assert.Contains("Timestamp filter at index 0 must be specified.", body);
}
[Theory]
@ -109,8 +109,8 @@ public class AlterationsApiTimestampFilterTests : IAsyncLifetime
var body = await response.Content.ReadAsStringAsync();
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
Assert.Contains("Timestamp filter column must be specified.", body);
Assert.Contains("Timestamp filter must be specified.", body);
Assert.Contains("Timestamp filter at index 0: Timestamp filter column must be specified.", body);
Assert.Contains("Timestamp filter at index 1 must be specified.", body);
}
private static object CreateRequest(string path)

View file

@ -1,3 +0,0 @@
using Xunit;
[assembly: CollectionBehavior(DisableTestParallelization = true)]

View file

@ -67,7 +67,9 @@ public class WorkflowInstanceFilterTimestampTests
var exception = Assert.Throws<ArgumentException>(() => filter.Apply(_workflowInstances).ToList());
Assert.Contains("Invalid timestamp filter column", exception.Message);
Assert.Contains("CreatedAt, UpdatedAt, FinishedAt", exception.Message);
Assert.DoesNotContain("CreatedAt == @0", exception.Message);
foreach (var column in WorkflowInstanceFilter.AllowedTimestampFilterColumns)
Assert.Contains(column, exception.Message);
Assert.Equal($"{nameof(WorkflowInstanceFilter.TimestampFilters)}.Column", exception.ParamName);
}
@ -99,7 +101,7 @@ public class WorkflowInstanceFilterTimestampTests
]).ToList();
var error = Assert.Single(errors);
Assert.Equal("Timestamp filter column must be specified.", error);
Assert.Equal("Timestamp filter at index 0: Timestamp filter column must be specified.", error);
}
[Fact]
@ -108,7 +110,7 @@ public class WorkflowInstanceFilterTimestampTests
var errors = WorkflowInstanceFilter.ValidateTimestampFilters([null!]).ToList();
var error = Assert.Single(errors);
Assert.Equal("Timestamp filter must be specified.", error);
Assert.Equal("Timestamp filter at index 0 must be specified.", error);
}
private DateTimeOffset GetMatchingTimestamp(string column) => column switch