@@ -6,6 +6,10 @@ import { EndpointCache } from "./EndpointCache";
6
6
jest . mock ( "mnemonist" ) ;
7
7
8
8
describe ( EndpointCache . name , ( ) => {
9
+ let endpointCache ;
10
+ const capacity = 100 ;
11
+ const key = "key" ;
12
+
9
13
const now = Date . now ( ) ;
10
14
const set = jest . fn ( ) ;
11
15
const get = jest . fn ( ) ;
@@ -33,28 +37,23 @@ describe(EndpointCache.name, () => {
33
37
has,
34
38
clear,
35
39
} ) ;
40
+ endpointCache = new EndpointCache ( capacity ) ;
36
41
} ) ;
37
42
38
43
afterEach ( ( ) => {
39
44
jest . clearAllMocks ( ) ;
40
45
} ) ;
41
46
42
47
it ( "passes capacity to LRUCache" , ( ) => {
43
- const capacity = 100 ;
44
- new EndpointCache ( capacity ) ;
45
48
expect ( LRUCache ) . toHaveBeenCalledTimes ( 1 ) ;
46
49
expect ( LRUCache ) . toHaveBeenCalledWith ( capacity ) ;
47
50
} ) ;
48
51
49
52
describe ( "get" , ( ) => {
50
- let endpointCache ;
51
- const key = "key" ;
52
-
53
53
beforeEach ( ( ) => {
54
54
has . mockReturnValue ( true ) ;
55
55
get . mockReturnValue ( getEndpointsWithExpiry ( mockEndpoints ) ) ;
56
56
jest . spyOn ( Date , "now" ) . mockImplementation ( ( ) => now ) ;
57
- endpointCache = new EndpointCache ( 100 ) ;
58
57
} ) ;
59
58
60
59
const verifyHasAndGetCalls = ( ) => {
@@ -112,12 +111,8 @@ describe(EndpointCache.name, () => {
112
111
} ) ;
113
112
114
113
describe ( "set" , ( ) => {
115
- let endpointCache ;
116
- const key = "key" ;
117
-
118
114
beforeEach ( ( ) => {
119
115
jest . spyOn ( Date , "now" ) . mockImplementation ( ( ) => now ) ;
120
- endpointCache = new EndpointCache ( 100 ) ;
121
116
} ) ;
122
117
123
118
it ( "converts CachePeriodInMinutes to Expires before caching" , ( ) => {
@@ -146,4 +141,21 @@ describe(EndpointCache.name, () => {
146
141
expect ( set ) . toHaveBeenCalledWith ( key , [ { Address : "address" , Expires : now + 60 * 1000 } ] ) ;
147
142
} ) ;
148
143
} ) ;
144
+
145
+ it ( "remove" , ( ) => {
146
+ endpointCache . remove ( key ) ;
147
+ expect ( set ) . toHaveBeenCalledTimes ( 1 ) ;
148
+ expect ( set ) . toHaveBeenCalledWith ( key , [ ] ) ;
149
+ } ) ;
150
+
151
+ it ( "has" , ( ) => {
152
+ endpointCache . has ( key ) ;
153
+ expect ( has ) . toHaveBeenCalledTimes ( 1 ) ;
154
+ expect ( has ) . toHaveBeenCalledWith ( key ) ;
155
+ } ) ;
156
+
157
+ it ( "clear" , ( ) => {
158
+ endpointCache . clear ( ) ;
159
+ expect ( clear ) . toHaveBeenCalledTimes ( 1 ) ;
160
+ } ) ;
149
161
} ) ;
0 commit comments