< Summary

Information
Class: Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.Export.Export
Assembly: Elsa.Workflows.Api
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Export/Endpoint.cs
Line coverage
75%
Covered lines: 15
Uncovered lines: 5
Coverable lines: 20
Total lines: 56
Line coverage: 75%
Branch coverage
60%
Covered branches: 6
Total branches: 10
Branch coverage: 60%
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()60%141066.66%

File(s)

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

#LineLine coverage
 1using Elsa.Authorization;
 2using Elsa.Abstractions;
 3using Elsa.Common.Models;
 4using Elsa.Workflows.Management;
 5using JetBrains.Annotations;
 6
 7namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.Export;
 8
 9/// <summary>
 10/// Exports the specified workflow definition as JSON download.
 11/// </summary>
 12[UsedImplicitly]
 713internal class Export(IWorkflowDefinitionExporter exporter) : ElsaEndpoint<Request>
 14{
 15    /// <inheritdoc />
 16    public override void Configure()
 17    {
 318        Routes("/bulk-actions/export/workflow-definitions", "/workflow-definitions/{definitionId}/export");
 319        Verbs(FastEndpoints.Http.GET, FastEndpoints.Http.POST);
 320        RequirePermission(Elsa.Workflows.Api.Permissions.WorkflowPermissions.Definitions, CoreVerbs.View);
 321    }
 22
 23    /// <inheritdoc />
 24    public override async Task HandleAsync(Request request, CancellationToken cancellationToken)
 25    {
 426        if (request.DefinitionId != null)
 27        {
 228            var versionOptions = string.IsNullOrEmpty(request.VersionOptions) ? VersionOptions.Latest : VersionOptions.F
 229            var result = await exporter.ExportAsync(request.DefinitionId, versionOptions, request.IncludeConsumingWorkfl
 30
 231            if (result == null)
 32            {
 033                await Send.NotFoundAsync(cancellationToken);
 034                return;
 35            }
 36
 237            await Send.BytesAsync(result.Data, result.FileName, cancellation: cancellationToken);
 38        }
 239        else if (request.Ids != null)
 40        {
 241            var result = await exporter.ExportManyAsync(request.Ids, request.IncludeConsumingWorkflows, cancellationToke
 42
 243            if (result == null)
 44            {
 045                await Send.NoContentAsync(cancellationToken);
 046                return;
 47            }
 48
 249            await Send.BytesAsync(result.Data, result.FileName, cancellation: cancellationToken);
 50        }
 51        else
 52        {
 053            await Send.NoContentAsync(cancellationToken);
 54        }
 455    }
 56}