mirror of https://github.com/Squidex/squidex.git
Browse Source
* First attempt. * Typed script vars and annotations. * Use intellisense for rule actions. * Fix tests. * Stupid mini fix.pull/861/head
committed by
GitHub
91 changed files with 1964 additions and 545 deletions
@ -0,0 +1,20 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Core |
||||
|
{ |
||||
|
[AttributeUsage(AttributeTargets.Property)] |
||||
|
public sealed class FieldDescriptionAttribute : Attribute |
||||
|
{ |
||||
|
public string Name { get; } |
||||
|
|
||||
|
public FieldDescriptionAttribute(string name) |
||||
|
{ |
||||
|
Name = name; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,82 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using Squidex.Domain.Apps.Core.Assets; |
||||
|
using Squidex.Domain.Apps.Core.Scripting.Internal; |
||||
|
using Squidex.Infrastructure; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Core.Scripting |
||||
|
{ |
||||
|
public sealed class AssetCommandScriptVars : ScriptVars |
||||
|
{ |
||||
|
[FieldDescription(nameof(FieldDescriptions.AssetParentId))] |
||||
|
public DomainId ParentId |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.AssetFileHash))] |
||||
|
public string? FileHash |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.AssetFileName))] |
||||
|
public string? FileName |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.AssetSlug))] |
||||
|
public string? FileSlug |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.AssetMimeType))] |
||||
|
public string? MimeType |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.AssetParentPath))] |
||||
|
public Array? ParentPath |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.AssetMetadata))] |
||||
|
public AssetMetadata? Metadata |
||||
|
{ |
||||
|
set => SetValue(value != null ? new AssetMetadataWrapper(value) : null); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.AssetTags))] |
||||
|
public HashSet<string>? Tags |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.AssetFileSize))] |
||||
|
public long FileSize |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.AssetIsProtected))] |
||||
|
public bool? IsProtected |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.EntityRequestDeletePermanent))] |
||||
|
public bool? Permanent |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,83 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Collections.ObjectModel; |
||||
|
using Squidex.Domain.Apps.Core.Assets; |
||||
|
using Squidex.Infrastructure; |
||||
|
using Squidex.Infrastructure.Json.Objects; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Core.Scripting |
||||
|
{ |
||||
|
public sealed class AssetEntityScriptVars : ScriptVars |
||||
|
{ |
||||
|
[FieldDescription(nameof(FieldDescriptions.AssetParentId))] |
||||
|
public DomainId ParentId |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.AssetFileHash))] |
||||
|
public string? FileHash |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.AssetFileName))] |
||||
|
public string? FileName |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.AssetSlug))] |
||||
|
public string? FileSlug |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.AssetMimeType))] |
||||
|
public string? MimeType |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.AssetParentPath))] |
||||
|
public Array? ParentPath |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.AssetMetadata))] |
||||
|
public AssetMetadata? Metadata |
||||
|
{ |
||||
|
set => SetValue(value != null ? new ReadOnlyDictionary<string, IJsonValue>(value) : null); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.AssetTags))] |
||||
|
public HashSet<string>? Tags |
||||
|
{ |
||||
|
set => SetValue(value != null ? new ReadOnlyCollection<string>(value.ToList()) : null); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.AssetFileSize))] |
||||
|
public long FileSize |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.AssetFileVersion))] |
||||
|
public long FileVersion |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.AssetIsProtected))] |
||||
|
public bool? IsProtected |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,57 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Security.Claims; |
||||
|
using Squidex.Infrastructure; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Core.Scripting |
||||
|
{ |
||||
|
public sealed class AssetScriptVars : ScriptVars |
||||
|
{ |
||||
|
[FieldDescription(nameof(FieldDescriptions.AppId))] |
||||
|
public DomainId AppId |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.EntityId))] |
||||
|
public DomainId AssetId |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.AppName))] |
||||
|
public string AppName |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.Operation))] |
||||
|
public string Operation |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.Command))] |
||||
|
public AssetCommandScriptVars Command |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.Asset))] |
||||
|
public AssetEntityScriptVars Asset |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.User))] |
||||
|
public ClaimsPrincipal? User |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,101 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Security.Claims; |
||||
|
using Squidex.Domain.Apps.Core.Contents; |
||||
|
using Squidex.Infrastructure; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Core.Scripting |
||||
|
{ |
||||
|
public sealed class ContentScriptVars : DataScriptVars |
||||
|
{ |
||||
|
[FieldDescription(nameof(FieldDescriptions.AppId))] |
||||
|
public DomainId AppId |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.SchemaId))] |
||||
|
public DomainId SchemaId |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.EntityId))] |
||||
|
public DomainId ContentId |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.AppName))] |
||||
|
public string AppName |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.ContentSchemaName))] |
||||
|
public string SchemaName |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.Operation))] |
||||
|
public string Operation |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.EntityRequestDeletePermanent))] |
||||
|
public bool Permanent |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.User))] |
||||
|
public ClaimsPrincipal? User |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.ContentStatus))] |
||||
|
public Status Status |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.ContentStatusOld))] |
||||
|
public Status StatusOld |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.ContentStatusOld))] |
||||
|
public Status OldStatus |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.ContentData))] |
||||
|
public ContentData? DataOld |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.ContentDataOld))] |
||||
|
public ContentData? OldData |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
|
||||
|
[FieldDescription(nameof(FieldDescriptions.ContentData))] |
||||
|
public override ContentData? Data |
||||
|
{ |
||||
|
get => GetValue<ContentData?>(); |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using Squidex.Domain.Apps.Core.Contents; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Core.Scripting |
||||
|
{ |
||||
|
public class DataScriptVars : ScriptVars |
||||
|
{ |
||||
|
public virtual ContentData? Data |
||||
|
{ |
||||
|
get => GetValue<ContentData?>(); |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using Squidex.Domain.Apps.Core.Rules.EnrichedEvents; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Core.Scripting |
||||
|
{ |
||||
|
public sealed class EventScriptVars : ScriptVars |
||||
|
{ |
||||
|
public EnrichedEvent Event |
||||
|
{ |
||||
|
set => SetValue(value); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,125 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Collections; |
||||
|
using System.Diagnostics.CodeAnalysis; |
||||
|
using Squidex.Domain.Apps.Core.Assets; |
||||
|
using Squidex.Infrastructure.Json.Objects; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Core.Scripting.Internal |
||||
|
{ |
||||
|
internal sealed class AssetMetadataWrapper : IDictionary<string, object?> |
||||
|
{ |
||||
|
private readonly AssetMetadata metadata; |
||||
|
|
||||
|
public int Count |
||||
|
{ |
||||
|
get => metadata.Count; |
||||
|
} |
||||
|
|
||||
|
public ICollection<string> Keys |
||||
|
{ |
||||
|
get => metadata.Keys; |
||||
|
} |
||||
|
|
||||
|
public ICollection<object?> Values |
||||
|
{ |
||||
|
get => metadata.Values.Cast<object?>().ToList(); |
||||
|
} |
||||
|
|
||||
|
public object? this[string key] |
||||
|
{ |
||||
|
get => metadata[key]; |
||||
|
set => metadata[key] = JsonValue.Create(value); |
||||
|
} |
||||
|
|
||||
|
public bool IsReadOnly |
||||
|
{ |
||||
|
get => false; |
||||
|
} |
||||
|
|
||||
|
public AssetMetadataWrapper(AssetMetadata metadata) |
||||
|
{ |
||||
|
this.metadata = metadata; |
||||
|
} |
||||
|
|
||||
|
public bool TryGetValue(string key, [MaybeNullWhen(false)] out object? value) |
||||
|
{ |
||||
|
if (metadata.TryGetValue(key, out var temp)) |
||||
|
{ |
||||
|
value = temp; |
||||
|
return true; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
value = null; |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public void Add(string key, object? value) |
||||
|
{ |
||||
|
metadata.Add(key, JsonValue.Create(value)); |
||||
|
} |
||||
|
|
||||
|
public void Add(KeyValuePair<string, object?> item) |
||||
|
{ |
||||
|
Add(item.Key, item.Value); |
||||
|
} |
||||
|
|
||||
|
public bool Remove(string key) |
||||
|
{ |
||||
|
return metadata.Remove(key); |
||||
|
} |
||||
|
|
||||
|
public bool Remove(KeyValuePair<string, object?> item) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
public void Clear() |
||||
|
{ |
||||
|
metadata.Clear(); |
||||
|
} |
||||
|
|
||||
|
public bool Contains(KeyValuePair<string, object?> item) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
public bool ContainsKey(string key) |
||||
|
{ |
||||
|
return metadata.ContainsKey(key); |
||||
|
} |
||||
|
|
||||
|
public void CopyTo(KeyValuePair<string, object?>[] array, int arrayIndex) |
||||
|
{ |
||||
|
var i = arrayIndex; |
||||
|
|
||||
|
foreach (var item in metadata) |
||||
|
{ |
||||
|
if (i >= array.Length) |
||||
|
{ |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
array[i] = new KeyValuePair<string, object?>(item.Key, item.Value); |
||||
|
i++; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public IEnumerator<KeyValuePair<string, object?>> GetEnumerator() |
||||
|
{ |
||||
|
return metadata.Select(x => new KeyValuePair<string, object?>(x.Key, x.Value)).GetEnumerator(); |
||||
|
} |
||||
|
|
||||
|
IEnumerator IEnumerable.GetEnumerator() |
||||
|
{ |
||||
|
return ((IEnumerable)metadata).GetEnumerator(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,380 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using FakeItEasy; |
||||
|
using Squidex.Domain.Apps.Core.Apps; |
||||
|
using Squidex.Domain.Apps.Core.GenerateFilters; |
||||
|
using Squidex.Domain.Apps.Core.Schemas; |
||||
|
using Squidex.Domain.Apps.Core.Scripting; |
||||
|
using Squidex.Infrastructure.Queries; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Core.Operations.Scripting |
||||
|
{ |
||||
|
public class ScriptingCompleterTests |
||||
|
{ |
||||
|
private readonly IScriptDescriptor scriptDescriptor1 = A.Fake<IScriptDescriptor>(); |
||||
|
private readonly IScriptDescriptor scriptDescriptor2 = A.Fake<IScriptDescriptor>(); |
||||
|
private readonly FilterSchema dataSchema; |
||||
|
private readonly ScriptingCompleter sut; |
||||
|
|
||||
|
public ScriptingCompleterTests() |
||||
|
{ |
||||
|
var schema = |
||||
|
new Schema("simple") |
||||
|
.AddString(1, "my-field", Partitioning.Invariant); |
||||
|
|
||||
|
dataSchema = schema.BuildDataSchema(LanguagesConfig.English.ToResolver(), ResolvedComponents.Empty); |
||||
|
|
||||
|
sut = new ScriptingCompleter(new[] { scriptDescriptor1, scriptDescriptor2 }); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Should_calls_descriptors() |
||||
|
{ |
||||
|
sut.UsageTrigger(); |
||||
|
|
||||
|
A.CallTo(() => scriptDescriptor1.Describe(A<AddDescription>._, A<ScriptScope>._)) |
||||
|
.MustHaveHappened(); |
||||
|
|
||||
|
A.CallTo(() => scriptDescriptor2.Describe(A<AddDescription>._, A<ScriptScope>._)) |
||||
|
.MustHaveHappened(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Should_describe_content_script() |
||||
|
{ |
||||
|
var result = sut.ContentScript(dataSchema); |
||||
|
|
||||
|
AssertCompletion(result, |
||||
|
PresetUser("ctx.user"), |
||||
|
new[] |
||||
|
{ |
||||
|
"ctx", |
||||
|
"ctx.appId", |
||||
|
"ctx.appName", |
||||
|
"ctx.contentId", |
||||
|
"ctx.data", |
||||
|
"ctx.data['my-field']", |
||||
|
"ctx.data['my-field'].iv", |
||||
|
"ctx.dataOld", |
||||
|
"ctx.dataOld['my-field']", |
||||
|
"ctx.dataOld['my-field'].iv", |
||||
|
"ctx.oldData", |
||||
|
"ctx.oldData['my-field']", |
||||
|
"ctx.oldData['my-field'].iv", |
||||
|
"ctx.oldStatus", |
||||
|
"ctx.operation", |
||||
|
"ctx.permanent", |
||||
|
"ctx.schemaId", |
||||
|
"ctx.schemaName", |
||||
|
"ctx.status", |
||||
|
"ctx.statusOld" |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Should_describe_asset_script() |
||||
|
{ |
||||
|
var result = sut.AssetScript(); |
||||
|
|
||||
|
AssertCompletion(result, |
||||
|
PresetUser("ctx.user"), |
||||
|
new[] |
||||
|
{ |
||||
|
"ctx", |
||||
|
"ctx.appId", |
||||
|
"ctx.appName", |
||||
|
"ctx.asset", |
||||
|
"ctx.asset.fileHash", |
||||
|
"ctx.asset.fileName", |
||||
|
"ctx.asset.fileSize", |
||||
|
"ctx.asset.fileSlug", |
||||
|
"ctx.asset.fileVersion", |
||||
|
"ctx.asset.isProtected", |
||||
|
"ctx.asset.metadata", |
||||
|
"ctx.asset.metadata['my-name']", |
||||
|
"ctx.asset.mimeType", |
||||
|
"ctx.asset.parentId", |
||||
|
"ctx.asset.parentPath", |
||||
|
"ctx.asset.tags", |
||||
|
"ctx.assetId", |
||||
|
"ctx.command", |
||||
|
"ctx.command.fileHash", |
||||
|
"ctx.command.fileName", |
||||
|
"ctx.command.fileSize", |
||||
|
"ctx.command.fileSlug", |
||||
|
"ctx.command.isProtected", |
||||
|
"ctx.command.metadata", |
||||
|
"ctx.command.metadata['my-name']", |
||||
|
"ctx.command.mimeType", |
||||
|
"ctx.command.parentId", |
||||
|
"ctx.command.parentPath", |
||||
|
"ctx.command.permanent", |
||||
|
"ctx.command.tags", |
||||
|
"ctx.operation", |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Should_describe_content_trigger() |
||||
|
{ |
||||
|
var result = sut.ContentTrigger(dataSchema); |
||||
|
|
||||
|
AssertContentTrigger(result); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Should_describe_dynamic_content_trigger() |
||||
|
{ |
||||
|
var result = sut.Trigger("ContentChanged"); |
||||
|
|
||||
|
AssertContentTrigger(result); |
||||
|
} |
||||
|
|
||||
|
private static void AssertContentTrigger(IReadOnlyList<ScriptingValue> result) |
||||
|
{ |
||||
|
AssertCompletion(result, |
||||
|
PresetActor("event.actor"), |
||||
|
PresetUser("event.user"), |
||||
|
new[] |
||||
|
{ |
||||
|
"event", |
||||
|
"event.appId", |
||||
|
"event.appId.id", |
||||
|
"event.appId.name", |
||||
|
"event.created", |
||||
|
"event.createdBy", |
||||
|
"event.createdBy.identifier", |
||||
|
"event.createdBy.type", |
||||
|
"event.data", |
||||
|
"event.data['my-field']", |
||||
|
"event.data['my-field'].iv", |
||||
|
"event.dataOld", |
||||
|
"event.dataOld['my-field']", |
||||
|
"event.dataOld['my-field'].iv", |
||||
|
"event.lastModified", |
||||
|
"event.lastModifiedBy", |
||||
|
"event.lastModifiedBy.identifier", |
||||
|
"event.lastModifiedBy.type", |
||||
|
"event.id", |
||||
|
"event.name", |
||||
|
"event.newStatus", |
||||
|
"event.schemaId", |
||||
|
"event.schemaId.id", |
||||
|
"event.schemaId.name", |
||||
|
"event.status", |
||||
|
"event.timestamp", |
||||
|
"event.type", |
||||
|
"event.version" |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Should_describe_asset_trigger() |
||||
|
{ |
||||
|
var result = sut.AssetTrigger(); |
||||
|
|
||||
|
AssertAssetTrigger(result); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Should_describe_dynamicasset_trigger() |
||||
|
{ |
||||
|
var result = sut.Trigger("AssetChanged"); |
||||
|
|
||||
|
AssertAssetTrigger(result); |
||||
|
} |
||||
|
|
||||
|
private void AssertAssetTrigger(IReadOnlyList<ScriptingValue> result) |
||||
|
{ |
||||
|
AssertCompletion(result, |
||||
|
PresetActor("event.actor"), |
||||
|
PresetUser("event.user"), |
||||
|
new[] |
||||
|
{ |
||||
|
"event", |
||||
|
"event.appId", |
||||
|
"event.appId.id", |
||||
|
"event.appId.name", |
||||
|
"event.assetType", |
||||
|
"event.created", |
||||
|
"event.createdBy", |
||||
|
"event.createdBy.identifier", |
||||
|
"event.createdBy.type", |
||||
|
"event.fileHash", |
||||
|
"event.fileName", |
||||
|
"event.fileSize", |
||||
|
"event.fileVersion", |
||||
|
"event.isImage", |
||||
|
"event.isProtected", |
||||
|
"event.lastModified", |
||||
|
"event.lastModifiedBy", |
||||
|
"event.lastModifiedBy.identifier", |
||||
|
"event.lastModifiedBy.type", |
||||
|
"event.id", |
||||
|
"event.metadata", |
||||
|
"event.metadata['my-name']", |
||||
|
"event.mimeType", |
||||
|
"event.name", |
||||
|
"event.parentId", |
||||
|
"event.pixelHeight", |
||||
|
"event.pixelWidth", |
||||
|
"event.slug", |
||||
|
"event.timestamp", |
||||
|
"event.type", |
||||
|
"event.version" |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Should_describe_comment_trigger() |
||||
|
{ |
||||
|
var result = sut.CommentTrigger(); |
||||
|
|
||||
|
AssertCommentTrigger(result); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Should_describe_dynamic_comment_trigger() |
||||
|
{ |
||||
|
var result = sut.Trigger("Comment"); |
||||
|
|
||||
|
AssertCommentTrigger(result); |
||||
|
} |
||||
|
|
||||
|
private static void AssertCommentTrigger(IReadOnlyList<ScriptingValue> result) |
||||
|
{ |
||||
|
AssertCompletion(result, |
||||
|
PresetActor("event.actor"), |
||||
|
PresetUser("event.user"), |
||||
|
PresetUser("event.mentionedUser"), |
||||
|
new[] |
||||
|
{ |
||||
|
"event", |
||||
|
"event.appId", |
||||
|
"event.appId.id", |
||||
|
"event.appId.name", |
||||
|
"event.name", |
||||
|
"event.text", |
||||
|
"event.timestamp", |
||||
|
"event.version" |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Should_describe_schema_trigger() |
||||
|
{ |
||||
|
var result = sut.SchemaTrigger(); |
||||
|
|
||||
|
AssertSchemaTrigger(result); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Should_describe_dynamic_schema_trigger() |
||||
|
{ |
||||
|
var result = sut.Trigger("SchemaChanged"); |
||||
|
|
||||
|
AssertSchemaTrigger(result); |
||||
|
} |
||||
|
|
||||
|
private static void AssertSchemaTrigger(IReadOnlyList<ScriptingValue> result) |
||||
|
{ |
||||
|
AssertCompletion(result, |
||||
|
PresetActor("event.actor"), |
||||
|
PresetUser("event.user"), |
||||
|
new[] |
||||
|
{ |
||||
|
"event", |
||||
|
"event.appId", |
||||
|
"event.appId.id", |
||||
|
"event.appId.name", |
||||
|
"event.name", |
||||
|
"event.schemaId", |
||||
|
"event.schemaId.id", |
||||
|
"event.schemaId.name", |
||||
|
"event.timestamp", |
||||
|
"event.type", |
||||
|
"event.version" |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Should_describe_usage_trigger() |
||||
|
{ |
||||
|
var result = sut.UsageTrigger(); |
||||
|
|
||||
|
AssertUsageTrigger(result); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Should_describe_dynamic_usage_trigger() |
||||
|
{ |
||||
|
var result = sut.Trigger("Usage"); |
||||
|
|
||||
|
AssertUsageTrigger(result); |
||||
|
} |
||||
|
|
||||
|
private static void AssertUsageTrigger(IReadOnlyList<ScriptingValue> result) |
||||
|
{ |
||||
|
AssertCompletion(result, |
||||
|
new[] |
||||
|
{ |
||||
|
"event", |
||||
|
"event.appId", |
||||
|
"event.appId.id", |
||||
|
"event.appId.name", |
||||
|
"event.callsCurrent", |
||||
|
"event.callsLimit", |
||||
|
"event.name", |
||||
|
"event.timestamp", |
||||
|
"event.version" |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private static void AssertCompletion(IReadOnlyList<ScriptingValue> result, params string[][] expected) |
||||
|
{ |
||||
|
var allExpected = expected.SelectMany(x => x).ToArray(); |
||||
|
|
||||
|
var paths = result.Select(x => x.Path).ToArray(); |
||||
|
|
||||
|
foreach (var value in paths) |
||||
|
{ |
||||
|
Assert.Contains(value, allExpected); |
||||
|
} |
||||
|
|
||||
|
foreach (var value in allExpected) |
||||
|
{ |
||||
|
Assert.Contains(value, paths); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private static string[] PresetActor(string path) |
||||
|
{ |
||||
|
return new[] |
||||
|
{ |
||||
|
$"{path}", |
||||
|
$"{path}.identifier", |
||||
|
$"{path}.type" |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
private static string[] PresetUser(string path) |
||||
|
{ |
||||
|
return new[] |
||||
|
{ |
||||
|
$"{path}", |
||||
|
$"{path}.claims", |
||||
|
$"{path}.claims.name", |
||||
|
$"{path}.email", |
||||
|
$"{path}.id", |
||||
|
$"{path}.isClient", |
||||
|
$"{path}.isUser", |
||||
|
}; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue