@voxgig/sdkgen 0.36.0 → 0.37.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 +1 -1
- package/dist/cmp/Main.js +0 -12
- package/dist/cmp/Main.js.map +1 -1
- package/package.json +1 -1
- package/project/.sdk/src/cmp/go/Config_go.ts +6 -2
- package/project/.sdk/src/cmp/js/EntityBase_js.ts +34 -0
- package/project/.sdk/src/cmp/js/Main_js.ts +10 -0
- package/project/.sdk/src/cmp/js/ReadmeExplanation_js.ts +33 -0
- package/project/.sdk/src/cmp/js/ReadmeHowto_js.ts +123 -0
- package/project/.sdk/src/cmp/js/ReadmeModel_js.ts +152 -0
- package/project/.sdk/src/cmp/js/ReadmeTopHowto_js.ts +25 -0
- package/project/.sdk/src/cmp/js/ReadmeTopQuick_js.ts +65 -0
- package/project/.sdk/src/cmp/js/ReadmeTopTest_js.ts +36 -0
- package/project/.sdk/src/cmp/js/TestDirect_js.ts +53 -5
- package/project/.sdk/src/cmp/js/TestEntity_js.ts +114 -20
- package/project/.sdk/src/cmp/js/fragment/Entity.fragment.js +7 -139
- package/project/.sdk/src/cmp/js/fragment/EntityBase.fragment.js +149 -0
- package/project/.sdk/src/cmp/js/fragment/EntityCreateOp.fragment.js +6 -10
- package/project/.sdk/src/cmp/js/fragment/EntityListOp.fragment.js +6 -10
- package/project/.sdk/src/cmp/js/fragment/EntityLoadOp.fragment.js +7 -11
- package/project/.sdk/src/cmp/js/fragment/EntityRemoveOp.fragment.js +7 -11
- package/project/.sdk/src/cmp/js/fragment/EntityUpdateOp.fragment.js +7 -11
- package/project/.sdk/src/cmp/js/fragment/Main.fragment.js +2 -0
- package/project/.sdk/src/cmp/js/fragment/SdkError.fragment.js +0 -2
- package/project/.sdk/src/cmp/lua/Config_lua.ts +6 -2
- package/project/.sdk/src/cmp/lua/TestEntity_lua.ts +3 -1
- package/project/.sdk/src/cmp/php/Config_php.ts +6 -2
- package/project/.sdk/src/cmp/php/TestDirect_php.ts +2 -2
- package/project/.sdk/src/cmp/php/TestEntity_php.ts +10 -15
- package/project/.sdk/src/cmp/py/Config_py.ts +6 -2
- package/project/.sdk/src/cmp/py/TestEntity_py.ts +3 -1
- package/project/.sdk/src/cmp/rb/Config_rb.ts +6 -2
- package/project/.sdk/src/cmp/ts/Main_ts.ts +7 -0
- package/project/.sdk/tm/go/feature/log_feature.go +1 -1
- package/project/.sdk/tm/go/test/runner_test.go +16 -2
- package/project/.sdk/tm/js/src/Context.js +142 -0
- package/project/.sdk/tm/js/src/Control.js +16 -0
- package/project/.sdk/tm/js/src/Operation.js +19 -0
- package/project/.sdk/tm/js/src/Point.js +24 -0
- package/project/.sdk/tm/js/src/README.md +1 -0
- package/project/.sdk/tm/js/src/Response.js +19 -0
- package/project/.sdk/tm/js/src/Result.js +21 -0
- package/project/.sdk/tm/js/src/Spec.js +26 -0
- package/project/.sdk/tm/js/src/feature/README.md +1 -0
- package/project/.sdk/tm/js/src/feature/base/BaseFeature.js +45 -0
- package/project/.sdk/tm/js/src/feature/log/LogFeature.js +46 -47
- package/project/.sdk/tm/js/src/feature/test/TestFeature.js +207 -0
- package/project/.sdk/tm/js/src/types.js +22 -0
- package/project/.sdk/tm/js/src/utility/CleanUtility.js +31 -0
- package/project/.sdk/tm/js/src/utility/DoneUtility.js +11 -4
- package/project/.sdk/tm/js/src/utility/FeatureAddUtility.js +42 -0
- package/project/.sdk/tm/js/src/utility/FeatureHookUtility.js +25 -0
- package/project/.sdk/tm/js/src/utility/FeatureInitUtility.js +11 -0
- package/project/.sdk/tm/js/src/utility/FetcherUtility.js +28 -0
- package/project/.sdk/tm/js/src/utility/MakeContextUtility.js +11 -0
- package/project/.sdk/tm/js/src/utility/MakeErrorUtility.js +55 -0
- package/project/.sdk/tm/js/src/utility/MakeFetchDefUtility.js +44 -0
- package/project/.sdk/tm/js/src/utility/MakeOptionsUtility.js +93 -0
- package/project/.sdk/tm/js/src/utility/MakePointUtility.js +77 -0
- package/project/.sdk/tm/js/src/utility/MakeRequestUtility.js +63 -0
- package/project/.sdk/tm/js/src/utility/MakeResponseUtility.js +55 -0
- package/project/.sdk/tm/js/src/utility/MakeResultUtility.js +54 -0
- package/project/.sdk/tm/js/src/utility/MakeSpecUtility.js +58 -0
- package/project/.sdk/tm/js/src/utility/MakeUrlUtility.js +40 -0
- package/project/.sdk/tm/js/src/utility/ParamUtility.js +61 -0
- package/project/.sdk/tm/js/src/utility/PrepareAuthUtility.js +41 -0
- package/project/.sdk/tm/js/src/utility/PrepareBodyUtility.js +25 -0
- package/project/.sdk/tm/js/src/utility/PrepareHeadersUtility.js +18 -0
- package/project/.sdk/tm/js/src/utility/{MethodUtility.js → PrepareMethodUtility.js} +7 -7
- package/project/.sdk/tm/js/src/utility/PrepareParamsUtility.js +25 -0
- package/project/.sdk/tm/js/src/utility/PreparePathUtility.js +13 -0
- package/project/.sdk/tm/js/src/utility/PrepareQueryUtility.js +26 -0
- package/project/.sdk/tm/js/src/utility/README.md +1 -0
- package/project/.sdk/tm/js/src/utility/ResultBasicUtility.js +34 -0
- package/project/.sdk/tm/js/src/utility/ResultBodyUtility.js +18 -0
- package/project/.sdk/tm/js/src/utility/ResultHeadersUtility.js +22 -0
- package/project/.sdk/tm/js/src/utility/StructUtility.js +2219 -1078
- package/project/.sdk/tm/js/src/utility/TransformRequestUtility.js +28 -0
- package/project/.sdk/tm/js/src/utility/TransformResponseUtility.js +31 -0
- package/project/.sdk/tm/js/src/utility/Utility.js +61 -61
- package/project/.sdk/tm/js/test/README.md +1 -0
- package/project/.sdk/tm/js/test/exists.test.js +16 -0
- package/project/.sdk/tm/js/test/runner.js +323 -107
- package/project/.sdk/tm/js/test/utility/Custom.test.js +41 -63
- package/project/.sdk/tm/js/test/utility/PrimaryUtility.test.js +390 -116
- package/project/.sdk/tm/js/test/utility/StructUtility.test.js +728 -175
- package/project/.sdk/tm/js/test/utility/index.js +9 -0
- package/project/.sdk/tm/js/test/utility.js +72 -0
- package/project/.sdk/tm/lua/test/primary_utility_test.lua +1213 -0
- package/project/.sdk/tm/lua/test/runner.lua +2 -2
- package/project/.sdk/tm/lua/test/struct_runner.lua +602 -0
- package/project/.sdk/tm/lua/test/struct_utility_test.lua +959 -0
- package/project/.sdk/tm/lua/utility/struct/struct.lua +10 -0
- package/project/.sdk/tm/php/feature/TestFeature.php +59 -96
- package/project/.sdk/tm/php/test/PrimaryUtilityTest.php +1309 -0
- package/project/.sdk/tm/php/test/Runner.php +24 -1
- package/project/.sdk/tm/php/test/StructRunner.php +275 -0
- package/project/.sdk/tm/php/test/StructUtilityTest.php +1336 -0
- package/project/.sdk/tm/php/utility/Fetcher.php +6 -2
- package/project/.sdk/tm/php/utility/MakeOptions.php +5 -1
- package/project/.sdk/tm/php/utility/MakeResult.php +3 -0
- package/project/.sdk/tm/php/utility/Param.php +9 -7
- package/project/.sdk/tm/php/utility/struct/Struct.php +312 -208
- package/project/.sdk/tm/py/test/runner.py +13 -0
- package/project/.sdk/tm/py/test/struct_runner.py +411 -0
- package/project/.sdk/tm/py/test/test_primary_utility.py +1101 -0
- package/project/.sdk/tm/py/test/test_struct_utility.py +751 -0
- package/project/.sdk/tm/rb/test/primary_utility_test.rb +1083 -0
- package/project/.sdk/tm/rb/test/runner.rb +5 -0
- package/project/.sdk/tm/rb/test/struct_runner.rb +309 -0
- package/project/.sdk/tm/rb/test/struct_utility_test.rb +670 -0
- package/src/cmp/Main.ts +1 -16
- package/project/.sdk/src/cmp/js/Quick_js.ts +0 -78
- package/project/.sdk/src/cmp/js/TestAcceptEntity_js.ts +0 -13
- package/project/.sdk/src/cmp/js/TestAccept_js.ts +0 -18
- package/project/.sdk/tm/js/src/utility/AuthUtility.js +0 -21
- package/project/.sdk/tm/js/src/utility/BodyUtility.js +0 -29
- package/project/.sdk/tm/js/src/utility/ErrorUtility.js +0 -33
- package/project/.sdk/tm/js/src/utility/FindparamUtility.js +0 -31
- package/project/.sdk/tm/js/src/utility/FullurlUtility.js +0 -39
- package/project/.sdk/tm/js/src/utility/HeadersUtility.js +0 -13
- package/project/.sdk/tm/js/src/utility/JoinurlUtility.js +0 -14
- package/project/.sdk/tm/js/src/utility/OperatorUtility.js +0 -44
- package/project/.sdk/tm/js/src/utility/OptionsUtility.js +0 -54
- package/project/.sdk/tm/js/src/utility/ParamsUtility.js +0 -21
- package/project/.sdk/tm/js/src/utility/QueryUtility.js +0 -21
- package/project/.sdk/tm/js/src/utility/ReqformUtility.js +0 -32
- package/project/.sdk/tm/js/src/utility/RequestUtility.js +0 -48
- package/project/.sdk/tm/js/src/utility/ResbasicUtility.js +0 -27
- package/project/.sdk/tm/js/src/utility/ResbodyUtility.js +0 -15
- package/project/.sdk/tm/js/src/utility/ResformUtility.js +0 -34
- package/project/.sdk/tm/js/src/utility/ResheadersUtility.js +0 -19
- package/project/.sdk/tm/js/src/utility/ResponseUtility.js +0 -37
- package/project/.sdk/tm/js/src/utility/ResultUtility.js +0 -28
- package/project/.sdk/tm/js/src/utility/SpecUtility.js +0 -35
|
@@ -1,187 +1,461 @@
|
|
|
1
1
|
|
|
2
|
-
const { test, describe } = require('node:test')
|
|
3
|
-
const { equal,
|
|
2
|
+
const { test, describe, before } = require('node:test')
|
|
3
|
+
const { equal, deepStrictEqual, ok } = require('node:assert')
|
|
4
|
+
const assert = require('node:assert')
|
|
4
5
|
|
|
5
|
-
const {
|
|
6
|
+
const {
|
|
7
|
+
makeRunner,
|
|
8
|
+
} = require('../runner')
|
|
6
9
|
|
|
10
|
+
const {
|
|
11
|
+
SDK,
|
|
12
|
+
TEST_JSON_FILE
|
|
13
|
+
} = require('./index')
|
|
7
14
|
|
|
8
|
-
describe('PrimaryUtility', async ()=>{
|
|
9
15
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
16
|
+
describe('PrimaryUtility', async () => {
|
|
17
|
+
|
|
18
|
+
let spec
|
|
19
|
+
let runset
|
|
20
|
+
let runsetflags
|
|
21
|
+
let client
|
|
22
|
+
let utility
|
|
23
|
+
let struct
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
// Ensure ctx has options derived from client when needed.
|
|
27
|
+
function fixctx(ctx) {
|
|
28
|
+
if (ctx && ctx.client && null == ctx.options) {
|
|
29
|
+
ctx.options = ctx.client.options()
|
|
13
30
|
}
|
|
14
31
|
}
|
|
15
32
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
33
|
+
|
|
34
|
+
before(async () => {
|
|
35
|
+
const runner = await makeRunner(TEST_JSON_FILE, await SDK.test())
|
|
36
|
+
const run = await runner('primary')
|
|
37
|
+
|
|
38
|
+
spec = run.spec
|
|
39
|
+
runset = run.runset
|
|
40
|
+
runsetflags = run.runsetflags
|
|
41
|
+
client = run.client
|
|
42
|
+
utility = client.utility()
|
|
43
|
+
struct = utility.struct
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
test('exists', () => {
|
|
48
|
+
const fns = [
|
|
49
|
+
'clean', 'done', 'makeError', 'featureAdd', 'featureHook', 'featureInit',
|
|
50
|
+
'fetcher', 'makeFetchDef', 'makeContext', 'makeOptions', 'makeRequest',
|
|
51
|
+
'makeResponse', 'makeResult', 'makePoint', 'makeSpec', 'makeUrl',
|
|
52
|
+
'param', 'prepareAuth', 'prepareBody', 'prepareHeaders', 'prepareMethod',
|
|
53
|
+
'prepareParams', 'preparePath', 'prepareQuery', 'resultBasic',
|
|
54
|
+
'resultBody', 'resultHeaders', 'transformRequest', 'transformResponse',
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
for (const fn of fns) {
|
|
58
|
+
equal('function', typeof utility[fn], fn + ' should be a function')
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
test('context-basic', async () => {
|
|
64
|
+
await runset(spec.makeContext.basic, utility.makeContext)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
test('method-basic', async () => {
|
|
69
|
+
await runset(spec.prepareMethod.basic, utility.prepareMethod)
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
test('headers-basic', async () => {
|
|
74
|
+
await runset(spec.prepareHeaders.basic, utility.prepareHeaders)
|
|
58
75
|
})
|
|
59
76
|
|
|
60
77
|
|
|
61
78
|
test('auth-basic', async () => {
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
79
|
+
const sdkopts = spec.prepareAuth?.DEF?.setup?.a || {}
|
|
80
|
+
const authClient = SDK.test({}, sdkopts)
|
|
81
|
+
await runset(spec.prepareAuth.basic, (ctx) => {
|
|
82
|
+
ctx.client = authClient
|
|
83
|
+
fixctx(ctx)
|
|
84
|
+
return utility.prepareAuth(ctx)
|
|
65
85
|
})
|
|
66
86
|
})
|
|
67
87
|
|
|
68
88
|
|
|
69
|
-
test('
|
|
70
|
-
|
|
71
|
-
await runset(spec.basic, subject)
|
|
89
|
+
test('params-basic', async () => {
|
|
90
|
+
await runset(spec.prepareParams.basic, utility.prepareParams)
|
|
72
91
|
})
|
|
73
92
|
|
|
74
93
|
|
|
75
|
-
test('
|
|
76
|
-
|
|
77
|
-
|
|
94
|
+
test('query-basic', async () => {
|
|
95
|
+
await runset(spec.prepareQuery.basic, utility.prepareQuery)
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
test('body-basic', async () => {
|
|
100
|
+
await runset(spec.prepareBody.basic, (ctx) => {
|
|
101
|
+
fixctx(ctx)
|
|
102
|
+
return utility.prepareBody(ctx)
|
|
103
|
+
})
|
|
78
104
|
})
|
|
79
105
|
|
|
80
106
|
|
|
81
107
|
test('findparam-basic', async () => {
|
|
82
|
-
|
|
83
|
-
await runset(spec.basic, subject)
|
|
108
|
+
await runset(spec.param.basic, utility.param)
|
|
84
109
|
})
|
|
85
110
|
|
|
86
111
|
|
|
87
112
|
test('fullurl-basic', async () => {
|
|
88
|
-
|
|
89
|
-
await runset(spec.basic, subject)
|
|
113
|
+
await runset(spec.makeUrl.basic, utility.makeUrl)
|
|
90
114
|
})
|
|
91
115
|
|
|
92
116
|
|
|
93
|
-
test('
|
|
94
|
-
|
|
95
|
-
|
|
117
|
+
test('operator-basic', async () => {
|
|
118
|
+
await runset(spec.operator.basic, (opmap) => ({
|
|
119
|
+
entity: opmap.entity || '_',
|
|
120
|
+
name: opmap.name || '_',
|
|
121
|
+
input: opmap.input || '_',
|
|
122
|
+
points: opmap.points || [],
|
|
123
|
+
}))
|
|
96
124
|
})
|
|
97
125
|
|
|
98
126
|
|
|
99
|
-
test('
|
|
100
|
-
|
|
101
|
-
|
|
127
|
+
test('options-basic', async () => {
|
|
128
|
+
await runset(spec.makeOptions.basic, (vin) => {
|
|
129
|
+
const ctx = utility.makeContext({ options: vin.options, config: vin.config })
|
|
130
|
+
ctx.client = client
|
|
131
|
+
ctx.utility = utility
|
|
132
|
+
return utility.makeOptions(ctx)
|
|
133
|
+
})
|
|
102
134
|
})
|
|
103
135
|
|
|
104
136
|
|
|
105
|
-
test('
|
|
106
|
-
const
|
|
107
|
-
|
|
137
|
+
test('spec-basic', async () => {
|
|
138
|
+
const sdkopts = spec.makeSpec?.DEF?.setup?.a || {}
|
|
139
|
+
const specClient = SDK.test({}, sdkopts)
|
|
140
|
+
await runset(spec.makeSpec.basic, (ctx) => {
|
|
141
|
+
ctx.client = specClient
|
|
142
|
+
ctx.options = specClient.options()
|
|
143
|
+
return utility.makeSpec(ctx)
|
|
144
|
+
})
|
|
108
145
|
})
|
|
109
|
-
|
|
110
146
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
await runset(spec.basic,
|
|
147
|
+
|
|
148
|
+
test('reqform-basic', async () => {
|
|
149
|
+
await runset(spec.transformRequest.basic, utility.transformRequest)
|
|
114
150
|
})
|
|
115
|
-
|
|
116
151
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
await runset(spec.basic,
|
|
152
|
+
|
|
153
|
+
test('resform-basic', async () => {
|
|
154
|
+
await runset(spec.transformResponse.basic, utility.transformResponse)
|
|
120
155
|
})
|
|
121
156
|
|
|
122
157
|
|
|
123
|
-
test('
|
|
124
|
-
|
|
125
|
-
|
|
158
|
+
test('resbasic-basic', async () => {
|
|
159
|
+
await runset(spec.resultBasic.basic, (ctx) => {
|
|
160
|
+
fixctx(ctx)
|
|
161
|
+
return utility.resultBasic(ctx)
|
|
162
|
+
})
|
|
126
163
|
})
|
|
127
164
|
|
|
128
165
|
|
|
129
|
-
test('
|
|
130
|
-
|
|
131
|
-
|
|
166
|
+
test('resheaders-basic', async () => {
|
|
167
|
+
await runset(spec.resultHeaders.basic, (ctx) => {
|
|
168
|
+
// Convert plain headers map to forEach-based (browser Response API)
|
|
169
|
+
if (ctx.response?.headers && !ctx.response.headers.forEach) {
|
|
170
|
+
const h = ctx.response.headers
|
|
171
|
+
ctx.response.headers = {
|
|
172
|
+
forEach: (cb) => Object.entries(h).forEach(([k, v]) => cb(v, k.toLowerCase()))
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return utility.resultHeaders(ctx)
|
|
176
|
+
})
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
test('resbody-basic', async () => {
|
|
181
|
+
await runset(spec.resultBody.basic, async (ctx) => {
|
|
182
|
+
if (ctx.response && !ctx.response.json) {
|
|
183
|
+
const body = ctx.response.body
|
|
184
|
+
ctx.response.json = async () => body
|
|
185
|
+
}
|
|
186
|
+
return utility.resultBody(ctx)
|
|
187
|
+
})
|
|
132
188
|
})
|
|
133
189
|
|
|
134
190
|
|
|
135
191
|
test('request-basic', async () => {
|
|
136
|
-
const
|
|
137
|
-
|
|
192
|
+
const mockFetch = async (url, init) => ({
|
|
193
|
+
status: 200,
|
|
194
|
+
statusText: 'OK',
|
|
195
|
+
headers: { forEach: (cb) => { cb('application/json', 'content-type', {}) } },
|
|
196
|
+
json: async () => ({ id: 'res01' }),
|
|
197
|
+
body: 'present',
|
|
198
|
+
})
|
|
199
|
+
const reqClient = new SDK({
|
|
200
|
+
system: { fetch: mockFetch }
|
|
201
|
+
})
|
|
202
|
+
const reqUtility = reqClient.utility()
|
|
203
|
+
await runset(spec.makeRequest.basic, async (ctx) => {
|
|
204
|
+
ctx.client = reqClient
|
|
205
|
+
ctx.utility = reqUtility
|
|
206
|
+
ctx.options = reqClient.options()
|
|
207
|
+
return reqUtility.makeRequest(ctx)
|
|
208
|
+
})
|
|
138
209
|
})
|
|
139
210
|
|
|
140
211
|
|
|
141
|
-
test('
|
|
142
|
-
|
|
143
|
-
|
|
212
|
+
test('response-basic', async () => {
|
|
213
|
+
await runset(spec.makeResponse.basic, async (ctx) => {
|
|
214
|
+
fixctx(ctx)
|
|
215
|
+
// Add json() and forEach to response for proper handling
|
|
216
|
+
if (ctx.response && !ctx.response.json) {
|
|
217
|
+
const body = ctx.response.body
|
|
218
|
+
ctx.response.json = async () => body
|
|
219
|
+
}
|
|
220
|
+
if (ctx.response?.headers && !ctx.response.headers.forEach) {
|
|
221
|
+
const h = ctx.response.headers
|
|
222
|
+
ctx.response.headers = {
|
|
223
|
+
forEach: (cb) => Object.entries(h).forEach(([k, v]) => cb(v, k.toLowerCase()))
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return utility.makeResponse(ctx)
|
|
227
|
+
})
|
|
144
228
|
})
|
|
145
229
|
|
|
146
|
-
|
|
147
|
-
test('
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
ctx.response.json = async ()=>resdata
|
|
152
|
-
return subject(ctx, result)
|
|
230
|
+
|
|
231
|
+
test('done-basic', async () => {
|
|
232
|
+
await runset(spec.done.basic, (ctx) => {
|
|
233
|
+
fixctx(ctx)
|
|
234
|
+
return utility.done(ctx)
|
|
153
235
|
})
|
|
154
236
|
})
|
|
155
237
|
|
|
156
238
|
|
|
157
|
-
test('
|
|
158
|
-
|
|
159
|
-
|
|
239
|
+
test('error-basic', async () => {
|
|
240
|
+
await runset(spec.makeError.basic, (...args) => {
|
|
241
|
+
const ctx = args[0]
|
|
242
|
+
fixctx(ctx)
|
|
243
|
+
return utility.makeError(...args)
|
|
244
|
+
})
|
|
160
245
|
})
|
|
161
246
|
|
|
162
247
|
|
|
163
|
-
test('
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
248
|
+
test('makePoint-single', () => {
|
|
249
|
+
const ctx = makeCtx()
|
|
250
|
+
const point = {
|
|
251
|
+
parts: ['items', '{id}'],
|
|
252
|
+
args: { params: [] },
|
|
253
|
+
params: [],
|
|
254
|
+
alias: {},
|
|
255
|
+
select: {},
|
|
256
|
+
active: true,
|
|
257
|
+
transform: { req: undefined, res: undefined },
|
|
258
|
+
}
|
|
259
|
+
ctx.op.points = [point]
|
|
260
|
+
|
|
261
|
+
const result = utility.makePoint(ctx)
|
|
262
|
+
ok(!(result instanceof Error))
|
|
263
|
+
equal(ctx.point, point)
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
test('makeFetchDef', () => {
|
|
268
|
+
const ctx = makeFullCtx()
|
|
269
|
+
ctx.spec = {
|
|
270
|
+
base: 'http://localhost:8080',
|
|
271
|
+
prefix: '/api',
|
|
272
|
+
path: 'items/{id}',
|
|
273
|
+
suffix: '',
|
|
274
|
+
params: { id: 'item01' },
|
|
275
|
+
query: {},
|
|
276
|
+
headers: { 'content-type': 'application/json' },
|
|
277
|
+
method: 'GET',
|
|
278
|
+
step: 'start',
|
|
279
|
+
body: undefined,
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const fetchdef = utility.makeFetchDef(ctx)
|
|
283
|
+
ok(!(fetchdef instanceof Error), 'should not be error')
|
|
284
|
+
equal(fetchdef.method, 'GET')
|
|
285
|
+
ok(fetchdef.url.includes('/api/items/item01'))
|
|
286
|
+
equal(fetchdef.headers['content-type'], 'application/json')
|
|
287
|
+
ok(null == fetchdef.body)
|
|
288
|
+
})
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
test('makeFetchDef-with-body', () => {
|
|
292
|
+
const ctx = makeFullCtx()
|
|
293
|
+
ctx.spec = {
|
|
294
|
+
base: 'http://localhost:8080',
|
|
295
|
+
prefix: '',
|
|
296
|
+
path: 'items',
|
|
297
|
+
suffix: '',
|
|
298
|
+
params: {},
|
|
299
|
+
query: {},
|
|
300
|
+
headers: {},
|
|
301
|
+
method: 'POST',
|
|
302
|
+
step: 'start',
|
|
303
|
+
body: { name: 'test' },
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const fetchdef = utility.makeFetchDef(ctx)
|
|
307
|
+
ok(!(fetchdef instanceof Error))
|
|
308
|
+
equal(fetchdef.method, 'POST')
|
|
309
|
+
equal(fetchdef.body, JSON.stringify({ name: 'test' }, null, 2))
|
|
310
|
+
})
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
test('featureAdd', () => {
|
|
314
|
+
const ctx = makeCtx()
|
|
315
|
+
const startLen = client._features.length
|
|
316
|
+
|
|
317
|
+
const feature = {
|
|
318
|
+
version: '0.0.1',
|
|
319
|
+
name: 'testfeat',
|
|
320
|
+
active: true,
|
|
321
|
+
init: () => { },
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
utility.featureAdd(ctx, feature)
|
|
325
|
+
equal(client._features.length, startLen + 1)
|
|
326
|
+
equal(client._features[client._features.length - 1].name, 'testfeat')
|
|
327
|
+
})
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
test('featureHook', () => {
|
|
331
|
+
const ctx = makeCtx()
|
|
332
|
+
|
|
333
|
+
let called = false
|
|
334
|
+
client._features = [{
|
|
335
|
+
name: 'hookfeat',
|
|
336
|
+
TestHook: () => { called = true },
|
|
337
|
+
}]
|
|
338
|
+
|
|
339
|
+
utility.featureHook(ctx, 'TestHook')
|
|
340
|
+
equal(called, true)
|
|
341
|
+
})
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
test('featureInit', () => {
|
|
345
|
+
const ctx = makeCtx()
|
|
346
|
+
|
|
347
|
+
let initCalled = false
|
|
348
|
+
const feature = {
|
|
349
|
+
name: 'initfeat',
|
|
350
|
+
active: true,
|
|
351
|
+
init: () => { initCalled = true },
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
ctx.options.feature.initfeat = { active: true }
|
|
355
|
+
|
|
356
|
+
utility.featureInit(ctx, feature)
|
|
357
|
+
equal(initCalled, true)
|
|
358
|
+
})
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
test('featureInit-inactive', () => {
|
|
362
|
+
const ctx = makeCtx()
|
|
363
|
+
|
|
364
|
+
let initCalled = false
|
|
365
|
+
const feature = {
|
|
366
|
+
name: 'nofeat',
|
|
367
|
+
active: false,
|
|
368
|
+
init: () => { initCalled = true },
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
ctx.options.feature.nofeat = { active: false }
|
|
372
|
+
|
|
373
|
+
utility.featureInit(ctx, feature)
|
|
374
|
+
equal(initCalled, false)
|
|
375
|
+
})
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
test('fetcher-live', async () => {
|
|
379
|
+
const calls = []
|
|
380
|
+
const liveClient = new SDK({
|
|
381
|
+
system: {
|
|
382
|
+
fetch: async (url, init) => {
|
|
383
|
+
calls.push({ url, init })
|
|
384
|
+
return { status: 200, statusText: 'OK' }
|
|
385
|
+
}
|
|
170
386
|
}
|
|
171
|
-
return subject(ctx, result)
|
|
172
387
|
})
|
|
388
|
+
const liveUtility = liveClient.utility()
|
|
389
|
+
const ctx = liveUtility.makeContext({ opname: 'load' }, liveClient._rootctx)
|
|
390
|
+
ctx.client = liveClient
|
|
391
|
+
|
|
392
|
+
const fetchdef = { method: 'GET', headers: {} }
|
|
393
|
+
const response = await liveUtility.fetcher(ctx, 'http://example.com/test', fetchdef)
|
|
394
|
+
ok(!(response instanceof Error))
|
|
395
|
+
equal(calls.length, 1)
|
|
396
|
+
equal(calls[0].url, 'http://example.com/test')
|
|
173
397
|
})
|
|
174
398
|
|
|
175
|
-
|
|
176
|
-
test('
|
|
177
|
-
const
|
|
178
|
-
|
|
399
|
+
|
|
400
|
+
test('fetcher-blocked-test-mode', async () => {
|
|
401
|
+
const blockedClient = new SDK({
|
|
402
|
+
system: { fetch: async () => ({}) }
|
|
403
|
+
})
|
|
404
|
+
blockedClient._mode = 'test'
|
|
405
|
+
|
|
406
|
+
const blockedUtility = blockedClient.utility()
|
|
407
|
+
const ctx = blockedUtility.makeContext({ opname: 'load' }, blockedClient._rootctx)
|
|
408
|
+
ctx.client = blockedClient
|
|
409
|
+
const fetchdef = { method: 'GET', headers: {} }
|
|
410
|
+
|
|
411
|
+
const result = await blockedUtility.fetcher(ctx, 'http://example.com/test', fetchdef)
|
|
412
|
+
ok(result instanceof Error)
|
|
413
|
+
ok(result.message.includes('mode'))
|
|
179
414
|
})
|
|
180
415
|
|
|
181
416
|
|
|
182
|
-
test('
|
|
183
|
-
const
|
|
184
|
-
|
|
417
|
+
test('makeError-no-throw', () => {
|
|
418
|
+
const ctx = makeFullCtx()
|
|
419
|
+
ctx.ctrl.throw = false
|
|
420
|
+
ctx.result = { ok: false, resdata: { id: 'safe01' } }
|
|
421
|
+
|
|
422
|
+
const out = utility.makeError(ctx, ctx.error('test_code', 'test message'))
|
|
423
|
+
deepStrictEqual(out, { id: 'safe01' })
|
|
424
|
+
})
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
test('clean', () => {
|
|
428
|
+
const ctx = makeFullCtx()
|
|
429
|
+
const val = { key: 'secret123', name: 'test' }
|
|
430
|
+
const cleaned = utility.clean(ctx, val)
|
|
431
|
+
ok(null != cleaned)
|
|
185
432
|
})
|
|
186
|
-
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
// Helper functions for manual tests
|
|
436
|
+
function makeCtx(overrides) {
|
|
437
|
+
return utility.makeContext({
|
|
438
|
+
opname: 'load',
|
|
439
|
+
...overrides,
|
|
440
|
+
}, client._rootctx)
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
function makeFullCtx(overrides) {
|
|
445
|
+
const ctx = makeCtx(overrides)
|
|
446
|
+
ctx.point = {
|
|
447
|
+
parts: ['items', '{id}'],
|
|
448
|
+
args: { params: [{ name: 'id', reqd: true }] },
|
|
449
|
+
params: ['id'],
|
|
450
|
+
alias: {},
|
|
451
|
+
select: {},
|
|
452
|
+
active: true,
|
|
453
|
+
relations: [],
|
|
454
|
+
transform: { req: undefined, res: undefined },
|
|
455
|
+
}
|
|
456
|
+
ctx.match = { id: 'item01' }
|
|
457
|
+
ctx.reqmatch = { id: 'item01' }
|
|
458
|
+
return ctx
|
|
459
|
+
}
|
|
460
|
+
|
|
187
461
|
})
|