@@ -165,10 +165,10 @@ ${data}${secondPayload}`;
165
165
suite ( 'Test Controller Utils: Args Mapping' , ( ) => {
166
166
test ( 'Converts map with mixed values to array of strings' , async ( ) => {
167
167
const inputMap = {
168
- key1 : 'value1' ,
168
+ key1 : [ 'value1' ] ,
169
169
key2 : null ,
170
170
key3 : undefined ,
171
- key4 : 'value4' ,
171
+ key4 : [ 'value4' ] ,
172
172
} ;
173
173
const expectedOutput = [ 'key1=value1' , 'key2' , 'key4=value4' ] ;
174
174
@@ -209,24 +209,35 @@ ${data}${secondPayload}`;
209
209
210
210
assert . deepStrictEqual ( result , expectedOutput ) ;
211
211
} ) ;
212
+ test ( 'Handles mapToArgs for a key with multiple values' , async ( ) => {
213
+ const inputMap = {
214
+ key1 : null ,
215
+ key2 : [ 'value1' , 'value2' ] ,
216
+ } ;
217
+ const expectedOutput = [ 'key1' , 'key2=value1' , 'key2=value2' ] ;
218
+
219
+ const result = mapToArgs ( inputMap ) ;
220
+
221
+ assert . deepStrictEqual ( result , expectedOutput ) ;
222
+ } ) ;
212
223
test ( 'Adds new argument if it does not exist' , ( ) => {
213
224
const map = { } ;
214
225
const argKey = 'newKey' ;
215
226
const argValue = 'newValue' ;
216
227
217
228
const updatedMap = addArgIfNotExist ( map , argKey , argValue ) ;
218
229
219
- assert . deepStrictEqual ( updatedMap , { [ argKey ] : argValue } ) ;
230
+ assert . deepStrictEqual ( updatedMap , { [ argKey ] : [ argValue ] } ) ;
220
231
} ) ;
221
232
222
233
test ( 'Does not overwrite existing argument' , ( ) => {
223
- const map = { existingKey : 'existingValue' } ;
234
+ const map = { existingKey : [ 'existingValue' ] } ;
224
235
const argKey = 'existingKey' ;
225
236
const argValue = 'newValue' ;
226
237
227
238
const updatedMap = addArgIfNotExist ( map , argKey , argValue ) ;
228
239
229
- assert . deepStrictEqual ( updatedMap , { [ argKey ] : 'existingValue' } ) ;
240
+ assert . deepStrictEqual ( updatedMap , { [ argKey ] : [ 'existingValue' ] } ) ;
230
241
} ) ;
231
242
232
243
test ( 'Handles null value for new key' , ( ) => {
@@ -249,21 +260,9 @@ ${data}${secondPayload}`;
249
260
assert . deepStrictEqual ( updatedMap , { [ argKey ] : null } ) ;
250
261
} ) ;
251
262
252
- test ( 'Accepts addition if key exists with undefined value' , ( ) => {
253
- const map = { undefinedKey : undefined } ;
254
- const argKey = 'undefinedKey' ;
255
- const argValue = 'newValue' ;
256
-
257
- // Attempting to add a key that is explicitly set to undefined
258
- const updatedMap = addArgIfNotExist ( map , argKey , argValue ) ;
259
-
260
- // Expect the map to remain unchanged because the key exists as undefined
261
- assert . strictEqual ( map [ argKey ] , argValue ) ;
262
- assert . deepStrictEqual ( updatedMap , { [ argKey ] : argValue } ) ;
263
- } ) ;
264
263
test ( 'Complex test for argKeyExists with various key types' , ( ) => {
265
264
const map = {
266
- stringKey : 'stringValue' ,
265
+ stringKey : [ 'stringValue' ] ,
267
266
nullKey : null ,
268
267
// Note: not adding an 'undefinedKey' explicitly since it's not present and hence undefined by default
269
268
} ;
@@ -289,7 +288,15 @@ ${data}${secondPayload}`;
289
288
} ) ;
290
289
test ( 'Converts array of strings with "=" into a map' , ( ) => {
291
290
const args = [ 'key1=value1' , 'key2=value2' ] ;
292
- const expectedMap = { key1 : 'value1' , key2 : 'value2' } ;
291
+ const expectedMap = { key1 : [ 'value1' ] , key2 : [ 'value2' ] } ;
292
+
293
+ const resultMap = argsToMap ( args ) ;
294
+
295
+ assert . deepStrictEqual ( resultMap , expectedMap ) ;
296
+ } ) ;
297
+ test ( 'Handles argsToMap for multiple values for the same key' , ( ) => {
298
+ const args = [ 'key1=value1' , 'key1=value2' ] ;
299
+ const expectedMap = { key1 : [ 'value1' , 'value2' ] } ;
293
300
294
301
const resultMap = argsToMap ( args ) ;
295
302
@@ -307,7 +314,7 @@ ${data}${secondPayload}`;
307
314
308
315
test ( 'Handles mixed keys with and without "="' , ( ) => {
309
316
const args = [ 'key1=value1' , 'key2' ] ;
310
- const expectedMap = { key1 : 'value1' , key2 : null } ;
317
+ const expectedMap = { key1 : [ 'value1' ] , key2 : null } ;
311
318
312
319
const resultMap = argsToMap ( args ) ;
313
320
@@ -316,7 +323,7 @@ ${data}${secondPayload}`;
316
323
317
324
test ( 'Handles strings with multiple "=" characters' , ( ) => {
318
325
const args = [ 'key1=part1=part2' ] ;
319
- const expectedMap = { key1 : 'part1=part2' } ;
326
+ const expectedMap = { key1 : [ 'part1=part2' ] } ;
320
327
321
328
const resultMap = argsToMap ( args ) ;
322
329
0 commit comments