@macrowing/inbiz-codegen 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +592 -2
- package/bin/inbiz-codegen.mjs +7 -0
- package/package.json +32 -4
- package/scripts/prepare-templates.mjs +35 -0
- package/src/backend/init.mjs +170 -0
- package/src/config.mjs +150 -0
- package/src/favicon.mjs +100 -0
- package/src/generate.mjs +935 -0
- package/src/generated-output.mjs +107 -0
- package/src/index.mjs +346 -0
- package/src/menu/build.mjs +252 -0
- package/src/menu/check.mjs +163 -0
- package/src/menu/command.mjs +179 -0
- package/src/migrate-runtime.mjs +106 -0
- package/src/platform/client.mjs +167 -0
- package/src/platform/command.mjs +386 -0
- package/src/platform/pack.mjs +591 -0
- package/src/platform/recover.mjs +236 -0
- package/src/platform/startup.mjs +343 -0
- package/src/platform/state.mjs +116 -0
- package/src/platform/update.mjs +157 -0
- package/src/platform/zip.mjs +134 -0
- package/src/pull.mjs +284 -0
- package/src/scaffold/commands.mjs +349 -0
- package/src/scaffold/init.mjs +392 -0
- package/src/scaffold/template-files.mjs +40 -0
- package/src/scaffold/template-source.mjs +235 -0
- package/src/scaffold/template-sync.mjs +335 -0
- package/src/transform/heaviness.mjs +380 -0
- package/src/transform/preview-props.mjs +108 -0
- package/src/transform/published-page-links.mjs +61 -0
- package/src/transform/published-script.mjs +110 -0
- package/src/transform/registry.mjs +781 -0
- package/src/transform/schema-to-jsx.mjs +1708 -0
- package/src/util/des.mjs +10 -0
- package/templates/README.md +34 -0
- package/templates/backend/Directory.Build.props +19 -0
- package/templates/backend/Directory.Packages.props +49 -0
- package/templates/backend/Macrowing.Scaffold.slnx +13 -0
- package/templates/backend/host/Macrowing.Start/Init/app.json +8 -0
- package/templates/backend/host/Macrowing.Start/Init/menus.json +4 -0
- package/templates/backend/host/Macrowing.Start/Initialization/InitializationDefinition.cs +245 -0
- package/templates/backend/host/Macrowing.Start/Initialization/InitializationEndpoints.cs +57 -0
- package/templates/backend/host/Macrowing.Start/Initialization/InitializationHostedService.cs +63 -0
- package/templates/backend/host/Macrowing.Start/Initialization/InitializationOptions.cs +44 -0
- package/templates/backend/host/Macrowing.Start/Initialization/InitializationRunner.cs +294 -0
- package/templates/backend/host/Macrowing.Start/Initialization/InitializationState.cs +72 -0
- package/templates/backend/host/Macrowing.Start/Initialization/MenuFactory.cs +118 -0
- package/templates/backend/host/Macrowing.Start/Initialization/PackageBuilder.cs +317 -0
- package/templates/backend/host/Macrowing.Start/Initialization/PlatformAppImporter.cs +371 -0
- package/templates/backend/host/Macrowing.Start/Macrowing.Start.csproj +26 -0
- package/templates/backend/host/Macrowing.Start/Program.cs +33 -0
- package/templates/backend/host/Macrowing.Start/StartModule.cs +67 -0
- package/templates/backend/host/Macrowing.Start/appsettings.json +38 -0
- package/templates/backend/modules/Macrowing.Generated/Application/GeneratedApplicationAutoMapperProfile.cs +42 -0
- package/templates/backend/modules/Macrowing.Generated/Domain/Entities/GeneratedEntityBase.cs +72 -0
- package/templates/backend/modules/Macrowing.Generated/Domain/GeneratedConsts.cs +50 -0
- package/templates/backend/modules/Macrowing.Generated/EntityFrameworkCore/GeneratedDbContext.cs +55 -0
- package/templates/backend/modules/Macrowing.Generated/EntityFrameworkCore/GeneratedDbContextModelBuilderExtensions.cs +61 -0
- package/templates/backend/modules/Macrowing.Generated/EntityFrameworkCore/IGeneratedDbContext.cs +32 -0
- package/templates/backend/modules/Macrowing.Generated/GeneratedModule.cs +89 -0
- package/templates/backend/modules/Macrowing.Generated/Macrowing.Generated.csproj +22 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Cms/CmsClient.cs +95 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Cms/CmsModels.cs +81 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Dictionary/DictionaryClient.cs +44 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/InBizSdkModule.cs +16 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/InterfaceEngine/InterfaceEngineClient.cs +50 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Localization/LocalizationClient.cs +28 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Macrowing.InBiz.SDK.csproj +16 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Message/MessageClient.cs +99 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Message/MessageModels.cs +63 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Model/ModelClient.cs +131 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Model/ModelQuery.cs +108 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Model/ModelWrite.cs +44 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Permission/PermissionClient.cs +86 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Platform/InBizPlatformException.cs +42 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Platform/InBizPlatformRegistration.cs +60 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Platform/InBizPlatformTransport.cs +96 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Platform/InBizRequestContext.cs +27 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/README.md +117 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Details/WorkFlowDetailsClient.cs +35 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Details/WorkFlowDetailsQuery.cs +20 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Operations/WorkFlowOperationRequests.cs +105 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Operations/WorkFlowOperationsClient.cs +53 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/README.md +132 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Tracking/WorkFlowTrackingClient.cs +50 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Upgrade/WorkFlowUpgradeClient.cs +78 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Upgrade/WorkFlowUpgradeModels.cs +34 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/WorkFlowContracts.cs +88 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/WorkFlowRegistration.cs +59 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/WorkFlowTransport.cs +163 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Workbench/WorkFlowWorkbenchClient.cs +59 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Workbench/WorkFlowWorkbenchModels.cs +76 -0
- package/templates/backend/modules/Macrowing.OC.SDK/Macrowing.OC.SDK.csproj +20 -0
- package/templates/backend/modules/Macrowing.OC.SDK/OcSdkModule.cs +18 -0
- package/templates/backend/modules/Macrowing.OC.SDK/Protos/README.md +22 -0
- package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/Macrowing.InBiz.SDK.Tests.csproj +14 -0
- package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/PlatformContractTests.cs +288 -0
- package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/PlatformLiveTests.cs +173 -0
- package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/WorkFlowHttpServer.cs +113 -0
- package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/WorkFlowLiveTests.cs +269 -0
- package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/WorkFlowOperationsTests.cs +80 -0
- package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/WorkFlowQueryTests.cs +163 -0
- package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/WorkFlowTransportTests.cs +111 -0
- package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/WorkFlowUpgradeTests.cs +87 -0
- package/templates/frontend/components/README.md +39 -0
- package/templates/frontend/components/app-components/README.md +33 -0
- package/templates/frontend/components/app-components/common/.gitkeep +0 -0
- package/templates/frontend/components/app-components/components/.gitkeep +0 -0
- package/templates/frontend/components/app-components/package.json +20 -0
- package/templates/frontend/mgt/.umirc.ts +574 -0
- package/templates/frontend/mgt/package.json +96 -0
- package/templates/frontend/mgt/src/app-extends.ts +9 -0
- package/templates/frontend/mgt/src/app.tsx +20 -0
- package/templates/frontend/mgt/src/config/app.ts +31 -0
- package/templates/frontend/mgt/src/layout/header.tsx +14 -0
- package/templates/frontend/mgt/src/layout/index.tsx +11 -0
- package/templates/frontend/mgt/src/layout/sidebar.tsx +14 -0
- package/templates/frontend/mgt/src/locales.ts +8 -0
- package/templates/frontend/mgt/src/pages/.gitkeep +0 -0
- package/templates/frontend/mgt/src/root.tsx +12 -0
- package/templates/frontend/mgt/src/route-view.tsx +3 -0
- package/templates/frontend/mgt/src/runtime.ts +21 -0
- package/templates/frontend/mgt/src/styles/app.css +1 -0
- package/templates/frontend/mgt/src/styles/layout.less +79 -0
- package/templates/frontend/mgt/tsconfig.json +65 -0
- package/templates/frontend/mgt/typings.d.ts +57 -0
- package/templates/frontend/wap/.umirc.ts +574 -0
- package/templates/frontend/wap/package.json +73 -0
- package/templates/frontend/wap/src/app-extends.ts +9 -0
- package/templates/frontend/wap/src/app.tsx +28 -0
- package/templates/frontend/wap/src/config/app.ts +31 -0
- package/templates/frontend/wap/src/layout/header.tsx +14 -0
- package/templates/frontend/wap/src/layout/index.tsx +18 -0
- package/templates/frontend/wap/src/layout/sidebar.tsx +14 -0
- package/templates/frontend/wap/src/locales.ts +8 -0
- package/templates/frontend/wap/src/pages/.gitkeep +0 -0
- package/templates/frontend/wap/src/root.tsx +12 -0
- package/templates/frontend/wap/src/route-view.tsx +3 -0
- package/templates/frontend/wap/src/runtime.ts +21 -0
- package/templates/frontend/wap/src/styles/adaptation.less +190 -0
- package/templates/frontend/wap/src/styles/app.css +7 -0
- package/templates/frontend/wap/src/styles/global.less +81 -0
- package/templates/frontend/wap/src/styles/layout.less +92 -0
- package/templates/frontend/wap/tsconfig.json +66 -0
- package/templates/frontend/wap/typings.d.ts +24 -0
- package/templates/frontend/web/.umirc.ts +574 -0
- package/templates/frontend/web/package.json +26 -0
- package/templates/frontend/web/src/app-extends.ts +9 -0
- package/templates/frontend/web/src/app.tsx +25 -0
- package/templates/frontend/web/src/config/app.ts +31 -0
- package/templates/frontend/web/src/layout/header.tsx +14 -0
- package/templates/frontend/web/src/layout/index.tsx +11 -0
- package/templates/frontend/web/src/layout/sidebar.tsx +14 -0
- package/templates/frontend/web/src/locales.ts +8 -0
- package/templates/frontend/web/src/root.tsx +12 -0
- package/templates/frontend/web/src/route-view.tsx +3 -0
- package/templates/frontend/web/src/runtime.ts +21 -0
- package/templates/frontend/web/src/styles/app.css +104 -0
- package/templates/frontend/web/src/styles/layout.less +124 -0
- package/templates/frontend/web/tsconfig.json +91 -0
- package/templates/frontend/web/typings.d.ts +46 -0
- package/templates/package.json +14 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
using Macrowing.InBiz.SDK.Cms;
|
|
2
|
+
using Macrowing.InBiz.SDK.Dictionary;
|
|
3
|
+
using Macrowing.InBiz.SDK.InterfaceEngine;
|
|
4
|
+
using Macrowing.InBiz.SDK.Localization;
|
|
5
|
+
using Macrowing.InBiz.SDK.Message;
|
|
6
|
+
using Macrowing.InBiz.SDK.Model;
|
|
7
|
+
using Macrowing.InBiz.SDK.Permission;
|
|
8
|
+
using Macrowing.InBiz.SDK.Platform;
|
|
9
|
+
using Microsoft.Extensions.Configuration;
|
|
10
|
+
using Microsoft.Extensions.DependencyInjection;
|
|
11
|
+
using Xunit.Abstractions;
|
|
12
|
+
|
|
13
|
+
namespace Macrowing.InBiz.SDK.Tests;
|
|
14
|
+
|
|
15
|
+
public sealed class PlatformLiveFactAttribute : FactAttribute
|
|
16
|
+
{
|
|
17
|
+
public PlatformLiveFactAttribute(params string[] fixtureKeys)
|
|
18
|
+
{
|
|
19
|
+
if (Environment.GetEnvironmentVariable("INBIZ_PLATFORM_LIVE") != "read-only")
|
|
20
|
+
Skip = "Requires an explicitly enabled InBiz gateway and authenticated test session.";
|
|
21
|
+
else if (fixtureKeys.Any(key => string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("INBIZ_PLATFORM_" + key))))
|
|
22
|
+
Skip = "Requires fixture settings: " + string.Join(", ", fixtureKeys.Select(key => "INBIZ_PLATFORM_" + key));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
[Trait("Category", "PlatformLive")]
|
|
27
|
+
public sealed class PlatformLiveTests(ITestOutputHelper output)
|
|
28
|
+
{
|
|
29
|
+
[PlatformLiveFact]
|
|
30
|
+
public async Task AuthorizedAccountHasManagementAndConfiguredMenuAccess()
|
|
31
|
+
{
|
|
32
|
+
await using var run = new Session();
|
|
33
|
+
var permission = run.Get<IPermissionClient>();
|
|
34
|
+
Assert.True(await permission.HasApplicationManagementAccessAsync(run.Context));
|
|
35
|
+
var routes = Required("ALLOWED_ROUTES").Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
|
|
36
|
+
var decisions = await permission.GetMenuRoutesAsync(run.Context, Required("SITE_OUT_ID"), routes);
|
|
37
|
+
foreach (var route in routes)
|
|
38
|
+
Assert.True(Assert.Single(decisions, decision => decision.Route == route).IsHavePerm);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
[PlatformLiveFact]
|
|
42
|
+
public async Task CmsReadsConfiguredCategoryAndListsThenFindsItsContent()
|
|
43
|
+
{
|
|
44
|
+
await using var run = new Session();
|
|
45
|
+
var cms = run.Get<ICmsClient>();
|
|
46
|
+
var categories = await cms.GetCategoriesAsync(run.Context, CmsContentKind.Image);
|
|
47
|
+
var category = Assert.Single(categories, item => item.Key == Required("CMS_IMAGE_CATEGORY"));
|
|
48
|
+
Assert.False(string.IsNullOrWhiteSpace(category.Title));
|
|
49
|
+
var page = await cms.ListAsync(run.Context, new(CmsContentKind.Image, category.Key));
|
|
50
|
+
Assert.True(page.Total > 0);
|
|
51
|
+
Assert.Equal(1, page.PageIndex);
|
|
52
|
+
var item = Assert.Single(page.ContentList, entry => entry.Id == Required("CMS_IMAGE_CONTENT"));
|
|
53
|
+
var detail = await cms.GetAsync(run.Context, item.Id);
|
|
54
|
+
Assert.NotNull(detail);
|
|
55
|
+
Assert.False(string.IsNullOrWhiteSpace(detail.Title));
|
|
56
|
+
Assert.Equal(item.Id, detail.Id);
|
|
57
|
+
Assert.Equal(item.Title, detail.Title);
|
|
58
|
+
output.WriteLine($"CMS image categories: {categories.Count}; records in fixture category: {page.Total}.");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
[PlatformLiveFact]
|
|
62
|
+
public async Task MissingModelAndInterfaceDefinitionsHaveDistinctBusinessErrors()
|
|
63
|
+
{
|
|
64
|
+
await using var run = new Session();
|
|
65
|
+
var model = run.Get<IModelClient>();
|
|
66
|
+
var interfaces = run.Get<IInterfaceEngineClient>();
|
|
67
|
+
var missing = MissingKey();
|
|
68
|
+
await CheckBusinessErrorAsync("model:00031", () => model.QueryAsync(run.Context, new(missing)));
|
|
69
|
+
await CheckBusinessErrorAsync("model:00021", () => model.GetAsync(run.Context, missing, missing));
|
|
70
|
+
await CheckBusinessErrorAsync("api:00001", () => interfaces.InvokeAsync(run.Context, new(missing)));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
[PlatformLiveFact]
|
|
74
|
+
public async Task UnknownDictionaryGroupAndTemplateReturnEmptyResults()
|
|
75
|
+
{
|
|
76
|
+
await using var run = new Session();
|
|
77
|
+
var missing = MissingKey();
|
|
78
|
+
Assert.Empty(await run.Get<IDictionaryClient>().GetGroupsAsync(run.Context, [missing], Required("LANGUAGE")));
|
|
79
|
+
Assert.Empty(await run.Get<IMessageClient>().GetTemplateAsync(run.Context, missing));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
[PlatformLiveFact]
|
|
83
|
+
public async Task PublishedBusinessTranslationsReturnAnObject()
|
|
84
|
+
{
|
|
85
|
+
await using var run = new Session();
|
|
86
|
+
var translations = await run.Get<ILocalizationClient>().GetTextsAsync(run.Context, Required("LANGUAGE"));
|
|
87
|
+
output.WriteLine($"Published entries: {translations.Count}.");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
[PlatformLiveFact("MODEL_QUERY_KEY", "MODEL_NAME", "MODEL_RECORD_ID", "MODEL_PRIMARY_FIELD")]
|
|
91
|
+
public async Task PublishedModelQueryAndRecordExposeTheExpectedPrimaryKey()
|
|
92
|
+
{
|
|
93
|
+
await using var run = new Session("MODEL_APP_ID");
|
|
94
|
+
var model = run.Get<IModelClient>();
|
|
95
|
+
var page = await model.QueryAsync(run.Context, new(Required("MODEL_QUERY_KEY")));
|
|
96
|
+
Assert.NotNull(page);
|
|
97
|
+
Assert.NotEmpty(page.Rows);
|
|
98
|
+
Assert.True(page.Total >= page.Rows.Count);
|
|
99
|
+
var primary = Required("MODEL_PRIMARY_FIELD");
|
|
100
|
+
Assert.All(page.Rows, row => Assert.True(row.ContainsKey(primary)));
|
|
101
|
+
var id = Required("MODEL_RECORD_ID");
|
|
102
|
+
Assert.Contains(page.Rows, row => row[primary].ToString() == id);
|
|
103
|
+
var record = await model.GetAsync(run.Context, Required("MODEL_NAME"), id);
|
|
104
|
+
Assert.Equal(id, record[primary].ToString());
|
|
105
|
+
output.WriteLine($"Published model rows: {page.Rows.Count}; record from query verified by ID.");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
[PlatformLiveFact("DICTIONARY_GROUP_KEY", "DICTIONARY_VALUE")]
|
|
109
|
+
public async Task ConfiguredDictionaryContainsTheExpectedValueAndLabel()
|
|
110
|
+
{
|
|
111
|
+
await using var run = new Session("DICTIONARY_APP_ID");
|
|
112
|
+
var group = Required("DICTIONARY_GROUP_KEY");
|
|
113
|
+
var entries = await run.Get<IDictionaryClient>().GetGroupsAsync(run.Context, [group], Required("LANGUAGE"));
|
|
114
|
+
var entry = Assert.Single(entries[group], item => item.Value == Required("DICTIONARY_VALUE"));
|
|
115
|
+
Assert.False(string.IsNullOrWhiteSpace(entry.Text));
|
|
116
|
+
output.WriteLine($"Dictionary choices in fixture group: {entries[group].Count}.");
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
[PlatformLiveFact("MESSAGE_TEMPLATE_KEY")]
|
|
120
|
+
public async Task ConfiguredMessageTemplateReturnsRealChannelContentWithoutSending()
|
|
121
|
+
{
|
|
122
|
+
await using var run = new Session("MESSAGE_APP_ID");
|
|
123
|
+
var template = Required("MESSAGE_TEMPLATE_KEY");
|
|
124
|
+
var channels = await run.Get<IMessageClient>().GetTemplateAsync(run.Context, template);
|
|
125
|
+
Assert.NotEmpty(channels);
|
|
126
|
+
Assert.All(channels, channel => Assert.Equal(template, channel.TemplateKey));
|
|
127
|
+
Assert.Contains(channels, channel => !string.IsNullOrWhiteSpace(channel.Title) || !string.IsNullOrWhiteSpace(channel.Content));
|
|
128
|
+
output.WriteLine($"Message channel configurations: {channels.Count}; no send performed.");
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
[PlatformLiveFact("TRANSLATION_KEY", "TRANSLATION_VALUE")]
|
|
132
|
+
public async Task PublishedBusinessTranslationPreservesItsValue()
|
|
133
|
+
{
|
|
134
|
+
await using var run = new Session("LOCALIZATION_APP_ID");
|
|
135
|
+
var translations = await run.Get<ILocalizationClient>().GetTextsAsync(run.Context, Required("LANGUAGE"));
|
|
136
|
+
Assert.Equal(Required("TRANSLATION_VALUE"), translations[Required("TRANSLATION_KEY")].GetString());
|
|
137
|
+
output.WriteLine($"Published entries: {translations.Count}; fixture translation value verified.");
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private static async Task CheckBusinessErrorAsync(string code, Func<Task> operation)
|
|
141
|
+
{
|
|
142
|
+
var error = await Assert.ThrowsAsync<InBizPlatformException>(operation);
|
|
143
|
+
Assert.Equal(InBizFailureKind.Business, error.Kind);
|
|
144
|
+
Assert.Equal(code, error.ErrorCode);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
private static string MissingKey() => "sdk-missing-" + Guid.NewGuid().ToString("N");
|
|
148
|
+
|
|
149
|
+
private static string Required(string key) =>
|
|
150
|
+
Environment.GetEnvironmentVariable("INBIZ_PLATFORM_" + key) is { } value && !string.IsNullOrWhiteSpace(value)
|
|
151
|
+
? value
|
|
152
|
+
: throw new InvalidOperationException($"Missing live platform setting: INBIZ_PLATFORM_{key}.");
|
|
153
|
+
|
|
154
|
+
private sealed class Session : IAsyncDisposable
|
|
155
|
+
{
|
|
156
|
+
private readonly ServiceProvider services;
|
|
157
|
+
public InBizRequestContext Context { get; }
|
|
158
|
+
|
|
159
|
+
public Session(string? appOverrideKey = null)
|
|
160
|
+
{
|
|
161
|
+
var appOverride = appOverrideKey is null ? null : Environment.GetEnvironmentVariable("INBIZ_PLATFORM_" + appOverrideKey);
|
|
162
|
+
Context = new(string.IsNullOrWhiteSpace(appOverride) ? Required("APP_ID") : appOverride, Required("TOKEN"));
|
|
163
|
+
var configuration = new ConfigurationBuilder().AddInMemoryCollection(
|
|
164
|
+
new Dictionary<string, string?> { ["InBiz:Platform:BaseUrl"] = Required("BASE_URL") }).Build();
|
|
165
|
+
services = new ServiceCollection().AddSingleton<IConfiguration>(configuration)
|
|
166
|
+
.AddInBizPlatform().BuildServiceProvider();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
public T Get<T>() where T : notnull => services.GetRequiredService<T>();
|
|
170
|
+
|
|
171
|
+
public ValueTask DisposeAsync() => services.DisposeAsync();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
using System.Collections.Concurrent;
|
|
2
|
+
using System.Net;
|
|
3
|
+
using System.Text.Json.Nodes;
|
|
4
|
+
using Macrowing.InBiz.SDK.WorkFlow;
|
|
5
|
+
using Microsoft.AspNetCore.Builder;
|
|
6
|
+
using Microsoft.AspNetCore.Hosting;
|
|
7
|
+
using Microsoft.AspNetCore.Http;
|
|
8
|
+
using Microsoft.AspNetCore.Http.Features;
|
|
9
|
+
using Microsoft.Extensions.Configuration;
|
|
10
|
+
using Microsoft.Extensions.DependencyInjection;
|
|
11
|
+
using Microsoft.Extensions.Logging;
|
|
12
|
+
using Volo.Abp.Modularity;
|
|
13
|
+
|
|
14
|
+
namespace Macrowing.InBiz.SDK.Tests;
|
|
15
|
+
|
|
16
|
+
internal sealed class WorkFlowHttpServer(WebApplication app, ServiceProvider services, ConcurrentQueue<WorkFlowHttpServer.Request> requests) : IAsyncDisposable
|
|
17
|
+
{
|
|
18
|
+
internal const string OrgToken = "org+token/&=?";
|
|
19
|
+
internal const string LoginName = "example+user";
|
|
20
|
+
internal const string Jwt = "jwt+token/&=?";
|
|
21
|
+
internal static WorkFlowCredential Credential => WorkFlowCredential.Organization(OrgToken, LoginName);
|
|
22
|
+
|
|
23
|
+
internal sealed record Request(string Method, string Path, string RawTarget, string Version, string Accept, string Cookie,
|
|
24
|
+
string? ContentType, string Body, Dictionary<string, string> Query, string AppId, string Token);
|
|
25
|
+
|
|
26
|
+
internal sealed record Response(string Body, int Status = 200, string ContentType = "application/json",
|
|
27
|
+
string? Location = null, string? SetCookie = null, bool AbpError = false);
|
|
28
|
+
|
|
29
|
+
internal static Task<WorkFlowHttpServer> StartAsync(params Response[] responses)
|
|
30
|
+
{
|
|
31
|
+
var pending = new ConcurrentQueue<Response>(responses);
|
|
32
|
+
return StartAsync(async context =>
|
|
33
|
+
{
|
|
34
|
+
var response = pending.TryDequeue(out var next) ? next : new Response("Unexpected request", 500);
|
|
35
|
+
context.Response.StatusCode = response.Status;
|
|
36
|
+
context.Response.ContentType = response.ContentType;
|
|
37
|
+
if (response.Location is not null)
|
|
38
|
+
context.Response.Headers.Location = response.Location;
|
|
39
|
+
if (response.SetCookie is not null)
|
|
40
|
+
context.Response.Headers.SetCookie = response.SetCookie;
|
|
41
|
+
if (response.AbpError)
|
|
42
|
+
context.Response.Headers["_AbpErrorFormat"] = "true";
|
|
43
|
+
if (response.Body.Length > 0)
|
|
44
|
+
await context.Response.WriteAsync(response.Body);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
internal static async Task<WorkFlowHttpServer> StartAsync(RequestDelegate respond)
|
|
49
|
+
{
|
|
50
|
+
var builder = WebApplication.CreateSlimBuilder();
|
|
51
|
+
builder.Logging.ClearProviders();
|
|
52
|
+
builder.WebHost.ConfigureKestrel(server => server.Listen(IPAddress.Loopback, 0));
|
|
53
|
+
var app = builder.Build();
|
|
54
|
+
var requests = new ConcurrentQueue<Request>();
|
|
55
|
+
app.Run(async context =>
|
|
56
|
+
{
|
|
57
|
+
var request = context.Request;
|
|
58
|
+
using var reader = new StreamReader(request.Body);
|
|
59
|
+
requests.Enqueue(new(request.Method, request.Path.Value!, context.Features.Get<IHttpRequestFeature>()!.RawTarget!,
|
|
60
|
+
request.Headers["vVersion"].ToString(), request.Headers.Accept.ToString(), request.Headers.Cookie.ToString(),
|
|
61
|
+
request.ContentType, await reader.ReadToEndAsync(context.RequestAborted),
|
|
62
|
+
request.Query.ToDictionary(pair => pair.Key, pair => pair.Value.ToString(), StringComparer.Ordinal),
|
|
63
|
+
request.Headers["appId"].ToString(), request.Headers["token"].ToString()));
|
|
64
|
+
await respond(context);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
await app.StartAsync();
|
|
68
|
+
var services = new ServiceCollection();
|
|
69
|
+
services.AddSingleton<IConfiguration>(new ConfigurationBuilder().AddInMemoryCollection(new Dictionary<string, string?>
|
|
70
|
+
{
|
|
71
|
+
["InBiz:WorkFlow:BaseUrl"] = app.Urls.Single() + "/edoc2Flow-web",
|
|
72
|
+
["InBiz:WorkFlow:Timeout"] = "00:00:15",
|
|
73
|
+
["InBiz:Platform:BaseUrl"] = app.Urls.Single() + "/inbiz",
|
|
74
|
+
["InBiz:Platform:Timeout"] = "00:00:15"
|
|
75
|
+
}).Build());
|
|
76
|
+
services.AddOptions();
|
|
77
|
+
new InBizSdkModule().ConfigureServices(new ServiceConfigurationContext(services));
|
|
78
|
+
return new(app, services.BuildServiceProvider(), requests);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
internal T Client<T>() where T : notnull => services.GetRequiredService<T>();
|
|
82
|
+
|
|
83
|
+
internal Request[] Requests => requests.ToArray();
|
|
84
|
+
|
|
85
|
+
internal static void AssertRequest(Request actual, string method, string route, (string Name, string Value)[]? query = null,
|
|
86
|
+
string? json = null, bool withJwt = false)
|
|
87
|
+
{
|
|
88
|
+
Assert.Equal(method, actual.Method);
|
|
89
|
+
Assert.Equal("/edoc2Flow-web/" + route, actual.Path);
|
|
90
|
+
Assert.Equal("6", actual.Version);
|
|
91
|
+
Assert.Equal("application/json", actual.Accept);
|
|
92
|
+
Assert.Empty(actual.Cookie);
|
|
93
|
+
var auth = withJwt ? new[] { ("token", Jwt) } : [("orgToken", OrgToken), ("loginName", LoginName)];
|
|
94
|
+
Assert.Equal(auth.Concat(query ?? []).OrderBy(pair => pair.Item1),
|
|
95
|
+
actual.Query.Select(pair => (pair.Key, pair.Value)).OrderBy(pair => pair.Key));
|
|
96
|
+
if (json is null)
|
|
97
|
+
{
|
|
98
|
+
Assert.Null(actual.ContentType);
|
|
99
|
+
Assert.Empty(actual.Body);
|
|
100
|
+
}
|
|
101
|
+
else
|
|
102
|
+
{
|
|
103
|
+
Assert.StartsWith("application/json", actual.ContentType);
|
|
104
|
+
Assert.True(JsonNode.DeepEquals(JsonNode.Parse(json), JsonNode.Parse(actual.Body)), actual.Body);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public async ValueTask DisposeAsync()
|
|
109
|
+
{
|
|
110
|
+
await services.DisposeAsync();
|
|
111
|
+
await app.DisposeAsync();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
using System.Globalization;
|
|
2
|
+
using System.Text.Json;
|
|
3
|
+
using Macrowing.InBiz.SDK.WorkFlow;
|
|
4
|
+
using Microsoft.Extensions.Configuration;
|
|
5
|
+
using Microsoft.Extensions.DependencyInjection;
|
|
6
|
+
using Xunit.Abstractions;
|
|
7
|
+
|
|
8
|
+
namespace Macrowing.InBiz.SDK.Tests;
|
|
9
|
+
|
|
10
|
+
public sealed class WorkFlowLiveFactAttribute : FactAttribute
|
|
11
|
+
{
|
|
12
|
+
public WorkFlowLiveFactAttribute()
|
|
13
|
+
{
|
|
14
|
+
if (Environment.GetEnvironmentVariable("INBIZ_WF_LIVE") != "isolated-test")
|
|
15
|
+
Skip = "Requires an explicitly enabled, writable edoc2Flow test environment.";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
[Trait("Category", "WorkFlowLive")]
|
|
20
|
+
public sealed class WorkFlowLiveTests(ITestOutputHelper output)
|
|
21
|
+
{
|
|
22
|
+
[WorkFlowLiveFact]
|
|
23
|
+
public async Task ReturnThenStopUpdatesPendingTasksAndHistory()
|
|
24
|
+
{
|
|
25
|
+
using var cancellation = new CancellationTokenSource(TimeSpan.FromMinutes(2));
|
|
26
|
+
await using var run = new Scenario(output, cancellation.Token);
|
|
27
|
+
var instanceId = await run.StartAsync("return-stop");
|
|
28
|
+
var firstTask = await run.RequirePendingAsync(run.Starter, instanceId, run.FirstStep);
|
|
29
|
+
await run.CompleteAsync(run.Starter, firstTask);
|
|
30
|
+
await run.RequireNoPendingAsync(run.Starter, instanceId);
|
|
31
|
+
await run.RequireCompletedAsync(run.Starter, instanceId, firstTask);
|
|
32
|
+
var reviewTask = await run.RequirePendingAsync(run.Reviewer, instanceId, run.ReviewStep);
|
|
33
|
+
|
|
34
|
+
var returnComment = run.Marker + " return";
|
|
35
|
+
await run.Operations.ReturnTaskAsync(run.Reviewer.Credential,
|
|
36
|
+
new(reviewTask, WorkFlowReturnTarget.PreviousStep) { Comment = returnComment }, cancellation.Token);
|
|
37
|
+
await run.RequireNoPendingAsync(run.Reviewer, instanceId);
|
|
38
|
+
var returnedTask = await run.RequirePendingAsync(run.Starter, instanceId, run.FirstStep);
|
|
39
|
+
Assert.NotEqual(firstTask, returnedTask);
|
|
40
|
+
await run.RequireInitiatedStateAsync(instanceId, 0);
|
|
41
|
+
await run.RequireCompletedAsync(run.Reviewer, instanceId, reviewTask);
|
|
42
|
+
await run.RequireLogAsync(run.Reviewer, instanceId, reviewTask, returnComment, 5);
|
|
43
|
+
|
|
44
|
+
var stopComment = run.Marker + " stop";
|
|
45
|
+
await run.Operations.StopProcessAsync(run.Starter.Credential,
|
|
46
|
+
new(instanceId) { TaskId = returnedTask, Comment = stopComment }, cancellation.Token);
|
|
47
|
+
await run.RequireNoPendingAsync(run.Starter, instanceId);
|
|
48
|
+
await run.RequireNoPendingAsync(run.Reviewer, instanceId);
|
|
49
|
+
await run.RequireInitiatedStateAsync(instanceId, 1);
|
|
50
|
+
await run.RequireNoCompletedAsync(run.Starter, instanceId);
|
|
51
|
+
await run.RequireNoCompletedAsync(run.Reviewer, instanceId);
|
|
52
|
+
await run.RequireArchivedStateAsync(run.Starter, instanceId, 170);
|
|
53
|
+
await run.RequireArchivedStateAsync(run.Reviewer, instanceId, 170);
|
|
54
|
+
await run.RequireLogAsync(run.Starter, instanceId, returnedTask, stopComment, 170);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
[WorkFlowLiveFact]
|
|
58
|
+
public async Task NormalCompletionUpdatesPendingTasksAndArchive()
|
|
59
|
+
{
|
|
60
|
+
using var cancellation = new CancellationTokenSource(TimeSpan.FromMinutes(2));
|
|
61
|
+
await using var run = new Scenario(output, cancellation.Token);
|
|
62
|
+
var instanceId = await run.StartAsync("complete");
|
|
63
|
+
var firstTask = await run.RequirePendingAsync(run.Starter, instanceId, run.FirstStep);
|
|
64
|
+
await run.CompleteAsync(run.Starter, firstTask);
|
|
65
|
+
await run.RequireNoPendingAsync(run.Starter, instanceId);
|
|
66
|
+
await run.RequireCompletedAsync(run.Starter, instanceId, firstTask);
|
|
67
|
+
var reviewTask = await run.RequirePendingAsync(run.Reviewer, instanceId, run.ReviewStep);
|
|
68
|
+
await run.CompleteAsync(run.Reviewer, reviewTask);
|
|
69
|
+
await run.RequireNoPendingAsync(run.Reviewer, instanceId);
|
|
70
|
+
await run.RequireNoPendingAsync(run.Starter, instanceId);
|
|
71
|
+
await run.RequireInitiatedStateAsync(instanceId, 20);
|
|
72
|
+
await run.RequireNoCompletedAsync(run.Starter, instanceId);
|
|
73
|
+
await run.RequireNoCompletedAsync(run.Reviewer, instanceId);
|
|
74
|
+
await run.RequireArchivedStateAsync(run.Starter, instanceId, 20);
|
|
75
|
+
await run.RequireArchivedStateAsync(run.Reviewer, instanceId, 20);
|
|
76
|
+
await run.RequireLogAsync(run.Starter, instanceId, firstTask, run.ApprovalComment);
|
|
77
|
+
await run.RequireLogAsync(run.Reviewer, instanceId, reviewTask, run.ApprovalComment);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private sealed record Actor(string UserId, WorkFlowCredential Credential)
|
|
81
|
+
{
|
|
82
|
+
public static Actor FromEnvironment(string role)
|
|
83
|
+
{
|
|
84
|
+
var prefix = "INBIZ_WF_" + role;
|
|
85
|
+
var userId = Required(prefix + "_USER_ID");
|
|
86
|
+
var orgToken = Environment.GetEnvironmentVariable(prefix + "_ORG_TOKEN");
|
|
87
|
+
var jwt = Environment.GetEnvironmentVariable(prefix + "_JWT");
|
|
88
|
+
if (string.IsNullOrWhiteSpace(orgToken) == string.IsNullOrWhiteSpace(jwt))
|
|
89
|
+
throw new InvalidOperationException($"Set exactly one of {prefix}_ORG_TOKEN and {prefix}_JWT.");
|
|
90
|
+
return new(userId, string.IsNullOrWhiteSpace(orgToken)
|
|
91
|
+
? WorkFlowCredential.Jwt(jwt!)
|
|
92
|
+
: WorkFlowCredential.Organization(orgToken, Environment.GetEnvironmentVariable(prefix + "_LOGIN_NAME")));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private sealed class Scenario : IAsyncDisposable
|
|
97
|
+
{
|
|
98
|
+
private readonly ServiceProvider services;
|
|
99
|
+
private readonly IWorkFlowWorkbenchClient workbench;
|
|
100
|
+
private readonly IWorkFlowTrackingClient tracking;
|
|
101
|
+
private readonly ITestOutputHelper output;
|
|
102
|
+
private readonly CancellationToken cancellation;
|
|
103
|
+
private readonly string definitionId = Required("INBIZ_WF_DEFINITION_ID");
|
|
104
|
+
private readonly string definitionName = Required("INBIZ_WF_DEFINITION_NAME");
|
|
105
|
+
|
|
106
|
+
public Actor Starter { get; } = Actor.FromEnvironment("STARTER");
|
|
107
|
+
public Actor Reviewer { get; } = Actor.FromEnvironment("REVIEWER");
|
|
108
|
+
public string FirstStep { get; } = Required("INBIZ_WF_FIRST_STEP");
|
|
109
|
+
public string ReviewStep { get; } = Required("INBIZ_WF_REVIEW_STEP");
|
|
110
|
+
public string Marker { get; } = "sdk-live-" + Guid.NewGuid().ToString("N");
|
|
111
|
+
public string ApprovalComment => Marker + " approve";
|
|
112
|
+
public IWorkFlowOperationsClient Operations { get; }
|
|
113
|
+
|
|
114
|
+
public Scenario(ITestOutputHelper output, CancellationToken cancellation)
|
|
115
|
+
{
|
|
116
|
+
this.output = output;
|
|
117
|
+
this.cancellation = cancellation;
|
|
118
|
+
if (!definitionName.StartsWith("SDK Acceptance ", StringComparison.Ordinal)
|
|
119
|
+
|| Starter.UserId == Reviewer.UserId || FirstStep == ReviewStep)
|
|
120
|
+
throw new InvalidOperationException("Use a dedicated SDK Acceptance definition, two users and two distinct steps.");
|
|
121
|
+
|
|
122
|
+
var baseUrl = Required("INBIZ_WF_BASE_URL");
|
|
123
|
+
var configuration = new ConfigurationBuilder().AddInMemoryCollection(
|
|
124
|
+
new Dictionary<string, string?> { ["InBiz:WorkFlow:BaseUrl"] = baseUrl }).Build();
|
|
125
|
+
services = new ServiceCollection().AddSingleton<IConfiguration>(configuration)
|
|
126
|
+
.AddInBizWorkFlow().BuildServiceProvider();
|
|
127
|
+
Operations = services.GetRequiredService<IWorkFlowOperationsClient>();
|
|
128
|
+
workbench = services.GetRequiredService<IWorkFlowWorkbenchClient>();
|
|
129
|
+
tracking = services.GetRequiredService<IWorkFlowTrackingClient>();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public async Task<string> StartAsync(string scenario)
|
|
133
|
+
{
|
|
134
|
+
var page = await workbench.GetStartableProcessesAsync(Starter.Credential,
|
|
135
|
+
new(Starter.UserId) { ProcessName = definitionName, PageIndex = 1, PageSize = 20 }, cancellation);
|
|
136
|
+
Assert.Single(Rows(page), row => Text(row, "processDefinitionId") == definitionId
|
|
137
|
+
&& Text(row, "ProcessName") == definitionName);
|
|
138
|
+
// Authenticate both actors before issuing any writes.
|
|
139
|
+
await workbench.GetMyPendingTasksAsync(Reviewer.Credential, new(Reviewer.UserId) { PageIndex = 1, PageSize = 1 }, cancellation);
|
|
140
|
+
output.WriteLine($"{scenario}: definition={definitionId}, businessKey={Marker}");
|
|
141
|
+
var result = await Operations.StartProcessAsync(Starter.Credential,
|
|
142
|
+
new(Starter.UserId) { ProcessDefinitionId = definitionId, BusinessKey = Marker, Summary = Marker }, cancellation);
|
|
143
|
+
Assert.False(string.IsNullOrWhiteSpace(result.Details), "Start did not return an instance ID.");
|
|
144
|
+
var instanceId = result.Details!;
|
|
145
|
+
output.WriteLine($"Started instance={instanceId}");
|
|
146
|
+
await RequireInitiatedStateAsync(instanceId, 0);
|
|
147
|
+
return instanceId;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
public async Task CompleteAsync(Actor actor, string taskId) =>
|
|
151
|
+
await Operations.CompleteTaskAsync(actor.Credential,
|
|
152
|
+
new(taskId) { Comment = ApprovalComment }, cancellation);
|
|
153
|
+
|
|
154
|
+
public async Task<string> RequirePendingAsync(Actor actor, string instanceId, string step)
|
|
155
|
+
{
|
|
156
|
+
var task = Assert.Single(await PendingAsync(actor, instanceId));
|
|
157
|
+
Assert.Equal(step, Text(task, "stepName"));
|
|
158
|
+
Assert.Equal(actor.UserId, Text(task, "taskAssignee"));
|
|
159
|
+
var taskId = Text(task, "taskId");
|
|
160
|
+
Assert.False(string.IsNullOrWhiteSpace(taskId), "Pending task has no task ID.");
|
|
161
|
+
output.WriteLine($"instance={instanceId}: pending step={step}, task={taskId}");
|
|
162
|
+
return taskId!;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
public async Task RequireNoPendingAsync(Actor actor, string instanceId) =>
|
|
166
|
+
Assert.Empty(await PendingAsync(actor, instanceId));
|
|
167
|
+
|
|
168
|
+
public async Task RequireCompletedAsync(Actor actor, string instanceId, string taskId) =>
|
|
169
|
+
Assert.Contains(await CompletedAsync(actor, instanceId), row => Text(row, "taskId") == taskId);
|
|
170
|
+
|
|
171
|
+
public async Task RequireNoCompletedAsync(Actor actor, string instanceId) =>
|
|
172
|
+
Assert.Empty(await CompletedAsync(actor, instanceId));
|
|
173
|
+
|
|
174
|
+
public async Task RequireInitiatedStateAsync(string instanceId, int expected)
|
|
175
|
+
{
|
|
176
|
+
var row = Assert.Single(InstanceRows(await workbench.GetMyInitiatedProcessesAsync(Starter.Credential,
|
|
177
|
+
Query(Starter, instanceId), cancellationToken: cancellation), instanceId));
|
|
178
|
+
Assert.Equal(expected, State(row, "processState"));
|
|
179
|
+
var ended = row.TryGetProperty("processCompleteTime", out var end) && end.ValueKind != JsonValueKind.Null;
|
|
180
|
+
Assert.Equal(expected != 0, ended);
|
|
181
|
+
output.WriteLine($"instance={instanceId}: processState={expected}, ended={ended}");
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
public async Task RequireArchivedStateAsync(Actor actor, string instanceId, int expected)
|
|
185
|
+
{
|
|
186
|
+
// edoc2Flow inserts the assignee archive rows asynchronously after commit.
|
|
187
|
+
using var deadline = CancellationTokenSource.CreateLinkedTokenSource(cancellation);
|
|
188
|
+
var timeout = TimeSpan.FromSeconds(15);
|
|
189
|
+
deadline.CancelAfter(timeout);
|
|
190
|
+
try
|
|
191
|
+
{
|
|
192
|
+
while (true)
|
|
193
|
+
{
|
|
194
|
+
var rows = InstanceRows(await workbench.GetMyArchivedProcessesAsync(actor.Credential,
|
|
195
|
+
Query(actor, instanceId), deadline.Token), instanceId);
|
|
196
|
+
if (rows.Count > 0)
|
|
197
|
+
{
|
|
198
|
+
Assert.Equal(expected, State(Assert.Single(rows), "taskState"));
|
|
199
|
+
output.WriteLine($"instance={instanceId}: actor={Role(actor)}, archived taskState={expected}");
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
await Task.Delay(TimeSpan.FromMilliseconds(500), deadline.Token);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
catch (OperationCanceledException) when (deadline.IsCancellationRequested && !cancellation.IsCancellationRequested)
|
|
206
|
+
{
|
|
207
|
+
Assert.Fail($"Archive not visible after {timeout.TotalSeconds} seconds: instance={instanceId}, actor={Role(actor)}, expected taskState={expected}.");
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
public async Task RequireLogAsync(Actor actor, string instanceId, string taskId, string comment, int? state = null)
|
|
212
|
+
{
|
|
213
|
+
var result = await tracking.GetProcessLogAsync(actor.Credential, instanceId, cancellation);
|
|
214
|
+
Assert.True(result.Details is { ValueKind: JsonValueKind.Object }, "Expected a process log page.");
|
|
215
|
+
var row = Assert.Single(result.Details!.Value.GetProperty("rows").EnumerateArray(),
|
|
216
|
+
entry => Text(entry, "id") == taskId);
|
|
217
|
+
Assert.Equal(comment, Text(row, "comment"));
|
|
218
|
+
if (state.HasValue)
|
|
219
|
+
Assert.Equal(state.Value, State(row, "taskState"));
|
|
220
|
+
output.WriteLine($"instance={instanceId}: actor={Role(actor)}, task={taskId}, log comment verified");
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
public ValueTask DisposeAsync() => services.DisposeAsync();
|
|
224
|
+
|
|
225
|
+
private async Task<IReadOnlyList<JsonElement>> PendingAsync(Actor actor, string instanceId) =>
|
|
226
|
+
InstanceRows(await workbench.GetMyPendingTasksAsync(actor.Credential, Query(actor, instanceId), cancellation), instanceId);
|
|
227
|
+
|
|
228
|
+
private async Task<IReadOnlyList<JsonElement>> CompletedAsync(Actor actor, string instanceId) =>
|
|
229
|
+
InstanceRows(await workbench.GetMyCompletedTasksAsync(actor.Credential, Query(actor, instanceId), cancellation), instanceId);
|
|
230
|
+
|
|
231
|
+
private string Role(Actor actor) => actor == Starter ? "starter" : "reviewer";
|
|
232
|
+
|
|
233
|
+
private static WorkFlowListQuery Query(Actor actor, string instanceId) =>
|
|
234
|
+
new(actor.UserId) { ProcessInstanceId = instanceId, PageIndex = 1, PageSize = 20 };
|
|
235
|
+
|
|
236
|
+
private static IReadOnlyList<JsonElement> Rows(WorkFlowResult<WorkFlowPage> result)
|
|
237
|
+
{
|
|
238
|
+
// The engine returns code 200 with no details when a list is empty.
|
|
239
|
+
if (result.Details is null)
|
|
240
|
+
return [];
|
|
241
|
+
Assert.NotNull(result.Details.Rows);
|
|
242
|
+
Assert.Equal(result.Details.Total, result.Details.Rows.Count);
|
|
243
|
+
return result.Details.Rows;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
private static IReadOnlyList<JsonElement> InstanceRows(WorkFlowResult<WorkFlowPage> result, string instanceId)
|
|
247
|
+
{
|
|
248
|
+
var rows = Rows(result);
|
|
249
|
+
Assert.All(rows, row => Assert.Equal(instanceId, Text(row, "processInstanceId")));
|
|
250
|
+
return rows;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
private static string? Text(JsonElement row, string key) =>
|
|
254
|
+
row.TryGetProperty(key, out var value) && value.ValueKind == JsonValueKind.String ? value.GetString() : null;
|
|
255
|
+
|
|
256
|
+
private static int State(JsonElement row, string key)
|
|
257
|
+
{
|
|
258
|
+
var value = row.GetProperty(key);
|
|
259
|
+
return value.ValueKind == JsonValueKind.String
|
|
260
|
+
? int.Parse(value.GetString()!, CultureInfo.InvariantCulture)
|
|
261
|
+
: value.GetInt32();
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
private static string Required(string key) =>
|
|
266
|
+
Environment.GetEnvironmentVariable(key) is { } value && !string.IsNullOrWhiteSpace(value)
|
|
267
|
+
? value
|
|
268
|
+
: throw new InvalidOperationException($"Missing live workflow setting: {key}.");
|
|
269
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
using Macrowing.InBiz.SDK.WorkFlow;
|
|
2
|
+
using static Macrowing.InBiz.SDK.Tests.WorkFlowHttpServer;
|
|
3
|
+
|
|
4
|
+
namespace Macrowing.InBiz.SDK.Tests;
|
|
5
|
+
|
|
6
|
+
public sealed class WorkFlowOperationsTests
|
|
7
|
+
{
|
|
8
|
+
[Fact]
|
|
9
|
+
public async Task StartsProcessWithJsonEncodedVariables()
|
|
10
|
+
{
|
|
11
|
+
await using var server = await StartAsync(new Response("""{"code":"200","message":"started","details":"instance-42"}"""));
|
|
12
|
+
var client = server.Client<IWorkFlowOperationsClient>();
|
|
13
|
+
|
|
14
|
+
var result = await client.StartProcessAsync(Credential, new("starter-1")
|
|
15
|
+
{
|
|
16
|
+
ProcessDefinitionId = "approval:1:7",
|
|
17
|
+
BusinessKey = "record-2",
|
|
18
|
+
Variables = [new("approved", "true")],
|
|
19
|
+
Summary = "Approval"
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
Assert.Equal(new WorkFlowResult<string>("200", "started", "instance-42"), result);
|
|
23
|
+
var request = Assert.Single(server.Requests);
|
|
24
|
+
AssertRequest(request, "POST", "process/operation/initiatingProcess",
|
|
25
|
+
json: """{"starter":"starter-1","processDefinitionId":"approval:1:7","businessKey":"record-2","variablesParams":"[{\"name\":\"approved\",\"value\":\"true\"}]","summary":"Approval"}""");
|
|
26
|
+
Assert.Contains("orgToken=org%2Btoken%2F%26%3D%3F", request.RawTarget);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
[Theory]
|
|
30
|
+
[InlineData("processCompletion", """{"taskId":"task-1","comment":"reviewed","variablesParams":"[]","isrefuse":false,"signDataStr":"signature"}""")]
|
|
31
|
+
[InlineData("processStop", """{"processInstanceId":"instance-42","taskId":"task-1","callback":"callback-1","manage":false,"comment":"stop"}""")]
|
|
32
|
+
public async Task SendsEngineOperationDto(string action, string json)
|
|
33
|
+
{
|
|
34
|
+
await using var server = await StartAsync(new Response("""{"code":"200","details":null}"""));
|
|
35
|
+
var client = server.Client<IWorkFlowOperationsClient>();
|
|
36
|
+
var result = await (action switch
|
|
37
|
+
{
|
|
38
|
+
"processCompletion" => client.CompleteTaskAsync(Credential, new("task-1")
|
|
39
|
+
{ Comment = "reviewed", Variables = [], SignDataStr = "signature" }),
|
|
40
|
+
"processStop" => client.StopProcessAsync(Credential, new("instance-42")
|
|
41
|
+
{ TaskId = "task-1", Manage = false, Callback = "callback-1", Comment = "stop" }),
|
|
42
|
+
_ => throw new ArgumentOutOfRangeException(nameof(action))
|
|
43
|
+
});
|
|
44
|
+
Assert.Equal("200", result.Code);
|
|
45
|
+
Assert.Null(result.Details);
|
|
46
|
+
AssertRequest(Assert.Single(server.Requests), "POST", $"process/operation/{action}", json: json);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
[Theory]
|
|
50
|
+
[InlineData(WorkFlowReturnTarget.PreviousStep, "previousStep")]
|
|
51
|
+
[InlineData(WorkFlowReturnTarget.Originator, "sponsor")]
|
|
52
|
+
[InlineData(WorkFlowReturnTarget.OriginatorForRevision, "initiatorModif")]
|
|
53
|
+
public async Task MapsReturnTargetToEngineConstant(WorkFlowReturnTarget target, string wireType)
|
|
54
|
+
{
|
|
55
|
+
await using var server = await StartAsync(new Response("""{"code":"200","details":null}"""));
|
|
56
|
+
var result = await server.Client<IWorkFlowOperationsClient>().ReturnTaskAsync(Credential, new("task-1", target) { Comment = "revise" });
|
|
57
|
+
Assert.Equal("200", result.Code);
|
|
58
|
+
AssertRequest(Assert.Single(server.Requests), "POST", "process/operation/processReturn",
|
|
59
|
+
json: $$"""{"taskId":"task-1","retrunType":"{{wireType}}","comment":"revise"}""");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
[Fact]
|
|
63
|
+
public async Task BusinessKeyRequiresDefinitionIdBecauseTheEngineUsesItToFindDrafts()
|
|
64
|
+
{
|
|
65
|
+
await using var server = await StartAsync();
|
|
66
|
+
var client = server.Client<IWorkFlowOperationsClient>();
|
|
67
|
+
Assert.Throws<ArgumentException>(() => { _ = client.StartProcessAsync(Credential, new("user") { ProcessKey = "approval", BusinessKey = "record" }); });
|
|
68
|
+
Assert.Empty(server.Requests);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
[Theory]
|
|
72
|
+
[InlineData(true)]
|
|
73
|
+
[InlineData(false)]
|
|
74
|
+
public async Task DraftCheckReadsBareBooleanAndSendsJwt(bool canSave)
|
|
75
|
+
{
|
|
76
|
+
await using var server = await StartAsync(new Response(canSave ? "true" : "false"));
|
|
77
|
+
Assert.Equal(canSave, await server.Client<IWorkFlowOperationsClient>().CanSaveDraftAsync(WorkFlowCredential.Jwt(Jwt), "proc+1"));
|
|
78
|
+
AssertRequest(Assert.Single(server.Requests), "GET", "process/operation/getIsDrafts", [("processId", "proc+1")], withJwt: true);
|
|
79
|
+
}
|
|
80
|
+
}
|