< Summary

Information
Class: Elsa.Platform.Integration.Steps.ConfigureFeaturesStep
Assembly: Elsa.Platform.Integration
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Platform.Integration/Steps/ConfigureFeaturesStep.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 22
Coverable lines: 22
Total lines: 48
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 26
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
get_ShellId()100%210%
get_Enable()100%210%
get_Disable()100%210%
ValidateAsync(...)0%600240%
ExecuteAsync()0%620%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Platform.Integration/Steps/ConfigureFeaturesStep.cs

#LineLine coverage
 1using System.Text.Json;
 2using Elsa.Platform.Integration.Services;
 3using Loom;
 4
 5namespace Elsa.Platform.Integration.Steps;
 6
 7[Step("elsa.configure-features")]
 08public sealed class ConfigureFeaturesStep(
 09    IShellConfigurationOverlayStore overlayStore,
 010    PlatformShellReloadTracker reloadTracker) : IStep, IValidatingStep
 11{
 012    public string ShellId { get; init; } = "Default";
 13
 014    public Dictionary<string, JsonElement>? Enable { get; init; }
 15
 016    public List<string>? Disable { get; init; }
 17
 18    public ValueTask<IReadOnlyList<RecipeDiagnostic>> ValidateAsync(
 19        StepValidationContext context,
 20        CancellationToken cancellationToken = default)
 21    {
 022        List<RecipeDiagnostic> diagnostics = [];
 023        if (string.IsNullOrWhiteSpace(ShellId))
 024            diagnostics.Add(context.Error("ELSA_PLATFORM_SHELL_ID_REQUIRED", "Shell ID is required.", context.Target("in
 25
 026        if ((Enable is null || Enable.Count == 0) && (Disable is null || Disable.Count == 0))
 027            diagnostics.Add(context.Error("ELSA_PLATFORM_FEATURE_CHANGE_REQUIRED", "At least one feature enable or disab
 28
 029        foreach (var feature in Enable ?? [])
 30        {
 031            if (feature.Value.ValueKind is not JsonValueKind.Object and not JsonValueKind.Null and not JsonValueKind.Und
 032                diagnostics.Add(context.Error("ELSA_PLATFORM_FEATURE_CONFIG_INVALID", $"Feature '{feature.Key}' configur
 33        }
 34
 035        var duplicate = Enable?.Keys.FirstOrDefault(feature => Disable?.Contains(feature, StringComparer.OrdinalIgnoreCa
 036        if (duplicate is not null)
 037            diagnostics.Add(context.Error("ELSA_PLATFORM_FEATURE_CHANGE_CONFLICT", $"Feature '{duplicate}' cannot be ena
 38
 039        return ValueTask.FromResult<IReadOnlyList<RecipeDiagnostic>>(diagnostics);
 40    }
 41
 42    public async ValueTask ExecuteAsync(StepContext context, CancellationToken cancellationToken = default)
 43    {
 044        var changed = await overlayStore.ConfigureFeaturesAsync(ShellId, Enable, Disable, cancellationToken);
 045        if (changed)
 046            reloadTracker.MarkForReload(ShellId);
 047    }
 48}