Add activity testing API integration and activity test UI support

Introduced `ITestsApi` and supporting models for activity testing in workflows. Updated the UI to support triggering and displaying activity test results, including handling outcomes, outputs, exceptions, and status. Additionally, updated dependency injection for the new API and adjusted the project references.
This commit is contained in:
Sipke Schoorstra 2025-06-09 10:01:43 +02:00
parent 2db059da3d
commit 451554aa83
No known key found for this signature in database
GPG key ID: 5C10502B28A4268F
6 changed files with 105 additions and 0 deletions

View file

@ -12,6 +12,7 @@ using Elsa.Api.Client.Resources.Resilience.Contracts;
using Elsa.Api.Client.Resources.Scripting.Contracts;
using Elsa.Api.Client.Resources.StorageDrivers.Contracts;
using Elsa.Api.Client.Resources.Tasks.Contracts;
using Elsa.Api.Client.Resources.Tests;
using Elsa.Api.Client.Resources.VariableTypes.Contracts;
using Elsa.Api.Client.Resources.WorkflowActivationStrategies.Contracts;
using Elsa.Api.Client.Resources.WorkflowDefinitions.Contracts;
@ -86,6 +87,7 @@ public static class DependencyInjectionExtensions
services.AddApi<IWorkflowContextProviderDescriptorsApi>(builderOptions);
services.AddApi<IAlterationsApi>(builderOptions);
services.AddApi<ITasksApi>(builderOptions);
services.AddApi<ITestsApi>(builderOptions);
});
}

View file

@ -0,0 +1,18 @@
using Refit;
namespace Elsa.Api.Client.Resources.Tests;
/// <summary>
/// Represents a client for the testing API.
/// </summary>
public interface ITestsApi
{
/// <summary>
/// Sends the specified request to the login API.
/// </summary>
/// <param name="request">The request.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The response.</returns>
[Post("/tests/activities")]
Task<TestActivityResponse> TestActivityAsync([Body] TestActivityRequest request, CancellationToken cancellationToken = default);
}

View file

@ -0,0 +1,9 @@
using Elsa.Api.Client.Resources.WorkflowDefinitions.Models;
namespace Elsa.Api.Client.Resources.Tests;
public class TestActivityRequest
{
public WorkflowDefinitionHandle WorkflowDefinitionHandle { get; set; } = null!;
public ActivityHandle ActivityHandle { get; set; } = null!;
}

View file

@ -0,0 +1,12 @@
using Elsa.Api.Client.Resources.WorkflowInstances.Models;
using Elsa.Api.Client.Shared.Models;
namespace Elsa.Api.Client.Resources.Tests;
public class TestActivityResponse
{
public IDictionary<string, object?>? Outputs { get; set; }
public ICollection<string>? Outcomes { get; set; }
public ExceptionState? Exception { get; set; }
public ActivityStatus Status { get; set; }
}

View file

@ -0,0 +1,16 @@
namespace Elsa.Api.Client.Resources.WorkflowDefinitions.Models;
/// <summary>
/// Represents a handle to an activity.
/// </summary>
public class ActivityHandle
{
public static ActivityHandle FromActivityId(string activityId) => new() { ActivityId = activityId };
public static ActivityHandle FromActivityNodeId(string activityNodeId) => new() { ActivityNodeId = activityNodeId };
public static ActivityHandle FromActivityInstanceId(string activityInstanceId) => new() { ActivityInstanceId = activityInstanceId };
public static ActivityHandle FromActivityHash(string activityHash) => new() { ActivityHash = activityHash };
public string? ActivityId { get; init; }
public string? ActivityNodeId { get; init;}
public string? ActivityInstanceId { get; init;}
public string? ActivityHash { get; init;}
}

View file

@ -0,0 +1,48 @@
using Elsa.Api.Client.Shared.Models;
namespace Elsa.Api.Client.Resources.WorkflowDefinitions.Models;
/// <summary>
/// Represents a handle to a workflow definition.
/// </summary>
public class WorkflowDefinitionHandle
{
/// <summary>
/// Gets or sets the definition ID. When set, the <see cref="DefinitionVersionId"/> property is ignored.
/// </summary>
public string? DefinitionId { get; set; }
/// <summary>
/// Gets or sets the version options. When set, the <see cref="DefinitionVersionId"/> property is ignored.
/// </summary>
public VersionOptions? VersionOptions { get; set; }
/// <summary>
/// Gets or sets the definition version ID. When set, the <see cref="DefinitionId"/> and <see cref="VersionOptions"/> properties are ignored.
/// </summary>
public string? DefinitionVersionId { get; set; }
/// <summary>
/// Creates a new <see cref="WorkflowDefinitionHandle"/> instance with the specified definition ID and version options.
/// </summary>
public static WorkflowDefinitionHandle ByDefinitionId(string definitionId, VersionOptions? versionOptions = null) => new() { DefinitionId = definitionId, VersionOptions = versionOptions };
/// <summary>
/// Creates a new <see cref="WorkflowDefinitionHandle"/> instance with the specified definition version ID.
/// </summary>
/// <param name="definitionVersionId"></param>
/// <returns></returns>
public static WorkflowDefinitionHandle ByDefinitionVersionId(string definitionVersionId) => new() { DefinitionVersionId = definitionVersionId };
/// <inheritdoc />
public override string ToString()
{
if (DefinitionId != null)
return $"DefinitionId: {DefinitionId}, VersionOptions: {VersionOptions}";
if (DefinitionVersionId != null)
return $"DefinitionVersionId: {DefinitionVersionId}";
return string.Empty;
}
}