< Summary

Information
Class: Elsa.Workflows.Api.Endpoints.Events.TriggerPublic.Trigger
Assembly: Elsa.Workflows.Api
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/Events/TriggerPublic/Endpoint.cs
Line coverage
38%
Covered lines: 7
Uncovered lines: 11
Coverable lines: 18
Total lines: 50
Line coverage: 38.8%
Branch coverage
0%
Covered branches: 0
Total branches: 4
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%11100%
Configure()100%11100%
HandleAsync()0%2040%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/Events/TriggerPublic/Endpoint.cs

#LineLine coverage
 1using Elsa.Abstractions;
 2using Elsa.SasTokens.Contracts;
 3using Elsa.Workflows.Runtime;
 4using JetBrains.Annotations;
 5
 6namespace Elsa.Workflows.Api.Endpoints.Events.TriggerPublic;
 7
 8/// <summary>
 9/// Resumes a workflow instance blocked by a specified event encoded in the provided SAS token.
 10/// </summary>
 11[PublicAPI]
 12internal class Trigger : ElsaEndpointWithoutRequest
 13{
 14    private readonly ITokenService _tokenService;
 15    private readonly IEventPublisher _eventPublisher;
 16
 17    /// <inheritdoc />
 118    public Trigger(ITokenService tokenService, IEventPublisher eventPublisher)
 19    {
 120        _tokenService = tokenService;
 121        _eventPublisher = eventPublisher;
 122    }
 23
 24    /// <inheritdoc />
 25    public override void Configure()
 26    {
 127        Get("/events/trigger");
 128        AllowAnonymous();
 129    }
 30
 31    /// <inheritdoc />
 32    public override async Task HandleAsync(CancellationToken cancellationToken)
 33    {
 034        var token = Query<string>("t")!;
 35
 036        if (!_tokenService.TryDecryptToken<EventTokenPayload>(token, out var payload))
 37        {
 038            AddError("Invalid token.");
 039            await Send.ErrorsAsync(cancellation: cancellationToken);
 040            return;
 41        }
 42
 043        var eventName = payload.EventName;
 044        var workflowInstanceId = payload.WorkflowInstanceId;
 045        await _eventPublisher.PublishAsync(eventName, workflowInstanceId: workflowInstanceId, cancellationToken: cancell
 46
 047        if (!HttpContext.Response.HasStarted)
 048            await Send.OkAsync(cancellationToken);
 049    }
 50}