5
5
6
6
'use strict'
7
7
const tap = require ( 'tap' )
8
- const { grabLastUrlSegment } = require ( '../../lib/util' )
8
+ const { grabLastUrlSegment, setDynamoParameters } = require ( '../../lib/util' )
9
9
tap . test ( 'Utility Functions' , ( t ) => {
10
10
t . ok ( grabLastUrlSegment , 'imported function successfully' )
11
11
@@ -30,7 +30,61 @@ tap.test('Utility Functions', (t) => {
30
30
31
31
for ( const [ , fixture ] of fixtures . entries ( ) ) {
32
32
const result = grabLastUrlSegment ( fixture . input )
33
- t . equals ( result , fixture . output , `expecting ${ result } to equal ${ fixture . output } ` )
33
+ t . equal ( result , fixture . output , `expecting ${ result } to equal ${ fixture . output } ` )
34
34
}
35
35
t . end ( )
36
36
} )
37
+
38
+ tap . test ( 'DB parameters' , ( t ) => {
39
+ t . autoend ( )
40
+
41
+ t . test ( 'default values' , ( t ) => {
42
+ const input = { }
43
+ const endpoint = { }
44
+ const result = setDynamoParameters ( endpoint , input )
45
+ t . same (
46
+ result ,
47
+ {
48
+ host : undefined ,
49
+ port_path_or_id : 443 ,
50
+ collection : 'Unknown'
51
+ } ,
52
+ 'should set default values for parameters'
53
+ )
54
+ t . end ( )
55
+ } )
56
+
57
+ // v2 uses host key
58
+ t . test ( 'host, port, collection' , ( t ) => {
59
+ const input = { TableName : 'unit-test' }
60
+ const endpoint = { host : 'unit-test-host' , port : '123' }
61
+ const result = setDynamoParameters ( endpoint , input )
62
+ t . same (
63
+ result ,
64
+ {
65
+ host : endpoint . host ,
66
+ port_path_or_id : endpoint . port ,
67
+ collection : input . TableName
68
+ } ,
69
+ 'should set appropriate parameters'
70
+ )
71
+ t . end ( )
72
+ } )
73
+
74
+ // v3 uses hostname key
75
+ t . test ( 'hostname, port, collection' , ( t ) => {
76
+ const input = { TableName : 'unit-test' }
77
+ const endpoint = { hostname : 'unit-test-host' , port : '123' }
78
+ const result = setDynamoParameters ( endpoint , input )
79
+ t . same (
80
+ result ,
81
+ {
82
+ host : endpoint . hostname ,
83
+ port_path_or_id : endpoint . port ,
84
+ collection : input . TableName
85
+ } ,
86
+ 'should set appropriate parameters'
87
+ )
88
+ t . end ( )
89
+ } )
90
+ } )
0 commit comments