@@ -165,10 +165,10 @@ ${data}${secondPayload}`;
165165 suite ( 'Test Controller Utils: Args Mapping' , ( ) => {
166166 test ( 'Converts map with mixed values to array of strings' , async ( ) => {
167167 const inputMap = {
168- key1 : 'value1' ,
168+ key1 : [ 'value1' ] ,
169169 key2 : null ,
170170 key3 : undefined ,
171- key4 : 'value4' ,
171+ key4 : [ 'value4' ] ,
172172 } ;
173173 const expectedOutput = [ 'key1=value1' , 'key2' , 'key4=value4' ] ;
174174
@@ -209,24 +209,35 @@ ${data}${secondPayload}`;
209209
210210 assert . deepStrictEqual ( result , expectedOutput ) ;
211211 } ) ;
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+ } ) ;
212223 test ( 'Adds new argument if it does not exist' , ( ) => {
213224 const map = { } ;
214225 const argKey = 'newKey' ;
215226 const argValue = 'newValue' ;
216227
217228 const updatedMap = addArgIfNotExist ( map , argKey , argValue ) ;
218229
219- assert . deepStrictEqual ( updatedMap , { [ argKey ] : argValue } ) ;
230+ assert . deepStrictEqual ( updatedMap , { [ argKey ] : [ argValue ] } ) ;
220231 } ) ;
221232
222233 test ( 'Does not overwrite existing argument' , ( ) => {
223- const map = { existingKey : 'existingValue' } ;
234+ const map = { existingKey : [ 'existingValue' ] } ;
224235 const argKey = 'existingKey' ;
225236 const argValue = 'newValue' ;
226237
227238 const updatedMap = addArgIfNotExist ( map , argKey , argValue ) ;
228239
229- assert . deepStrictEqual ( updatedMap , { [ argKey ] : 'existingValue' } ) ;
240+ assert . deepStrictEqual ( updatedMap , { [ argKey ] : [ 'existingValue' ] } ) ;
230241 } ) ;
231242
232243 test ( 'Handles null value for new key' , ( ) => {
@@ -249,21 +260,9 @@ ${data}${secondPayload}`;
249260 assert . deepStrictEqual ( updatedMap , { [ argKey ] : null } ) ;
250261 } ) ;
251262
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- } ) ;
264263 test ( 'Complex test for argKeyExists with various key types' , ( ) => {
265264 const map = {
266- stringKey : 'stringValue' ,
265+ stringKey : [ 'stringValue' ] ,
267266 nullKey : null ,
268267 // Note: not adding an 'undefinedKey' explicitly since it's not present and hence undefined by default
269268 } ;
@@ -289,7 +288,15 @@ ${data}${secondPayload}`;
289288 } ) ;
290289 test ( 'Converts array of strings with "=" into a map' , ( ) => {
291290 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' ] } ;
293300
294301 const resultMap = argsToMap ( args ) ;
295302
@@ -307,7 +314,7 @@ ${data}${secondPayload}`;
307314
308315 test ( 'Handles mixed keys with and without "="' , ( ) => {
309316 const args = [ 'key1=value1' , 'key2' ] ;
310- const expectedMap = { key1 : 'value1' , key2 : null } ;
317+ const expectedMap = { key1 : [ 'value1' ] , key2 : null } ;
311318
312319 const resultMap = argsToMap ( args ) ;
313320
@@ -316,7 +323,7 @@ ${data}${secondPayload}`;
316323
317324 test ( 'Handles strings with multiple "=" characters' , ( ) => {
318325 const args = [ 'key1=part1=part2' ] ;
319- const expectedMap = { key1 : 'part1=part2' } ;
326+ const expectedMap = { key1 : [ 'part1=part2' ] } ;
320327
321328 const resultMap = argsToMap ( args ) ;
322329
0 commit comments