@@ -110,4 +110,40 @@ describe(EndpointCache.name, () => {
110
110
} ) ;
111
111
} ) ;
112
112
} ) ;
113
+
114
+ describe ( "set" , ( ) => {
115
+ let endpointCache ;
116
+ const key = "key" ;
117
+
118
+ beforeEach ( ( ) => {
119
+ jest . spyOn ( Date , "now" ) . mockImplementation ( ( ) => now ) ;
120
+ endpointCache = new EndpointCache ( 100 ) ;
121
+ } ) ;
122
+
123
+ it ( "converts CachePeriodInMinutes to Expires before caching" , ( ) => {
124
+ endpointCache . set ( key , mockEndpoints ) ;
125
+ expect ( set ) . toHaveBeenCalledTimes ( 1 ) ;
126
+ expect ( set ) . toHaveBeenCalledWith (
127
+ key ,
128
+ mockEndpoints . map ( ( { Address, CachePeriodInMinutes } ) => ( {
129
+ Address,
130
+ Expires : now + CachePeriodInMinutes * 60 * 1000 ,
131
+ } ) )
132
+ ) ;
133
+ } ) ;
134
+
135
+ it ( "sets Address to empty string if not passed" , ( ) => {
136
+ const mockEnpointsNoAddr = [ { CachePeriodInMinutes : 1 } ] ;
137
+ endpointCache . set ( key , mockEnpointsNoAddr ) ;
138
+ expect ( set ) . toHaveBeenCalledTimes ( 1 ) ;
139
+ expect ( set ) . toHaveBeenCalledWith ( key , [ { Address : "" , Expires : now + 60 * 1000 } ] ) ;
140
+ } ) ;
141
+
142
+ it ( "sets Expires in one minute if CachePeriodInMinutes is not passed" , ( ) => {
143
+ const mockEnpointsNoAddr = [ { Address : "address" } ] ;
144
+ endpointCache . set ( key , mockEnpointsNoAddr ) ;
145
+ expect ( set ) . toHaveBeenCalledTimes ( 1 ) ;
146
+ expect ( set ) . toHaveBeenCalledWith ( key , [ { Address : "address" , Expires : now + 60 * 1000 } ] ) ;
147
+ } ) ;
148
+ } ) ;
113
149
} ) ;
0 commit comments