@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.
Files changed (135) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/dist/cmp/Main.js +0 -12
  3. package/dist/cmp/Main.js.map +1 -1
  4. package/package.json +1 -1
  5. package/project/.sdk/src/cmp/go/Config_go.ts +6 -2
  6. package/project/.sdk/src/cmp/js/EntityBase_js.ts +34 -0
  7. package/project/.sdk/src/cmp/js/Main_js.ts +10 -0
  8. package/project/.sdk/src/cmp/js/ReadmeExplanation_js.ts +33 -0
  9. package/project/.sdk/src/cmp/js/ReadmeHowto_js.ts +123 -0
  10. package/project/.sdk/src/cmp/js/ReadmeModel_js.ts +152 -0
  11. package/project/.sdk/src/cmp/js/ReadmeTopHowto_js.ts +25 -0
  12. package/project/.sdk/src/cmp/js/ReadmeTopQuick_js.ts +65 -0
  13. package/project/.sdk/src/cmp/js/ReadmeTopTest_js.ts +36 -0
  14. package/project/.sdk/src/cmp/js/TestDirect_js.ts +53 -5
  15. package/project/.sdk/src/cmp/js/TestEntity_js.ts +114 -20
  16. package/project/.sdk/src/cmp/js/fragment/Entity.fragment.js +7 -139
  17. package/project/.sdk/src/cmp/js/fragment/EntityBase.fragment.js +149 -0
  18. package/project/.sdk/src/cmp/js/fragment/EntityCreateOp.fragment.js +6 -10
  19. package/project/.sdk/src/cmp/js/fragment/EntityListOp.fragment.js +6 -10
  20. package/project/.sdk/src/cmp/js/fragment/EntityLoadOp.fragment.js +7 -11
  21. package/project/.sdk/src/cmp/js/fragment/EntityRemoveOp.fragment.js +7 -11
  22. package/project/.sdk/src/cmp/js/fragment/EntityUpdateOp.fragment.js +7 -11
  23. package/project/.sdk/src/cmp/js/fragment/Main.fragment.js +2 -0
  24. package/project/.sdk/src/cmp/js/fragment/SdkError.fragment.js +0 -2
  25. package/project/.sdk/src/cmp/lua/Config_lua.ts +6 -2
  26. package/project/.sdk/src/cmp/lua/TestEntity_lua.ts +3 -1
  27. package/project/.sdk/src/cmp/php/Config_php.ts +6 -2
  28. package/project/.sdk/src/cmp/php/TestDirect_php.ts +2 -2
  29. package/project/.sdk/src/cmp/php/TestEntity_php.ts +10 -15
  30. package/project/.sdk/src/cmp/py/Config_py.ts +6 -2
  31. package/project/.sdk/src/cmp/py/TestEntity_py.ts +3 -1
  32. package/project/.sdk/src/cmp/rb/Config_rb.ts +6 -2
  33. package/project/.sdk/src/cmp/ts/Main_ts.ts +7 -0
  34. package/project/.sdk/tm/go/feature/log_feature.go +1 -1
  35. package/project/.sdk/tm/go/test/runner_test.go +16 -2
  36. package/project/.sdk/tm/js/src/Context.js +142 -0
  37. package/project/.sdk/tm/js/src/Control.js +16 -0
  38. package/project/.sdk/tm/js/src/Operation.js +19 -0
  39. package/project/.sdk/tm/js/src/Point.js +24 -0
  40. package/project/.sdk/tm/js/src/README.md +1 -0
  41. package/project/.sdk/tm/js/src/Response.js +19 -0
  42. package/project/.sdk/tm/js/src/Result.js +21 -0
  43. package/project/.sdk/tm/js/src/Spec.js +26 -0
  44. package/project/.sdk/tm/js/src/feature/README.md +1 -0
  45. package/project/.sdk/tm/js/src/feature/base/BaseFeature.js +45 -0
  46. package/project/.sdk/tm/js/src/feature/log/LogFeature.js +46 -47
  47. package/project/.sdk/tm/js/src/feature/test/TestFeature.js +207 -0
  48. package/project/.sdk/tm/js/src/types.js +22 -0
  49. package/project/.sdk/tm/js/src/utility/CleanUtility.js +31 -0
  50. package/project/.sdk/tm/js/src/utility/DoneUtility.js +11 -4
  51. package/project/.sdk/tm/js/src/utility/FeatureAddUtility.js +42 -0
  52. package/project/.sdk/tm/js/src/utility/FeatureHookUtility.js +25 -0
  53. package/project/.sdk/tm/js/src/utility/FeatureInitUtility.js +11 -0
  54. package/project/.sdk/tm/js/src/utility/FetcherUtility.js +28 -0
  55. package/project/.sdk/tm/js/src/utility/MakeContextUtility.js +11 -0
  56. package/project/.sdk/tm/js/src/utility/MakeErrorUtility.js +55 -0
  57. package/project/.sdk/tm/js/src/utility/MakeFetchDefUtility.js +44 -0
  58. package/project/.sdk/tm/js/src/utility/MakeOptionsUtility.js +93 -0
  59. package/project/.sdk/tm/js/src/utility/MakePointUtility.js +77 -0
  60. package/project/.sdk/tm/js/src/utility/MakeRequestUtility.js +63 -0
  61. package/project/.sdk/tm/js/src/utility/MakeResponseUtility.js +55 -0
  62. package/project/.sdk/tm/js/src/utility/MakeResultUtility.js +54 -0
  63. package/project/.sdk/tm/js/src/utility/MakeSpecUtility.js +58 -0
  64. package/project/.sdk/tm/js/src/utility/MakeUrlUtility.js +40 -0
  65. package/project/.sdk/tm/js/src/utility/ParamUtility.js +61 -0
  66. package/project/.sdk/tm/js/src/utility/PrepareAuthUtility.js +41 -0
  67. package/project/.sdk/tm/js/src/utility/PrepareBodyUtility.js +25 -0
  68. package/project/.sdk/tm/js/src/utility/PrepareHeadersUtility.js +18 -0
  69. package/project/.sdk/tm/js/src/utility/{MethodUtility.js → PrepareMethodUtility.js} +7 -7
  70. package/project/.sdk/tm/js/src/utility/PrepareParamsUtility.js +25 -0
  71. package/project/.sdk/tm/js/src/utility/PreparePathUtility.js +13 -0
  72. package/project/.sdk/tm/js/src/utility/PrepareQueryUtility.js +26 -0
  73. package/project/.sdk/tm/js/src/utility/README.md +1 -0
  74. package/project/.sdk/tm/js/src/utility/ResultBasicUtility.js +34 -0
  75. package/project/.sdk/tm/js/src/utility/ResultBodyUtility.js +18 -0
  76. package/project/.sdk/tm/js/src/utility/ResultHeadersUtility.js +22 -0
  77. package/project/.sdk/tm/js/src/utility/StructUtility.js +2219 -1078
  78. package/project/.sdk/tm/js/src/utility/TransformRequestUtility.js +28 -0
  79. package/project/.sdk/tm/js/src/utility/TransformResponseUtility.js +31 -0
  80. package/project/.sdk/tm/js/src/utility/Utility.js +61 -61
  81. package/project/.sdk/tm/js/test/README.md +1 -0
  82. package/project/.sdk/tm/js/test/exists.test.js +16 -0
  83. package/project/.sdk/tm/js/test/runner.js +323 -107
  84. package/project/.sdk/tm/js/test/utility/Custom.test.js +41 -63
  85. package/project/.sdk/tm/js/test/utility/PrimaryUtility.test.js +390 -116
  86. package/project/.sdk/tm/js/test/utility/StructUtility.test.js +728 -175
  87. package/project/.sdk/tm/js/test/utility/index.js +9 -0
  88. package/project/.sdk/tm/js/test/utility.js +72 -0
  89. package/project/.sdk/tm/lua/test/primary_utility_test.lua +1213 -0
  90. package/project/.sdk/tm/lua/test/runner.lua +2 -2
  91. package/project/.sdk/tm/lua/test/struct_runner.lua +602 -0
  92. package/project/.sdk/tm/lua/test/struct_utility_test.lua +959 -0
  93. package/project/.sdk/tm/lua/utility/struct/struct.lua +10 -0
  94. package/project/.sdk/tm/php/feature/TestFeature.php +59 -96
  95. package/project/.sdk/tm/php/test/PrimaryUtilityTest.php +1309 -0
  96. package/project/.sdk/tm/php/test/Runner.php +24 -1
  97. package/project/.sdk/tm/php/test/StructRunner.php +275 -0
  98. package/project/.sdk/tm/php/test/StructUtilityTest.php +1336 -0
  99. package/project/.sdk/tm/php/utility/Fetcher.php +6 -2
  100. package/project/.sdk/tm/php/utility/MakeOptions.php +5 -1
  101. package/project/.sdk/tm/php/utility/MakeResult.php +3 -0
  102. package/project/.sdk/tm/php/utility/Param.php +9 -7
  103. package/project/.sdk/tm/php/utility/struct/Struct.php +312 -208
  104. package/project/.sdk/tm/py/test/runner.py +13 -0
  105. package/project/.sdk/tm/py/test/struct_runner.py +411 -0
  106. package/project/.sdk/tm/py/test/test_primary_utility.py +1101 -0
  107. package/project/.sdk/tm/py/test/test_struct_utility.py +751 -0
  108. package/project/.sdk/tm/rb/test/primary_utility_test.rb +1083 -0
  109. package/project/.sdk/tm/rb/test/runner.rb +5 -0
  110. package/project/.sdk/tm/rb/test/struct_runner.rb +309 -0
  111. package/project/.sdk/tm/rb/test/struct_utility_test.rb +670 -0
  112. package/src/cmp/Main.ts +1 -16
  113. package/project/.sdk/src/cmp/js/Quick_js.ts +0 -78
  114. package/project/.sdk/src/cmp/js/TestAcceptEntity_js.ts +0 -13
  115. package/project/.sdk/src/cmp/js/TestAccept_js.ts +0 -18
  116. package/project/.sdk/tm/js/src/utility/AuthUtility.js +0 -21
  117. package/project/.sdk/tm/js/src/utility/BodyUtility.js +0 -29
  118. package/project/.sdk/tm/js/src/utility/ErrorUtility.js +0 -33
  119. package/project/.sdk/tm/js/src/utility/FindparamUtility.js +0 -31
  120. package/project/.sdk/tm/js/src/utility/FullurlUtility.js +0 -39
  121. package/project/.sdk/tm/js/src/utility/HeadersUtility.js +0 -13
  122. package/project/.sdk/tm/js/src/utility/JoinurlUtility.js +0 -14
  123. package/project/.sdk/tm/js/src/utility/OperatorUtility.js +0 -44
  124. package/project/.sdk/tm/js/src/utility/OptionsUtility.js +0 -54
  125. package/project/.sdk/tm/js/src/utility/ParamsUtility.js +0 -21
  126. package/project/.sdk/tm/js/src/utility/QueryUtility.js +0 -21
  127. package/project/.sdk/tm/js/src/utility/ReqformUtility.js +0 -32
  128. package/project/.sdk/tm/js/src/utility/RequestUtility.js +0 -48
  129. package/project/.sdk/tm/js/src/utility/ResbasicUtility.js +0 -27
  130. package/project/.sdk/tm/js/src/utility/ResbodyUtility.js +0 -15
  131. package/project/.sdk/tm/js/src/utility/ResformUtility.js +0 -34
  132. package/project/.sdk/tm/js/src/utility/ResheadersUtility.js +0 -19
  133. package/project/.sdk/tm/js/src/utility/ResponseUtility.js +0 -37
  134. package/project/.sdk/tm/js/src/utility/ResultUtility.js +0 -28
  135. 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, deepEqual } = require('node:assert')
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 { runner } = require('../runner')
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
- async function MockFetch(url, fetchdef) {
11
- return {
12
- status: 200,
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
- const runners = {
17
- auth: await runner('auth'),
18
- body: await runner('body'),
19
- error: await runner('error'),
20
- findparam: await runner('findparam'),
21
- fullurl: await runner('fullurl'),
22
- headers: await runner('headers'),
23
- method: await runner('method'),
24
- operator: await runner('operator'),
25
- options: await runner('options'),
26
- params: await runner('params'),
27
- query: await runner('query'),
28
- reqform: await runner('reqform'),
29
- request: await runner('request', { fetch: MockFetch }),
30
- resbasic: await runner('resbasic'),
31
- resbody: await runner('resbody'),
32
- resform: await runner('resform'),
33
- resheaders: await runner('resheaders'),
34
- response: await runner('response'),
35
- spec: await runner('spec'),
36
- }
37
-
38
-
39
- test('exists', async ()=>{
40
- equal('function', typeof runners.auth.subject)
41
- equal('function', typeof runners.body.subject)
42
- equal('function', typeof runners.error.subject)
43
- equal('function', typeof runners.findparam.subject)
44
- equal('function', typeof runners.fullurl.subject)
45
- equal('function', typeof runners.method.subject)
46
- equal('function', typeof runners.operator.subject)
47
- equal('function', typeof runners.options.subject)
48
- equal('function', typeof runners.params.subject)
49
- equal('function', typeof runners.query.subject)
50
- equal('function', typeof runners.reqform.subject)
51
- equal('function', typeof runners.request.subject)
52
- equal('function', typeof runners.resbasic.subject)
53
- equal('function', typeof runners.resbody.subject)
54
- equal('function', typeof runners.resform.subject)
55
- equal('function', typeof runners.resheaders.subject)
56
- equal('function', typeof runners.response.subject)
57
- equal('function', typeof runners.spec.subject)
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 { runset, spec, subject } = runners.auth
63
- await runset(spec.basic, undefined, (subject)=>(vin)=>{
64
- return subject(vin, vin.spec)
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('body-basic', async () => {
70
- const { runset, spec, subject } = runners.body
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('error-basic', async () => {
76
- const { runset, spec, subject } = runners.error
77
- await runset(spec.basic, subject)
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
- const { runset, spec, subject } = runners.findparam
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
- const { runset, spec, subject } = runners.fullurl
89
- await runset(spec.basic, subject)
113
+ await runset(spec.makeUrl.basic, utility.makeUrl)
90
114
  })
91
115
 
92
116
 
93
- test('headers-basic', async () => {
94
- const { runset, spec, subject } = runners.headers
95
- await runset(spec.basic, subject)
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('method-basic', async () => {
100
- const { runset, spec, subject } = runners.method
101
- await runset(spec.basic, subject)
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('operator-basic', async () => {
106
- const { runset, spec, subject } = runners.operator
107
- await runset(spec.basic, subject)
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
- test('options-basic', async () => {
112
- const { runset, spec, subject } = runners.options
113
- await runset(spec.basic, subject)
147
+
148
+ test('reqform-basic', async () => {
149
+ await runset(spec.transformRequest.basic, utility.transformRequest)
114
150
  })
115
-
116
151
 
117
- test('params-basic', async () => {
118
- const { runset, spec, subject } = runners.params
119
- await runset(spec.basic, subject)
152
+
153
+ test('resform-basic', async () => {
154
+ await runset(spec.transformResponse.basic, utility.transformResponse)
120
155
  })
121
156
 
122
157
 
123
- test('query-basic', async () => {
124
- const { runset, spec, subject } = runners.query
125
- await runset(spec.basic, subject)
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('reqform-basic', async () => {
130
- const { runset, spec, subject } = runners.reqform
131
- await runset(spec.basic, subject)
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 { runset, spec, subject } = runners.request
137
- await runset(spec.basic, subject)
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('resbasic-basic', async () => {
142
- const { runset, spec, subject } = runners.resbasic
143
- await runset(spec.basic, subject)
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('resbody-basic', async () => {
148
- const { runset, spec, subject } = runners.resbody
149
- await runset(spec.basic, (ctx, result)=>{
150
- let resdata = ctx.utility.struct.clone(ctx.response)
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('resform-basic', async () => {
158
- const { runset, spec, subject } = runners.resform
159
- await runset(spec.basic, subject)
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('resheaders-basic', async () => {
164
- const { runset, spec, subject } = runners.resheaders
165
- await runset(spec.basic, (ctx, result)=>{
166
- ctx.response.headers.forEach = function (callback) {
167
- Object.keys(this).forEach((key) => {
168
- callback(this[key], key, this)
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('response-basic', async () => {
177
- const { runset, spec, subject } = runners.response
178
- await runset(spec.basic, subject)
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('spec-basic', async () => {
183
- const { runset, spec, subject } = runners.spec
184
- await runset(spec.basic, subject)
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
  })