@@ -19,20 +19,20 @@ describe('Unit | Infrastructure | temporary-storage | InMemoryTemporaryStorage',
19
19
clock . restore ( ) ;
20
20
} ) ;
21
21
22
- it ( 'should resolve with the generated key' , function ( ) {
22
+ it ( 'should resolve with the generated key' , async function ( ) {
23
23
// when
24
- const key = inMemoryTemporaryStorage . save ( { value : { } , expirationDelaySeconds : 1000 } ) ;
24
+ const key = await inMemoryTemporaryStorage . save ( { value : { } , expirationDelaySeconds : 1000 } ) ;
25
25
26
26
// then
27
- expect ( key ) . to . exist ;
27
+ expect ( key ) . to . be . a . string ;
28
28
} ) ;
29
29
30
- it ( 'should return a key from passed key parameter if valid' , function ( ) {
30
+ it ( 'should return a key from passed key parameter if valid' , async function ( ) {
31
31
// given
32
32
const keyParameter = 'KEY-PARAMETER' ;
33
33
34
34
// when
35
- const returnedKey = inMemoryTemporaryStorage . save ( {
35
+ const returnedKey = await inMemoryTemporaryStorage . save ( {
36
36
key : keyParameter ,
37
37
value : { } ,
38
38
expirationDelaySeconds : 1000 ,
@@ -42,12 +42,12 @@ describe('Unit | Infrastructure | temporary-storage | InMemoryTemporaryStorage',
42
42
expect ( returnedKey ) . to . be . equal ( keyParameter ) ;
43
43
} ) ;
44
44
45
- it ( 'should return a generated key if key parameter is not valid' , function ( ) {
45
+ it ( 'should return a generated key if key parameter is not valid' , async function ( ) {
46
46
// given
47
47
const keyParameter = ' ' ;
48
48
49
49
// when
50
- const returnedKey = inMemoryTemporaryStorage . save ( {
50
+ const returnedKey = await inMemoryTemporaryStorage . save ( {
51
51
key : keyParameter ,
52
52
value : { } ,
53
53
expirationDelaySeconds : 1000 ,
@@ -57,87 +57,87 @@ describe('Unit | Infrastructure | temporary-storage | InMemoryTemporaryStorage',
57
57
expect ( returnedKey ) . not . be . equal ( keyParameter ) ;
58
58
} ) ;
59
59
60
- it ( 'should save key value with a defined ttl in seconds' , function ( ) {
60
+ it ( 'should save key value with a defined ttl in seconds' , async function ( ) {
61
61
// given
62
62
const TWO_MINUTES_IN_SECONDS = 2 * 60 ;
63
63
const TWO_MINUTES_IN_MILLISECONDS = 2 * 60 * 1000 ;
64
64
65
65
// when
66
- const key = inMemoryTemporaryStorage . save ( {
66
+ const key = await inMemoryTemporaryStorage . save ( {
67
67
value : { name : 'name' } ,
68
68
expirationDelaySeconds : TWO_MINUTES_IN_SECONDS ,
69
69
} ) ;
70
70
71
71
// then
72
- const expirationKeyInTimestamp = inMemoryTemporaryStorage . _client . getTtl ( key ) ;
72
+ const expirationKeyInTimestamp = await inMemoryTemporaryStorage . _client . getTtl ( key ) ;
73
73
expect ( expirationKeyInTimestamp ) . to . equal ( TWO_MINUTES_IN_MILLISECONDS ) ;
74
74
} ) ;
75
75
} ) ;
76
76
77
77
describe ( '#get' , function ( ) {
78
- it ( 'should retrieve the value if it exists' , function ( ) {
78
+ it ( 'should retrieve the value if it exists' , async function ( ) {
79
79
// given
80
80
const value = { name : 'name' } ;
81
81
const expirationDelaySeconds = 1000 ;
82
82
83
- const key = inMemoryTemporaryStorage . save ( { value, expirationDelaySeconds } ) ;
83
+ const key = await inMemoryTemporaryStorage . save ( { value, expirationDelaySeconds } ) ;
84
84
85
85
// when
86
- const result = inMemoryTemporaryStorage . get ( key ) ;
86
+ const result = await inMemoryTemporaryStorage . get ( key ) ;
87
87
88
88
// then
89
89
expect ( result ) . to . deep . equal ( value ) ;
90
90
} ) ;
91
91
} ) ;
92
92
93
93
describe ( '#update' , function ( ) {
94
- it ( 'should set a new value' , function ( ) {
94
+ it ( 'should set a new value' , async function ( ) {
95
95
// given
96
- const key = inMemoryTemporaryStorage . save ( {
96
+ const key = await inMemoryTemporaryStorage . save ( {
97
97
value : { name : 'name' } ,
98
98
} ) ;
99
99
100
100
// when
101
- inMemoryTemporaryStorage . update ( key , { url : 'url' } ) ;
101
+ await inMemoryTemporaryStorage . update ( key , { url : 'url' } ) ;
102
102
103
103
// then
104
- const result = inMemoryTemporaryStorage . get ( key ) ;
104
+ const result = await inMemoryTemporaryStorage . get ( key ) ;
105
105
expect ( result ) . to . deep . equal ( { url : 'url' } ) ;
106
106
} ) ;
107
107
108
108
it ( 'should not change the time to live' , async function ( ) {
109
109
// given
110
- const keyWithTtl = inMemoryTemporaryStorage . save ( {
110
+ const keyWithTtl = await inMemoryTemporaryStorage . save ( {
111
111
value : { } ,
112
112
expirationDelaySeconds : 1 ,
113
113
} ) ;
114
- const keyWithoutTtl = inMemoryTemporaryStorage . save ( { value : { } } ) ;
114
+ const keyWithoutTtl = await inMemoryTemporaryStorage . save ( { value : { } } ) ;
115
115
116
116
// when
117
117
await new Promise ( ( resolve ) => setTimeout ( resolve , 500 ) ) ;
118
- inMemoryTemporaryStorage . update ( keyWithTtl , { } ) ;
119
- inMemoryTemporaryStorage . update ( keyWithoutTtl , { } ) ;
118
+ await inMemoryTemporaryStorage . update ( keyWithTtl , { } ) ;
119
+ await inMemoryTemporaryStorage . update ( keyWithoutTtl , { } ) ;
120
120
await new Promise ( ( resolve ) => setTimeout ( resolve , 600 ) ) ;
121
121
122
122
// then
123
- expect ( inMemoryTemporaryStorage . get ( keyWithTtl ) ) . to . be . undefined ;
124
- expect ( inMemoryTemporaryStorage . get ( keyWithoutTtl ) ) . not . to . be . undefined ;
123
+ expect ( await inMemoryTemporaryStorage . get ( keyWithTtl ) ) . to . be . undefined ;
124
+ expect ( await inMemoryTemporaryStorage . get ( keyWithoutTtl ) ) . not . to . be . undefined ;
125
125
} ) ;
126
126
} ) ;
127
127
128
128
describe ( '#delete' , function ( ) {
129
- it ( 'should delete the value if it exists' , function ( ) {
129
+ it ( 'should delete the value if it exists' , async function ( ) {
130
130
// given
131
131
const value = { name : 'name' } ;
132
132
const expirationDelaySeconds = 1000 ;
133
133
134
- const key = inMemoryTemporaryStorage . save ( { value, expirationDelaySeconds } ) ;
134
+ const key = await inMemoryTemporaryStorage . save ( { value, expirationDelaySeconds } ) ;
135
135
136
136
// when
137
- inMemoryTemporaryStorage . delete ( key ) ;
137
+ await inMemoryTemporaryStorage . delete ( key ) ;
138
138
139
139
// then
140
- const savedKey = inMemoryTemporaryStorage . get ( key ) ;
140
+ const savedKey = await inMemoryTemporaryStorage . get ( key ) ;
141
141
expect ( savedKey ) . to . be . undefined ;
142
142
} ) ;
143
143
} ) ;
@@ -168,7 +168,7 @@ describe('Unit | Infrastructure | temporary-storage | InMemoryTemporaryStorage',
168
168
const key = 'key:lpush' ;
169
169
await inMemoryTemporaryStorage . lpush ( key , 'value' ) ;
170
170
await inMemoryTemporaryStorage . expire ( { key, expirationDelaySeconds : 120 } ) ;
171
- const remainingExpirationSeconds = inMemoryTemporaryStorage . ttl ( key ) ;
171
+ const remainingExpirationSeconds = await inMemoryTemporaryStorage . ttl ( key ) ;
172
172
173
173
// then
174
174
expect ( remainingExpirationSeconds ) . to . be . above ( Date . now ( ) ) ;
0 commit comments