@voxgig/sdkgen 0.25.0 → 0.28.0
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/bin/voxgig-sdkgen +6 -6
- package/dist/action/action.js +1 -2
- package/dist/action/action.js.map +1 -1
- package/dist/action/feature.js +4 -2
- package/dist/action/feature.js.map +1 -1
- package/dist/action/target.js +4 -2
- package/dist/action/target.js.map +1 -1
- package/dist/cmp/Entity.js +2 -1
- package/dist/cmp/Entity.js.map +1 -1
- package/dist/cmp/Feature.js +11 -9
- package/dist/cmp/Feature.js.map +1 -1
- package/dist/cmp/FeatureHook.js +2 -1
- package/dist/cmp/FeatureHook.js.map +1 -1
- package/dist/cmp/Main.js +6 -2
- package/dist/cmp/Main.js.map +1 -1
- package/dist/cmp/ReadmeEntity.js +2 -1
- package/dist/cmp/ReadmeEntity.js.map +1 -1
- package/dist/cmp/Test.d.ts +2 -0
- package/dist/cmp/Test.js +17 -0
- package/dist/cmp/Test.js.map +1 -0
- package/dist/sdkgen.d.ts +2 -1
- package/dist/sdkgen.js +17 -28
- package/dist/sdkgen.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +3 -1
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -1
- package/model/sdkgen.jsonic +9 -9
- package/package.json +8 -6
- package/project/.sdk/model/feature/log.jsonic +3 -3
- package/project/.sdk/model/feature/test.jsonic +8 -3
- package/project/.sdk/model/target/go.jsonic +19 -4
- package/project/.sdk/model/target/js.jsonic +2 -2
- package/project/.sdk/model/target/ts.jsonic +5 -5
- package/project/.sdk/src/cmp/go/Config_go.ts +119 -0
- package/project/.sdk/src/cmp/go/EntityOperation_go.ts +48 -0
- package/project/.sdk/src/cmp/go/Entity_go.ts +67 -0
- package/project/.sdk/src/cmp/go/MainEntity_go.ts +22 -0
- package/project/.sdk/src/cmp/go/Main_go.ts +209 -0
- package/project/.sdk/src/cmp/go/Package_go.ts +89 -0
- package/project/.sdk/src/cmp/go/TestDirect_go.ts +373 -0
- package/project/.sdk/src/cmp/go/TestEntity_go.ts +341 -0
- package/project/.sdk/src/cmp/go/Test_go.ts +37 -0
- package/project/.sdk/src/cmp/go/fragment/Entity.fragment.go +146 -0
- package/project/.sdk/src/cmp/go/fragment/EntityCreateOp.fragment.go +35 -0
- package/project/.sdk/src/cmp/go/fragment/EntityListOp.fragment.go +26 -0
- package/project/.sdk/src/cmp/go/fragment/EntityLoadOp.fragment.go +38 -0
- package/project/.sdk/src/cmp/go/fragment/EntityRemoveOp.fragment.go +38 -0
- package/project/.sdk/src/cmp/go/fragment/EntityUpdateOp.fragment.go +38 -0
- package/project/.sdk/src/cmp/go/fragment/Main.fragment.go +250 -0
- package/project/.sdk/src/cmp/go/fragment/SdkError.fragment.go +22 -0
- package/project/.sdk/src/cmp/go/tsconfig.json +15 -0
- package/project/.sdk/src/cmp/go/utility_go.ts +88 -0
- package/project/.sdk/src/cmp/js/Main_js.ts +3 -3
- package/project/.sdk/src/cmp/js/Quick_js.ts +1 -1
- package/project/.sdk/src/cmp/js/fragment/EntityCreateOp.fragment.js +6 -6
- package/project/.sdk/src/cmp/js/fragment/EntityListOp.fragment.js +6 -6
- package/project/.sdk/src/cmp/js/fragment/EntityLoadOp.fragment.js +6 -6
- package/project/.sdk/src/cmp/js/fragment/EntityRemoveOp.fragment.js +6 -6
- package/project/.sdk/src/cmp/js/fragment/EntityUpdateOp.fragment.js +6 -6
- package/project/.sdk/src/cmp/js/fragment/Main.fragment.js +85 -1
- package/project/.sdk/src/cmp/ts/Config_ts.ts +53 -6
- package/project/.sdk/src/cmp/ts/EntityOperation_ts.ts +3 -21
- package/project/.sdk/src/cmp/ts/Entity_ts.ts +3 -5
- package/project/.sdk/src/cmp/ts/Main_ts.ts +23 -13
- package/project/.sdk/src/cmp/ts/Package_ts.ts +30 -11
- package/project/.sdk/src/cmp/ts/SdkError_ts.ts +42 -0
- package/project/.sdk/src/cmp/ts/TestDirect_ts.ts +288 -0
- package/project/.sdk/src/cmp/ts/TestEntity_ts.ts +349 -2
- package/project/.sdk/src/cmp/ts/TestMain_ts.ts +0 -3
- package/project/.sdk/src/cmp/ts/Test_ts.ts +23 -3
- package/project/.sdk/src/cmp/ts/fragment/Config.fragment.ts +38 -5
- package/project/.sdk/src/cmp/ts/fragment/Direct.test.fragment.ts +30 -0
- package/project/.sdk/src/cmp/ts/fragment/Entity.fragment.ts +50 -38
- package/project/.sdk/src/cmp/ts/fragment/Entity.test.fragment.ts +9 -7
- package/project/.sdk/src/cmp/ts/fragment/EntityCreateOp.fragment.ts +47 -31
- package/project/.sdk/src/cmp/ts/fragment/EntityListOp.fragment.ts +49 -31
- package/project/.sdk/src/cmp/ts/fragment/EntityLoadOp.fragment.ts +50 -33
- package/project/.sdk/src/cmp/ts/fragment/EntityRemoveOp.fragment.ts +51 -32
- package/project/.sdk/src/cmp/ts/fragment/EntityUpdateOp.fragment.ts +51 -31
- package/project/.sdk/src/cmp/ts/fragment/Main.fragment.ts +166 -34
- package/project/.sdk/src/cmp/ts/fragment/SdkError.fragment.ts +25 -0
- package/project/.sdk/src/cmp/ts/tsconfig.json +15 -0
- package/project/.sdk/src/cmp/ts/utility_ts.ts +55 -1
- package/project/.sdk/tm/go/Makefile +10 -0
- package/project/.sdk/tm/go/core/context.go +267 -0
- package/project/.sdk/tm/go/core/control.go +7 -0
- package/project/.sdk/tm/go/core/error.go +25 -0
- package/project/.sdk/tm/go/core/helpers.go +33 -0
- package/project/.sdk/tm/go/core/operation.go +61 -0
- package/project/.sdk/tm/go/core/response.go +55 -0
- package/project/.sdk/tm/go/core/result.go +73 -0
- package/project/.sdk/tm/go/core/spec.go +97 -0
- package/project/.sdk/tm/go/core/target.go +102 -0
- package/project/.sdk/tm/go/core/types.go +44 -0
- package/project/.sdk/tm/go/core/utility_type.go +54 -0
- package/project/.sdk/tm/go/feature/base_feature.go +40 -0
- package/project/.sdk/tm/go/feature/test_feature.go +196 -0
- package/project/.sdk/tm/go/src/feature/README.md +1 -0
- package/project/.sdk/tm/go/src/feature/base/.gitkeep +0 -0
- package/project/.sdk/tm/go/src/feature/test/.gitkeep +0 -0
- package/project/.sdk/tm/go/test/custom_utility_test.go +80 -0
- package/project/.sdk/tm/go/test/exists_test.go +16 -0
- package/project/.sdk/tm/go/test/primary_utility_test.go +899 -0
- package/project/.sdk/tm/go/test/runner_test.go +428 -0
- package/project/.sdk/tm/go/test/struct_runner_test.go +1094 -0
- package/project/.sdk/tm/go/test/struct_utility_test.go +1423 -0
- package/project/.sdk/tm/go/utility/clean.go +7 -0
- package/project/.sdk/tm/go/utility/done.go +20 -0
- package/project/.sdk/tm/go/utility/feature_add.go +10 -0
- package/project/.sdk/tm/go/utility/feature_hook.go +30 -0
- package/project/.sdk/tm/go/utility/feature_init.go +30 -0
- package/project/.sdk/tm/go/utility/fetcher.go +102 -0
- package/project/.sdk/tm/go/utility/make_context.go +7 -0
- package/project/.sdk/tm/go/utility/make_error.go +69 -0
- package/project/.sdk/tm/go/utility/make_fetch_def.go +44 -0
- package/project/.sdk/tm/go/utility/make_options.go +130 -0
- package/project/.sdk/tm/go/utility/make_request.go +59 -0
- package/project/.sdk/tm/go/utility/make_response.go +46 -0
- package/project/.sdk/tm/go/utility/make_result.go +55 -0
- package/project/.sdk/tm/go/utility/make_spec.go +68 -0
- package/project/.sdk/tm/go/utility/make_target.go +95 -0
- package/project/.sdk/tm/go/utility/make_url.go +41 -0
- package/project/.sdk/tm/go/utility/param.go +66 -0
- package/project/.sdk/tm/go/utility/prepare_auth.go +40 -0
- package/project/.sdk/tm/go/utility/prepare_body.go +14 -0
- package/project/.sdk/tm/go/utility/prepare_headers.go +22 -0
- package/project/.sdk/tm/go/utility/prepare_method.go +21 -0
- package/project/.sdk/tm/go/utility/prepare_params.go +41 -0
- package/project/.sdk/tm/go/utility/prepare_path.go +21 -0
- package/project/.sdk/tm/go/utility/prepare_query.go +47 -0
- package/project/.sdk/tm/go/utility/register.go +39 -0
- package/project/.sdk/tm/go/utility/result_basic.go +31 -0
- package/project/.sdk/tm/go/utility/result_body.go +17 -0
- package/project/.sdk/tm/go/utility/result_headers.go +22 -0
- package/project/.sdk/tm/go/utility/struct/go.mod +3 -0
- package/project/.sdk/tm/go/utility/struct/voxgigstruct.go +4891 -0
- package/project/.sdk/tm/go/utility/transform_request.go +32 -0
- package/project/.sdk/tm/go/utility/transform_response.go +45 -0
- package/project/.sdk/tm/js/src/feature/log/LogFeature.js +2 -2
- package/project/.sdk/tm/ts/src/Context.ts +144 -0
- package/project/.sdk/tm/ts/src/Control.ts +20 -0
- package/project/.sdk/tm/ts/src/Operation.ts +24 -0
- package/project/.sdk/tm/ts/src/Response.ts +26 -0
- package/project/.sdk/tm/ts/src/Result.ts +30 -0
- package/project/.sdk/tm/ts/src/Spec.ts +40 -0
- package/project/.sdk/tm/ts/src/Target.ts +36 -0
- package/project/.sdk/tm/ts/src/feature/base/BaseFeature.ts +1 -1
- package/project/.sdk/tm/ts/src/feature/log/LogFeature.ts +2 -2
- package/project/.sdk/tm/ts/src/feature/test/TestFeature.ts +158 -104
- package/project/.sdk/tm/ts/src/types.ts +18 -78
- package/project/.sdk/tm/ts/src/utility/CleanUtility.ts +17 -31
- package/project/.sdk/tm/ts/src/utility/DoneUtility.ts +3 -4
- package/project/.sdk/tm/ts/src/utility/{AddfeatureUtility.ts → FeatureAddUtility.ts} +2 -2
- package/project/.sdk/tm/ts/src/utility/{FeaturehookUtility.ts → FeatureHookUtility.ts} +8 -5
- package/project/.sdk/tm/ts/src/utility/FeatureInitUtility.ts +15 -0
- package/project/.sdk/tm/ts/src/utility/FetcherUtility.ts +20 -2
- package/project/.sdk/tm/ts/src/utility/MakeContextUtility.ts +27 -0
- package/project/.sdk/tm/ts/src/utility/{ErrorUtility.ts → MakeErrorUtility.ts} +10 -6
- package/project/.sdk/tm/ts/src/utility/MakeFetchDefUtility.ts +46 -0
- package/project/.sdk/tm/ts/src/utility/{OptionsUtility.ts → MakeOptionsUtility.ts} +32 -7
- package/project/.sdk/tm/ts/src/utility/MakeRequestUtility.ts +66 -0
- package/project/.sdk/tm/ts/src/utility/MakeResponseUtility.ts +61 -0
- package/project/.sdk/tm/ts/src/utility/MakeResultUtility.ts +56 -0
- package/project/.sdk/tm/ts/src/utility/MakeSpecUtility.ts +61 -0
- package/project/.sdk/tm/ts/src/utility/MakeTargetUtility.ts +76 -0
- package/project/.sdk/tm/ts/src/utility/MakeUrlUtility.ts +61 -0
- package/project/.sdk/tm/ts/src/utility/{FindparamUtility.ts → ParamUtility.ts} +28 -8
- package/project/.sdk/tm/ts/src/utility/{AuthUtility.ts → PrepareAuthUtility.ts} +10 -4
- package/project/.sdk/tm/ts/src/utility/PrepareBodyUtility.ts +32 -0
- package/project/.sdk/tm/ts/src/utility/{HeadersUtility.ts → PrepareHeadersUtility.ts} +5 -7
- package/project/.sdk/tm/ts/src/utility/{MethodUtility.ts → PrepareMethodUtility.ts} +6 -6
- package/project/.sdk/tm/ts/src/utility/PrepareParamsUtility.ts +37 -0
- package/project/.sdk/tm/ts/src/utility/PreparePathUtility.ts +17 -0
- package/project/.sdk/tm/ts/src/utility/PrepareQueryUtility.ts +30 -0
- package/project/.sdk/tm/ts/src/utility/{ResbasicUtility.ts → ResultBasicUtility.ts} +12 -7
- package/project/.sdk/tm/ts/src/utility/ResultBodyUtility.ts +22 -0
- package/project/.sdk/tm/ts/src/utility/ResultHeadersUtility.ts +26 -0
- package/project/.sdk/tm/ts/src/utility/StructUtility.ts +1113 -525
- package/project/.sdk/tm/ts/src/utility/{ReqformUtility.ts → TransformRequestUtility.ts} +9 -7
- package/project/.sdk/tm/ts/src/utility/{ResformUtility.ts → TransformResponseUtility.ts} +11 -8
- package/project/.sdk/tm/ts/src/utility/Utility.ts +52 -65
- package/project/.sdk/tm/ts/test/exists.test.ts +0 -1
- package/project/.sdk/tm/ts/test/runner.ts +36 -13
- package/project/.sdk/tm/ts/test/utility/Custom.test.ts +30 -29
- package/project/.sdk/tm/ts/test/utility/PrimaryUtility.test.ts +385 -168
- package/project/.sdk/tm/ts/test/utility/StructUtility.test.ts +433 -189
- package/src/action/action.ts +1 -2
- package/src/action/feature.ts +7 -2
- package/src/action/target.ts +7 -7
- package/src/cmp/Entity.ts +7 -1
- package/src/cmp/Feature.ts +11 -9
- package/src/cmp/FeatureHook.ts +6 -1
- package/src/cmp/Main.ts +12 -2
- package/src/cmp/ReadmeEntity.ts +6 -1
- package/src/cmp/Test.ts +31 -0
- package/src/sdkgen.ts +19 -34
- package/src/types.ts +10 -1
- package/project/.sdk/src/cmp/ts/EntityTest_ts.ts +0 -180
- package/project/.sdk/tm/ts/src/utility/BodyUtility.ts +0 -29
- package/project/.sdk/tm/ts/src/utility/ContextUtility.ts +0 -67
- package/project/.sdk/tm/ts/src/utility/FullurlUtility.ts +0 -46
- package/project/.sdk/tm/ts/src/utility/InitfeatureUtility.ts +0 -13
- package/project/.sdk/tm/ts/src/utility/JoinurlUtility.ts +0 -15
- package/project/.sdk/tm/ts/src/utility/OperatorUtility.ts +0 -90
- package/project/.sdk/tm/ts/src/utility/ParamsUtility.ts +0 -37
- package/project/.sdk/tm/ts/src/utility/QueryUtility.ts +0 -27
- package/project/.sdk/tm/ts/src/utility/RequestUtility.ts +0 -66
- package/project/.sdk/tm/ts/src/utility/ResbodyUtility.ts +0 -19
- package/project/.sdk/tm/ts/src/utility/ResheadersUtility.ts +0 -23
- package/project/.sdk/tm/ts/src/utility/ResponseUtility.ts +0 -30
- package/project/.sdk/tm/ts/src/utility/ResultUtility.ts +0 -36
- package/project/.sdk/tm/ts/src/utility/SpecUtility.ts +0 -61
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
|
|
2
|
+
import {
|
|
3
|
+
Content,
|
|
4
|
+
File,
|
|
5
|
+
cmp,
|
|
6
|
+
} from '@voxgig/sdkgen'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
const TestDirect = cmp(function TestDirect(props: any) {
|
|
10
|
+
const ctx$ = props.ctx$
|
|
11
|
+
const model = ctx$.model
|
|
12
|
+
|
|
13
|
+
const target = props.target
|
|
14
|
+
const entity = props.entity
|
|
15
|
+
const gomodule = props.gomodule
|
|
16
|
+
|
|
17
|
+
const PROJECTNAME = model.Name.toUpperCase()
|
|
18
|
+
|
|
19
|
+
const opnames = Object.keys(entity.op)
|
|
20
|
+
const hasLoad = opnames.includes('load')
|
|
21
|
+
const hasList = opnames.includes('list')
|
|
22
|
+
|
|
23
|
+
if (!hasLoad && !hasList) {
|
|
24
|
+
return
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const loadOp = entity.op.load
|
|
28
|
+
const listOp = entity.op.list
|
|
29
|
+
|
|
30
|
+
// Get load target info
|
|
31
|
+
const loadTarget = loadOp?.targets?.[0]
|
|
32
|
+
const loadPath = loadTarget ? (loadTarget.parts || []).join('/') : ''
|
|
33
|
+
const loadParams = loadTarget?.args?.params || []
|
|
34
|
+
|
|
35
|
+
// Get list target info
|
|
36
|
+
const listTarget = listOp?.targets?.[0]
|
|
37
|
+
const listPath = listTarget ? (listTarget.parts || []).join('/') : ''
|
|
38
|
+
const listParams = listTarget?.args?.params || []
|
|
39
|
+
|
|
40
|
+
// Build the ENTID env var name for this entity
|
|
41
|
+
const entidEnvVar = `${PROJECTNAME}_TEST_${entity.Name.toUpperCase()}_ENTID`
|
|
42
|
+
|
|
43
|
+
File({ name: entity.name + '_direct_test.' + target.ext }, () => {
|
|
44
|
+
|
|
45
|
+
Content(`package sdktest
|
|
46
|
+
|
|
47
|
+
import (
|
|
48
|
+
"encoding/json"
|
|
49
|
+
"os"
|
|
50
|
+
"strings"
|
|
51
|
+
"testing"
|
|
52
|
+
|
|
53
|
+
sdk "${gomodule}"
|
|
54
|
+
"${gomodule}/core"
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
func Test${entity.Name}Direct(t *testing.T) {
|
|
58
|
+
`)
|
|
59
|
+
|
|
60
|
+
// Generate list test first (load needs list results in live mode)
|
|
61
|
+
if (hasList && listTarget) {
|
|
62
|
+
const listParamStr = listParams.length > 0
|
|
63
|
+
? listParams.map((p: any, i: number) =>
|
|
64
|
+
`"${p.name}": "direct0${i + 1}"`).join(', ')
|
|
65
|
+
: ''
|
|
66
|
+
|
|
67
|
+
// Build live params for list
|
|
68
|
+
const listLiveParams = listParams.map((p: any) => {
|
|
69
|
+
const key = p.name === 'id'
|
|
70
|
+
? entity.name + '01'
|
|
71
|
+
: p.name.replace(/_id$/, '') + '01'
|
|
72
|
+
return { name: p.name, key }
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
Content(` t.Run("direct-list-${entity.name}", func(t *testing.T) {
|
|
76
|
+
setup := ${entity.name}DirectSetup([]any{
|
|
77
|
+
map[string]any{"id": "direct01"},
|
|
78
|
+
map[string]any{"id": "direct02"},
|
|
79
|
+
})
|
|
80
|
+
client := setup.client
|
|
81
|
+
|
|
82
|
+
`)
|
|
83
|
+
|
|
84
|
+
if (listParams.length > 0) {
|
|
85
|
+
Content(` params := map[string]any{}
|
|
86
|
+
`)
|
|
87
|
+
for (const lp of listLiveParams) {
|
|
88
|
+
Content(` if setup.live {
|
|
89
|
+
params["${lp.name}"] = setup.idmap["${lp.key}"]
|
|
90
|
+
} else {
|
|
91
|
+
params["${lp.name}"] = "direct01"
|
|
92
|
+
}
|
|
93
|
+
`)
|
|
94
|
+
}
|
|
95
|
+
Content(`
|
|
96
|
+
result, err := client.Direct(map[string]any{
|
|
97
|
+
"path": "${listPath}",
|
|
98
|
+
"method": "GET",
|
|
99
|
+
"params": params,
|
|
100
|
+
})
|
|
101
|
+
`)
|
|
102
|
+
} else {
|
|
103
|
+
Content(`
|
|
104
|
+
result, err := client.Direct(map[string]any{
|
|
105
|
+
"path": "${listPath}",
|
|
106
|
+
"method": "GET",
|
|
107
|
+
"params": map[string]any{${listParamStr}},
|
|
108
|
+
})
|
|
109
|
+
`)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
Content(` if err != nil {
|
|
113
|
+
t.Fatalf("direct failed: %v", err)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if result["ok"] != true {
|
|
117
|
+
t.Fatalf("expected ok to be true, got %v", result["ok"])
|
|
118
|
+
}
|
|
119
|
+
if core.ToInt(result["status"]) != 200 {
|
|
120
|
+
t.Fatalf("expected status 200, got %v", result["status"])
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if !setup.live {
|
|
124
|
+
if dataList, ok := result["data"].([]any); ok {
|
|
125
|
+
if len(dataList) != 2 {
|
|
126
|
+
t.Fatalf("expected 2 items, got %d", len(dataList))
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
t.Fatalf("expected data to be an array, got %T", result["data"])
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if len(*setup.calls) != 1 {
|
|
133
|
+
t.Fatalf("expected 1 call, got %d", len(*setup.calls))
|
|
134
|
+
}
|
|
135
|
+
`)
|
|
136
|
+
|
|
137
|
+
if (listParams.length > 0) {
|
|
138
|
+
Content(` call := (*setup.calls)[0]
|
|
139
|
+
if initMap, ok := call["init"].(map[string]any); ok {
|
|
140
|
+
if initMap["method"] != "GET" {
|
|
141
|
+
t.Fatalf("expected method GET, got %v", initMap["method"])
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if url, ok := call["url"].(string); ok {
|
|
145
|
+
`)
|
|
146
|
+
for (let i = 0; i < listParams.length; i++) {
|
|
147
|
+
Content(` if !strings.Contains(url, "direct0${i + 1}") {
|
|
148
|
+
t.Fatalf("expected url to contain direct0${i + 1}, got %v", url)
|
|
149
|
+
}
|
|
150
|
+
`)
|
|
151
|
+
}
|
|
152
|
+
Content(` }
|
|
153
|
+
`)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
Content(` }
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
`)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Generate load test - in live mode, first list to get a real entity ID
|
|
163
|
+
if (hasLoad && loadTarget) {
|
|
164
|
+
const loadParamStr = loadParams.length > 0
|
|
165
|
+
? loadParams.map((p: any, i: number) =>
|
|
166
|
+
`"${p.name}": "direct0${i + 1}"`).join(', ')
|
|
167
|
+
: ''
|
|
168
|
+
|
|
169
|
+
// Identify ancestor params (not 'id') for live mode
|
|
170
|
+
const ancestorParams = loadParams.filter((p: any) => p.name !== 'id')
|
|
171
|
+
|
|
172
|
+
Content(` t.Run("direct-load-${entity.name}", func(t *testing.T) {
|
|
173
|
+
setup := ${entity.name}DirectSetup(map[string]any{"id": "direct01"})
|
|
174
|
+
client := setup.client
|
|
175
|
+
|
|
176
|
+
`)
|
|
177
|
+
|
|
178
|
+
if (loadParams.length > 0) {
|
|
179
|
+
Content(` params := map[string]any{}
|
|
180
|
+
`)
|
|
181
|
+
|
|
182
|
+
Content(` if setup.live {
|
|
183
|
+
`)
|
|
184
|
+
|
|
185
|
+
// In live mode: first list to get a real entity, then use its ID
|
|
186
|
+
if (hasList) {
|
|
187
|
+
// Build list params from idmap
|
|
188
|
+
Content(` listParams := map[string]any{}
|
|
189
|
+
`)
|
|
190
|
+
for (const p of listParams) {
|
|
191
|
+
const key = p.name === 'id'
|
|
192
|
+
? entity.name + '01'
|
|
193
|
+
: p.name.replace(/_id$/, '') + '01'
|
|
194
|
+
Content(` listParams["${p.name}"] = setup.idmap["${key}"]
|
|
195
|
+
`)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
Content(` listResult, listErr := client.Direct(map[string]any{
|
|
199
|
+
"path": "${listPath}",
|
|
200
|
+
"method": "GET",
|
|
201
|
+
"params": listParams,
|
|
202
|
+
})
|
|
203
|
+
if listErr != nil {
|
|
204
|
+
t.Fatalf("list for load setup failed: %v", listErr)
|
|
205
|
+
}
|
|
206
|
+
if listResult["ok"] != true {
|
|
207
|
+
t.Fatalf("list for load setup not ok: %v", listResult)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Get first entity ID from list
|
|
211
|
+
listData, _ := listResult["data"].([]any)
|
|
212
|
+
if len(listData) == 0 {
|
|
213
|
+
t.Skip("no entities to load in live mode")
|
|
214
|
+
}
|
|
215
|
+
firstEnt := core.ToMapAny(listData[0])
|
|
216
|
+
params["id"] = firstEnt["id"]
|
|
217
|
+
`)
|
|
218
|
+
// Set ancestor params from idmap
|
|
219
|
+
for (const p of ancestorParams) {
|
|
220
|
+
const key = p.name.replace(/_id$/, '') + '01'
|
|
221
|
+
Content(` params["${p.name}"] = setup.idmap["${key}"]
|
|
222
|
+
`)
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
Content(` } else {
|
|
227
|
+
`)
|
|
228
|
+
for (let i = 0; i < loadParams.length; i++) {
|
|
229
|
+
Content(` params["${loadParams[i].name}"] = "direct0${i + 1}"
|
|
230
|
+
`)
|
|
231
|
+
}
|
|
232
|
+
Content(` }
|
|
233
|
+
`)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
Content(`
|
|
237
|
+
result, err := client.Direct(map[string]any{
|
|
238
|
+
"path": "${loadPath}",
|
|
239
|
+
"method": "GET",
|
|
240
|
+
`)
|
|
241
|
+
if (loadParams.length > 0) {
|
|
242
|
+
Content(` "params": params,
|
|
243
|
+
`)
|
|
244
|
+
} else {
|
|
245
|
+
Content(` "params": map[string]any{},
|
|
246
|
+
`)
|
|
247
|
+
}
|
|
248
|
+
Content(` })
|
|
249
|
+
if err != nil {
|
|
250
|
+
t.Fatalf("direct failed: %v", err)
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if result["ok"] != true {
|
|
254
|
+
t.Fatalf("expected ok to be true, got %v", result["ok"])
|
|
255
|
+
}
|
|
256
|
+
if core.ToInt(result["status"]) != 200 {
|
|
257
|
+
t.Fatalf("expected status 200, got %v", result["status"])
|
|
258
|
+
}
|
|
259
|
+
if result["data"] == nil {
|
|
260
|
+
t.Fatal("expected data to be non-nil")
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if !setup.live {
|
|
264
|
+
if dataMap, ok := result["data"].(map[string]any); ok {
|
|
265
|
+
if dataMap["id"] != "direct01" {
|
|
266
|
+
t.Fatalf("expected data.id to be direct01, got %v", dataMap["id"])
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if len(*setup.calls) != 1 {
|
|
271
|
+
t.Fatalf("expected 1 call, got %d", len(*setup.calls))
|
|
272
|
+
}
|
|
273
|
+
call := (*setup.calls)[0]
|
|
274
|
+
if initMap, ok := call["init"].(map[string]any); ok {
|
|
275
|
+
if initMap["method"] != "GET" {
|
|
276
|
+
t.Fatalf("expected method GET, got %v", initMap["method"])
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
if url, ok := call["url"].(string); ok {
|
|
280
|
+
`)
|
|
281
|
+
|
|
282
|
+
for (let i = 0; i < loadParams.length; i++) {
|
|
283
|
+
Content(` if !strings.Contains(url, "direct0${i + 1}") {
|
|
284
|
+
t.Fatalf("expected url to contain direct0${i + 1}, got %v", url)
|
|
285
|
+
}
|
|
286
|
+
`)
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
Content(` }
|
|
290
|
+
}
|
|
291
|
+
})
|
|
292
|
+
|
|
293
|
+
`)
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
Content(`}
|
|
297
|
+
|
|
298
|
+
type ${entity.name}DirectSetupResult struct {
|
|
299
|
+
client *sdk.${model.const.Name}SDK
|
|
300
|
+
calls *[]map[string]any
|
|
301
|
+
live bool
|
|
302
|
+
idmap map[string]any
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
func ${entity.name}DirectSetup(mockres any) *${entity.name}DirectSetupResult {
|
|
306
|
+
loadEnvLocal()
|
|
307
|
+
|
|
308
|
+
calls := &[]map[string]any{}
|
|
309
|
+
|
|
310
|
+
env := envOverride(map[string]any{
|
|
311
|
+
"${entidEnvVar}": map[string]any{},
|
|
312
|
+
"${PROJECTNAME}_TEST_LIVE": "FALSE",
|
|
313
|
+
"${PROJECTNAME}_APIKEY": "NONE",
|
|
314
|
+
})
|
|
315
|
+
|
|
316
|
+
live := env["${PROJECTNAME}_TEST_LIVE"] == "TRUE"
|
|
317
|
+
|
|
318
|
+
if live {
|
|
319
|
+
mergedOpts := map[string]any{
|
|
320
|
+
"apikey": env["${PROJECTNAME}_APIKEY"],
|
|
321
|
+
}
|
|
322
|
+
client := sdk.New${model.const.Name}SDK(mergedOpts)
|
|
323
|
+
|
|
324
|
+
idmap := map[string]any{}
|
|
325
|
+
if entidRaw, ok := env["${entidEnvVar}"]; ok {
|
|
326
|
+
if entidStr, ok := entidRaw.(string); ok && strings.HasPrefix(entidStr, "{") {
|
|
327
|
+
json.Unmarshal([]byte(entidStr), &idmap)
|
|
328
|
+
} else if entidMap, ok := entidRaw.(map[string]any); ok {
|
|
329
|
+
idmap = entidMap
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
return &${entity.name}DirectSetupResult{client: client, calls: calls, live: true, idmap: idmap}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
mockFetch := func(url string, init map[string]any) (map[string]any, error) {
|
|
337
|
+
*calls = append(*calls, map[string]any{"url": url, "init": init})
|
|
338
|
+
return map[string]any{
|
|
339
|
+
"status": 200,
|
|
340
|
+
"statusText": "OK",
|
|
341
|
+
"headers": map[string]any{},
|
|
342
|
+
"json": (func() any)(func() any {
|
|
343
|
+
if mockres != nil {
|
|
344
|
+
return mockres
|
|
345
|
+
}
|
|
346
|
+
return map[string]any{"id": "direct01"}
|
|
347
|
+
}),
|
|
348
|
+
}, nil
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
client := sdk.New${model.const.Name}SDK(map[string]any{
|
|
352
|
+
"base": "http://localhost:8080",
|
|
353
|
+
"system": map[string]any{
|
|
354
|
+
"fetch": (func(string, map[string]any) (map[string]any, error))(mockFetch),
|
|
355
|
+
},
|
|
356
|
+
})
|
|
357
|
+
|
|
358
|
+
return &${entity.name}DirectSetupResult{client: client, calls: calls, live: false, idmap: map[string]any{}}
|
|
359
|
+
}
|
|
360
|
+
`)
|
|
361
|
+
|
|
362
|
+
// Suppress unused import warnings
|
|
363
|
+
Content(`
|
|
364
|
+
var _ = os.Getenv
|
|
365
|
+
var _ = json.Unmarshal
|
|
366
|
+
`)
|
|
367
|
+
})
|
|
368
|
+
})
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
export {
|
|
372
|
+
TestDirect
|
|
373
|
+
}
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
|
|
2
|
+
import {
|
|
3
|
+
KIT,
|
|
4
|
+
getModelPath,
|
|
5
|
+
} from '@voxgig/apidef'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
Content,
|
|
10
|
+
File,
|
|
11
|
+
cmp,
|
|
12
|
+
each,
|
|
13
|
+
} from '@voxgig/sdkgen'
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
const TestEntity = cmp(function TestEntity(props: any) {
|
|
17
|
+
const ctx$ = props.ctx$
|
|
18
|
+
const model = ctx$.model
|
|
19
|
+
|
|
20
|
+
const target = props.target
|
|
21
|
+
const entity = props.entity
|
|
22
|
+
const gomodule = props.gomodule
|
|
23
|
+
|
|
24
|
+
const basicflow = getModelPath(model, `main.${KIT}.flow.Basic${entity.Name}Flow`)
|
|
25
|
+
const dobasic = basicflow && true === basicflow.active
|
|
26
|
+
|
|
27
|
+
if (!dobasic) {
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const steps = basicflow.step || []
|
|
32
|
+
const createStep = steps.find((s: any) => s.op === 'create')
|
|
33
|
+
const updateStep = steps.find((s: any) => s.op === 'update')
|
|
34
|
+
const listSteps = steps.filter((s: any) => s.op === 'list')
|
|
35
|
+
const firstListStep = listSteps[0]
|
|
36
|
+
const lastListStep = listSteps[listSteps.length - 1]
|
|
37
|
+
|
|
38
|
+
const ref = createStep?.input?.ref || entity.name + '_ref01'
|
|
39
|
+
// Convert snake_case ref to camelCase for Go variable names
|
|
40
|
+
const refVar = ref.replace(/_([a-z0-9])/g, (_: any, c: string) => c.toUpperCase())
|
|
41
|
+
const ancestors = (entity.relations?.ancestors || []).flat()
|
|
42
|
+
const PROJUPPER = model.const.Name.toUpperCase()
|
|
43
|
+
const textfield = updateStep?.input?.textfield || 'kind'
|
|
44
|
+
const mark = updateStep?.spec?.[0]?.def?.mark || `Mark01-${ref}`
|
|
45
|
+
|
|
46
|
+
// Build idmap names: entity's own + ancestor ids
|
|
47
|
+
const idnames: string[] = []
|
|
48
|
+
for (let i = 1; i <= 3; i++) idnames.push(`${entity.name}0${i}`)
|
|
49
|
+
for (const anc of ancestors) {
|
|
50
|
+
for (let i = 1; i <= 3; i++) idnames.push(`${anc}0${i}`)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Get match entries from flow steps (filter out $ keys)
|
|
54
|
+
const getMatch = (step: any) => {
|
|
55
|
+
if (!step?.match) return []
|
|
56
|
+
return Object.entries(step.match).filter(([k]: any) => !k.endsWith('$'))
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const createMatch = getMatch(createStep)
|
|
60
|
+
const firstListMatch = getMatch(firstListStep)
|
|
61
|
+
const lastListMatch = getMatch(lastListStep)
|
|
62
|
+
|
|
63
|
+
// Get update data entries (non-id, non-$ keys)
|
|
64
|
+
const updateData = updateStep?.data
|
|
65
|
+
? Object.entries(updateStep.data).filter(([k]: any) => k !== 'id' && !k.endsWith('$'))
|
|
66
|
+
: []
|
|
67
|
+
|
|
68
|
+
// Aliases needed from update data entries
|
|
69
|
+
const aliases = updateData.map(([k, v]: any) => [k, v])
|
|
70
|
+
|
|
71
|
+
const idnamesStr = idnames.map(n => `"${n}"`).join(', ')
|
|
72
|
+
|
|
73
|
+
File({ name: entity.name + '_entity_test.' + target.ext }, () => {
|
|
74
|
+
|
|
75
|
+
Content(`package sdktest
|
|
76
|
+
|
|
77
|
+
import (
|
|
78
|
+
"encoding/json"
|
|
79
|
+
"fmt"
|
|
80
|
+
"os"
|
|
81
|
+
"path/filepath"
|
|
82
|
+
"runtime"
|
|
83
|
+
"testing"
|
|
84
|
+
"time"
|
|
85
|
+
|
|
86
|
+
sdk "${gomodule}"
|
|
87
|
+
"${gomodule}/core"
|
|
88
|
+
|
|
89
|
+
vs "github.com/voxgig/struct"
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
func Test${entity.Name}Entity(t *testing.T) {
|
|
93
|
+
t.Run("instance", func(t *testing.T) {
|
|
94
|
+
testsdk := sdk.TestSDK(nil, nil)
|
|
95
|
+
ent := testsdk.${entity.Name}(nil)
|
|
96
|
+
if ent == nil {
|
|
97
|
+
t.Fatal("expected non-nil ${entity.Name}Entity")
|
|
98
|
+
}
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
t.Run("basic", func(t *testing.T) {
|
|
102
|
+
setup := ${entity.name}BasicSetup(nil)
|
|
103
|
+
client := setup.client
|
|
104
|
+
|
|
105
|
+
// CREATE
|
|
106
|
+
${entity.name}Ent := client.${entity.Name}(nil)
|
|
107
|
+
${refVar}Data := core.ToMapAny(vs.GetProp(
|
|
108
|
+
vs.GetPath([]any{"new", "${entity.name}"}, setup.data), "${ref}"))
|
|
109
|
+
`)
|
|
110
|
+
|
|
111
|
+
// Add create match entries
|
|
112
|
+
for (const [key, val] of createMatch) {
|
|
113
|
+
Content(` ${refVar}Data["${key}"] = setup.idmap["${val}"]
|
|
114
|
+
`)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
Content(`
|
|
118
|
+
createResult, err := ${entity.name}Ent.Create(${refVar}Data, nil)
|
|
119
|
+
if err != nil {
|
|
120
|
+
t.Fatalf("create failed: %v", err)
|
|
121
|
+
}
|
|
122
|
+
createData := core.ToMapAny(createResult)
|
|
123
|
+
if createData == nil {
|
|
124
|
+
t.Fatal("expected create result to be a map")
|
|
125
|
+
}
|
|
126
|
+
if createData["id"] == nil {
|
|
127
|
+
t.Fatal("expected created entity to have an id")
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// LIST
|
|
131
|
+
`)
|
|
132
|
+
|
|
133
|
+
// Generate list match map
|
|
134
|
+
if (firstListMatch.length === 0) {
|
|
135
|
+
Content(` ${refVar}Match := map[string]any{}
|
|
136
|
+
`)
|
|
137
|
+
} else {
|
|
138
|
+
Content(` ${refVar}Match := map[string]any{
|
|
139
|
+
`)
|
|
140
|
+
for (const [key, val] of firstListMatch) {
|
|
141
|
+
Content(` "${key}": setup.idmap["${val}"],
|
|
142
|
+
`)
|
|
143
|
+
}
|
|
144
|
+
Content(` }
|
|
145
|
+
`)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
Content(` listResult, err := ${entity.name}Ent.List(${refVar}Match, nil)
|
|
149
|
+
if err != nil {
|
|
150
|
+
t.Fatalf("list failed: %v", err)
|
|
151
|
+
}
|
|
152
|
+
listData, ok := listResult.([]any)
|
|
153
|
+
if !ok {
|
|
154
|
+
t.Fatalf("expected list result to be an array, got %T", listResult)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
found := vs.Select(entityListToData(listData), map[string]any{"id": createData["id"]})
|
|
158
|
+
if vs.IsEmpty(found) {
|
|
159
|
+
t.Fatal("expected to find created entity in list")
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// UPDATE
|
|
163
|
+
markValue := fmt.Sprintf("${mark}_%d", setup.now)
|
|
164
|
+
${refVar}DataUp := map[string]any{
|
|
165
|
+
"id": createData["id"],
|
|
166
|
+
`)
|
|
167
|
+
|
|
168
|
+
// Add update data entries
|
|
169
|
+
for (const [key] of updateData) {
|
|
170
|
+
Content(` "${key}": setup.idmap["${key}"],
|
|
171
|
+
`)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
Content(` "${textfield}": markValue,
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
updateResult, err := ${entity.name}Ent.Update(${refVar}DataUp, nil)
|
|
178
|
+
if err != nil {
|
|
179
|
+
t.Fatalf("update failed: %v", err)
|
|
180
|
+
}
|
|
181
|
+
updateData := core.ToMapAny(updateResult)
|
|
182
|
+
if updateData == nil {
|
|
183
|
+
t.Fatal("expected update result to be a map")
|
|
184
|
+
}
|
|
185
|
+
if updateData["id"] != createData["id"] {
|
|
186
|
+
t.Fatal("expected update result id to match")
|
|
187
|
+
}
|
|
188
|
+
if updateData["${textfield}"] != markValue {
|
|
189
|
+
t.Fatalf("expected ${textfield} to be updated, got %v", updateData["${textfield}"])
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// LOAD
|
|
193
|
+
${refVar}MatchDt := map[string]any{
|
|
194
|
+
"id": createData["id"],
|
|
195
|
+
}
|
|
196
|
+
loadResult, err := ${entity.name}Ent.Load(${refVar}MatchDt, nil)
|
|
197
|
+
if err != nil {
|
|
198
|
+
t.Fatalf("load failed: %v", err)
|
|
199
|
+
}
|
|
200
|
+
loadData := core.ToMapAny(loadResult)
|
|
201
|
+
if loadData == nil {
|
|
202
|
+
t.Fatal("expected load result to be a map")
|
|
203
|
+
}
|
|
204
|
+
if loadData["id"] != createData["id"] {
|
|
205
|
+
t.Fatal("expected load result id to match")
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// REMOVE
|
|
209
|
+
${refVar}MatchRm := map[string]any{
|
|
210
|
+
"id": createData["id"],
|
|
211
|
+
}
|
|
212
|
+
_, err = ${entity.name}Ent.Remove(${refVar}MatchRm, nil)
|
|
213
|
+
if err != nil {
|
|
214
|
+
t.Fatalf("remove failed: %v", err)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// LIST (verify removed)
|
|
218
|
+
`)
|
|
219
|
+
|
|
220
|
+
// Generate verify list match map
|
|
221
|
+
if (lastListMatch.length === 0) {
|
|
222
|
+
Content(` ${refVar}MatchRt := map[string]any{}
|
|
223
|
+
`)
|
|
224
|
+
} else {
|
|
225
|
+
Content(` ${refVar}MatchRt := map[string]any{
|
|
226
|
+
`)
|
|
227
|
+
for (const [key, val] of lastListMatch) {
|
|
228
|
+
Content(` "${key}": setup.idmap["${val}"],
|
|
229
|
+
`)
|
|
230
|
+
}
|
|
231
|
+
Content(` }
|
|
232
|
+
`)
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
Content(` listResult2, err := ${entity.name}Ent.List(${refVar}MatchRt, nil)
|
|
236
|
+
if err != nil {
|
|
237
|
+
t.Fatalf("list after remove failed: %v", err)
|
|
238
|
+
}
|
|
239
|
+
listData2, ok := listResult2.([]any)
|
|
240
|
+
if !ok {
|
|
241
|
+
t.Fatalf("expected list result to be an array, got %T", listResult2)
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
found2 := vs.Select(entityListToData(listData2), map[string]any{"id": createData["id"]})
|
|
245
|
+
if !vs.IsEmpty(found2) {
|
|
246
|
+
t.Fatal("expected removed entity to not be in list")
|
|
247
|
+
}
|
|
248
|
+
})
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
`)
|
|
252
|
+
|
|
253
|
+
// Generate setup function
|
|
254
|
+
Content(`func ${entity.name}BasicSetup(extra map[string]any) *entityTestSetup {
|
|
255
|
+
loadEnvLocal()
|
|
256
|
+
|
|
257
|
+
_, filename, _, _ := runtime.Caller(0)
|
|
258
|
+
dir := filepath.Dir(filename)
|
|
259
|
+
|
|
260
|
+
entityDataFile := filepath.Join(dir, "..", "..", ".sdk", "test", "entity", "${entity.name}", "${entity.Name}TestData.json")
|
|
261
|
+
|
|
262
|
+
entityDataSource, err := os.ReadFile(entityDataFile)
|
|
263
|
+
if err != nil {
|
|
264
|
+
panic("failed to read ${entity.name} test data: " + err.Error())
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
var entityData map[string]any
|
|
268
|
+
if err := json.Unmarshal(entityDataSource, &entityData); err != nil {
|
|
269
|
+
panic("failed to parse ${entity.name} test data: " + err.Error())
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
options := map[string]any{}
|
|
273
|
+
options["entity"] = entityData["existing"]
|
|
274
|
+
|
|
275
|
+
client := sdk.TestSDK(options, extra)
|
|
276
|
+
|
|
277
|
+
`)
|
|
278
|
+
|
|
279
|
+
// Generate idmap via vs.Transform
|
|
280
|
+
Content('\t// Generate idmap via transform, matching TS pattern.\n')
|
|
281
|
+
Content('\tidmap := vs.Transform(\n')
|
|
282
|
+
Content('\t\t[]any{' + idnamesStr + '},\n')
|
|
283
|
+
Content('\t\tmap[string]any{\n')
|
|
284
|
+
Content('\t\t\t"`$PACK`": []any{"", map[string]any{\n')
|
|
285
|
+
Content('\t\t\t\t"`$KEY`": "`$COPY`",\n')
|
|
286
|
+
Content('\t\t\t\t"`$VAL`": []any{"`$FORMAT`", "upper", "`$COPY`"},\n')
|
|
287
|
+
Content('\t\t\t}},\n')
|
|
288
|
+
Content('\t\t},\n')
|
|
289
|
+
Content('\t)\n')
|
|
290
|
+
|
|
291
|
+
Content(`
|
|
292
|
+
env := envOverride(map[string]any{
|
|
293
|
+
"${PROJUPPER}_TEST_${entity.name.toUpperCase()}_ENTID": idmap,
|
|
294
|
+
"${PROJUPPER}_TEST_LIVE": "FALSE",
|
|
295
|
+
"${PROJUPPER}_TEST_EXPLAIN": "FALSE",
|
|
296
|
+
"${PROJUPPER}_APIKEY": "NONE",
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
idmapResolved := core.ToMapAny(env["${PROJUPPER}_TEST_${entity.name.toUpperCase()}_ENTID"])
|
|
300
|
+
if idmapResolved == nil {
|
|
301
|
+
idmapResolved = core.ToMapAny(idmap)
|
|
302
|
+
}
|
|
303
|
+
`)
|
|
304
|
+
|
|
305
|
+
// Add aliases for ancestor field names
|
|
306
|
+
for (const [key, val] of aliases) {
|
|
307
|
+
Content(` // Add ${key} alias for update test.
|
|
308
|
+
if idmapResolved["${key}"] == nil {
|
|
309
|
+
idmapResolved["${key}"] = idmapResolved["${val}"]
|
|
310
|
+
}
|
|
311
|
+
`)
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
Content(`
|
|
315
|
+
if env["${PROJUPPER}_TEST_LIVE"] == "TRUE" {
|
|
316
|
+
mergedOpts := vs.Merge([]any{
|
|
317
|
+
map[string]any{
|
|
318
|
+
"apikey": env["${PROJUPPER}_APIKEY"],
|
|
319
|
+
},
|
|
320
|
+
extra,
|
|
321
|
+
})
|
|
322
|
+
client = sdk.New${model.const.Name}SDK(core.ToMapAny(mergedOpts))
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return &entityTestSetup{
|
|
326
|
+
client: client,
|
|
327
|
+
data: entityData,
|
|
328
|
+
idmap: idmapResolved,
|
|
329
|
+
env: env,
|
|
330
|
+
explain: env["${PROJUPPER}_TEST_EXPLAIN"] == "TRUE",
|
|
331
|
+
now: time.Now().UnixMilli(),
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
`)
|
|
335
|
+
})
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
export {
|
|
340
|
+
TestEntity
|
|
341
|
+
}
|