using w4c_workflows.Controllers; using w4c_workflows.Models; using Xunit; namespace w4c_workflows.Tests; /// /// P0-7: webhook matching must use the denormalized indexed column when present /// and fall back to trigger JSON only for rows compiled before the column existed. /// public class WebhooksControllerTests { private static Workflow Wf(string? column, string? triggerJson) => new() { TenantId = "t1", Name = "n", Path = "p", Status = WorkflowStatus.Compiled, Mode = WorkflowMode.Function, Target = "default", WebhookPath = column, TriggerJson = triggerJson, }; [Fact] public void Matches_on_the_denormalized_column() { var workflow = Wf("/h/orders", "{\"type\":\"webhook\",\"webhookPath\":\"/h/orders\"}"); Assert.True(WebhooksController.IsWebhookMatch(workflow, "/h/orders")); Assert.False(WebhooksController.IsWebhookMatch(workflow, "/h/other")); } [Fact] public void Falls_back_to_trigger_json_for_legacy_rows() { var workflow = Wf(column: null, triggerJson: "{\"type\":\"webhook\",\"webhookPath\":\"/h/orders\"}"); Assert.True(WebhooksController.IsWebhookMatch(workflow, "/h/orders")); Assert.False(WebhooksController.IsWebhookMatch(workflow, "/h/other")); } [Fact] public void Non_webhook_trigger_never_matches() { var workflow = Wf(column: null, triggerJson: "{\"type\":\"cron\",\"cron\":\"0 * * * *\"}"); Assert.False(WebhooksController.IsWebhookMatch(workflow, "/h/orders")); } }