mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.4 KiB
80 lines
2.4 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using Squidex.Domain.Apps.Core.HandleRules;
|
|
using Squidex.Domain.Apps.Entities.TestHelpers;
|
|
using Squidex.Flows.Internal.Execution;
|
|
using Squidex.Infrastructure;
|
|
|
|
namespace Squidex.Domain.Apps.Entities.Rules;
|
|
|
|
public class RuleFlowTrackingCallbackTests : GivenContext
|
|
{
|
|
private readonly IRuleUsageTracker ruleUsageTracker = A.Fake<IRuleUsageTracker>();
|
|
private readonly RuleFlowTrackingCallback sut;
|
|
|
|
public RuleFlowTrackingCallbackTests()
|
|
{
|
|
sut = new RuleFlowTrackingCallback(ruleUsageTracker);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Should_track_usage_with_success()
|
|
{
|
|
var ruleId = DomainId.NewGuid();
|
|
|
|
await sut.OnUpdateAsync(
|
|
new FlowExecutionState<FlowEventContext>
|
|
{
|
|
InstanceId = default,
|
|
Context = new FlowEventContext(),
|
|
Definition = null!,
|
|
DefinitionId = ruleId.ToString(),
|
|
OwnerId = AppId.Id.ToString(),
|
|
Status = FlowExecutionStatus.Completed,
|
|
},
|
|
CancellationToken);
|
|
|
|
A.CallTo(() => ruleUsageTracker.TrackAsync(
|
|
AppId.Id,
|
|
ruleId,
|
|
A<DateOnly>._,
|
|
0,
|
|
1,
|
|
0,
|
|
CancellationToken))
|
|
.MustHaveHappened();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Should_track_usage_with_failure()
|
|
{
|
|
var ruleId = DomainId.NewGuid();
|
|
|
|
await sut.OnUpdateAsync(
|
|
new FlowExecutionState<FlowEventContext>
|
|
{
|
|
InstanceId = default,
|
|
Context = new FlowEventContext(),
|
|
Definition = null!,
|
|
DefinitionId = ruleId.ToString(),
|
|
OwnerId = AppId.Id.ToString(),
|
|
Status = FlowExecutionStatus.Failed,
|
|
},
|
|
CancellationToken);
|
|
|
|
A.CallTo(() => ruleUsageTracker.TrackAsync(
|
|
AppId.Id,
|
|
ruleId,
|
|
A<DateOnly>._,
|
|
0,
|
|
0,
|
|
1,
|
|
CancellationToken))
|
|
.MustHaveHappened();
|
|
}
|
|
}
|
|
|