@@ -14,6 +14,18 @@ const mockedKVs = [{
14
14
} , {
15
15
key : "app.settings.fontSize" ,
16
16
value : "40" ,
17
+ } , {
18
+ key : "app/settings/fontColor" ,
19
+ value : "red" ,
20
+ } , {
21
+ key : "app/settings/fontSize" ,
22
+ value : "40" ,
23
+ } , {
24
+ key : "app%settings%fontColor" ,
25
+ value : "red" ,
26
+ } , {
27
+ key : "app%settings%fontSize" ,
28
+ value : "40" ,
17
29
} , {
18
30
key : "TestKey" ,
19
31
label : "Test" ,
@@ -50,7 +62,7 @@ const mockedKVs = [{
50
62
} , {
51
63
key : "app5.settings" ,
52
64
value : "placeholder"
53
- } ,
65
+ }
54
66
] . map ( createMockedKeyValue ) ;
55
67
56
68
describe ( "load" , function ( ) {
@@ -287,4 +299,36 @@ describe("load", function () {
287
299
expect ( data . app4 . excludedFolders [ 0 ] ) . eq ( "node_modules" ) ;
288
300
expect ( data . app4 . excludedFolders [ 1 ] ) . eq ( "dist" ) ;
289
301
} ) ;
302
+
303
+ it ( "should construct configuration object with customized separator" , async ( ) => {
304
+ const connectionString = createMockedConnectionString ( ) ;
305
+ const settings = await load ( connectionString , {
306
+ selectors : [ {
307
+ keyFilter : "app/settings/*"
308
+ } ]
309
+ } ) ;
310
+ expect ( settings ) . not . undefined ;
311
+ const data = settings . constructConfigurationObject ( { separator : "/" } ) ;
312
+ expect ( data ) . not . undefined ;
313
+ expect ( data . app . settings . fontColor ) . eq ( "red" ) ;
314
+ expect ( data . app . settings . fontSize ) . eq ( "40" ) ;
315
+ } ) ;
316
+
317
+ it ( "should throw error when construct configuration object with invalid separator" , async ( ) => {
318
+ const connectionString = createMockedConnectionString ( ) ;
319
+ const settings = await load ( connectionString , {
320
+ selectors : [ {
321
+ keyFilter : "app%settings%*"
322
+ } ]
323
+ } ) ;
324
+ expect ( settings ) . not . undefined ;
325
+
326
+ expect ( ( ) => {
327
+ // Below line will throw error because of type checking, i.e. Type '"%"' is not assignable to type '"/" | "." | "," | ";" | "-" | "_" | "__" | ":" | undefined'.ts(2322)
328
+ // Here force to turn if off for testing purpose, as JavaScript does not have type checking.
329
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
330
+ // @ts -ignore
331
+ settings . constructConfigurationObject ( { separator : "%" } ) ;
332
+ } ) . to . throw ( "Invalid separator '%'. Supported values: '.', ',', ';', '-', '_', '__', '/', ':'." ) ;
333
+ } ) ;
290
334
} ) ;
0 commit comments