@@ -61,61 +61,47 @@ describe('redis', function() {
61
61
} ) ;
62
62
63
63
it ( 'updates the list of recent uploads once upload is successful' , function ( ) {
64
- var recentUploads = [ ] ;
65
-
66
64
var redis = new Redis ( { } , new FakeRedis ( FakeClient . extend ( {
67
65
get : function ( key ) {
68
66
return Promise . resolve ( null ) ;
69
- } ,
70
- zadd : function ( key , score , tag ) {
71
- recentUploads . push ( key + tag ) ;
72
67
}
73
68
} ) ) ) ;
74
69
75
70
var promise = redis . upload ( 'key' , 'value' ) ;
76
71
return assert . isFulfilled ( promise )
77
72
. then ( function ( ) {
78
- assert . equal ( recentUploads . length , 1 ) ;
79
- assert . equal ( recentUploads [ 0 ] , 'keydefault ' ) ;
73
+ assert . equal ( redis . _client . recentRevisions . length , 1 ) ;
74
+ assert . equal ( redis . _client . recentRevisions [ 0 ] , 'key:default ' ) ;
80
75
} ) ;
81
76
} ) ;
82
77
83
78
it ( 'trims the list of recent uploads and removes the index key' , function ( ) {
84
- var recentUploads = [ '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '10' , '11' ] ;
85
- var finalUploads = [ '3' , '4' , '5' , '6' , '7' , '8' , '9' , '10' , '11' , '12' ] ;
79
+ var finalUploads = [ '3' , '4' , '5' , '6' , '7' , '8' , '9' , '10' , '11' , 'key:12' ] ;
86
80
87
81
var redis = new Redis ( { } , new FakeRedis ( FakeClient . extend ( {
88
82
get : function ( key ) {
89
83
return Promise . resolve ( null ) ;
90
84
} ,
91
- set : function ( key , value ) {
92
- } ,
93
- zadd : function ( key , score , revisionKey ) {
94
- recentUploads . push ( revisionKey ) ;
95
- } ,
96
- zrem : function ( val , revision ) {
97
- var i = recentUploads . indexOf ( revision )
98
- recentUploads . splice ( i , 1 ) ;
99
- } ,
100
- zrange : function ( ) {
101
- return recentUploads . slice ( 0 , 2 ) ;
102
- } ,
103
85
del : function ( key ) {
104
86
assert ( key === 'key:1' || key === 'key:2' ) ;
87
+ } ,
88
+ zrange : function ( ) {
89
+ return this . recentRevisions . slice ( 0 , 2 ) ;
105
90
}
106
91
} ) ) ) ;
107
92
93
+ redis . _client . recentRevisions = [ '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '10' , '11' ] ;
94
+
108
95
var promise = redis . upload ( 'key' , '12' , 'value' ) ;
109
96
return assert . isFulfilled ( promise )
110
97
. then ( function ( ) {
111
- assert . equal ( recentUploads . length , 10 ) ;
112
- assert . deepEqual ( recentUploads , finalUploads ) ;
98
+ assert . equal ( redis . _client . recentRevisions . length , 10 ) ;
99
+ assert . deepEqual ( redis . _client . recentRevisions , finalUploads ) ;
113
100
} ) ;
114
101
} ) ;
115
102
116
103
it ( 'trims the list of recent uploads but leaves the active one' , function ( ) {
117
- var recentUploads = [ '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '10' , '11' ] ;
118
- var finalUploads = [ '1' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '10' , '11' , '12' ] ;
104
+ var finalUploads = [ '1' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '10' , '11' , 'key:12' ] ;
119
105
120
106
var redis = new Redis ( { } , new FakeRedis ( FakeClient . extend ( {
121
107
get : function ( key ) {
@@ -124,27 +110,18 @@ describe('redis', function() {
124
110
}
125
111
return Promise . resolve ( null ) ;
126
112
} ,
127
- set : function ( key , value ) {
128
- } ,
129
- zadd : function ( key , score , revisionKey ) {
130
- recentUploads . push ( revisionKey ) ;
131
- } ,
132
- zrem : function ( val , revision ) {
133
- var i = recentUploads . indexOf ( revision )
134
- recentUploads . splice ( i , 1 ) ;
135
- } ,
136
113
zrange : function ( ) {
137
- return recentUploads . slice ( 0 , 2 ) ;
138
- } ,
139
- del : function ( key ) {
114
+ return this . recentRevisions . slice ( 0 , 2 ) ;
140
115
}
141
116
} ) ) ) ;
142
117
118
+ redis . _client . recentRevisions = [ '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '10' , '11' ] ;
119
+
143
120
var promise = redis . upload ( 'key' , '12' , 'value' ) ;
144
121
return assert . isFulfilled ( promise )
145
122
. then ( function ( ) {
146
- assert . equal ( recentUploads . length , 11 ) ;
147
- assert . deepEqual ( recentUploads , finalUploads ) ;
123
+ assert . equal ( redis . _client . recentRevisions . length , 11 ) ;
124
+ assert . deepEqual ( redis . _client . recentRevisions , finalUploads ) ;
148
125
} ) ;
149
126
} ) ;
150
127
@@ -186,14 +163,14 @@ describe('redis', function() {
186
163
187
164
describe ( '#activate' , function ( ) {
188
165
it ( 'rejects if the revisionKey doesn\t exist in list of uploaded revisions' , function ( ) {
189
- var recentRevisions = [ 'a' , 'b' , 'c' ] ;
190
-
191
166
var redis = new Redis ( { } , new FakeRedis ( FakeClient . extend ( {
192
167
zrevrange : function ( ) {
193
- return recentRevisions ;
168
+ return this . recentRevisions ;
194
169
}
195
170
} ) ) ) ;
196
171
172
+ redis . _client . recentRevisions = [ 'a' , 'b' , 'c' ] ;
173
+
197
174
var promise = redis . activate ( 'key-prefix' , 'revision-key' ) ;
198
175
return assert . isRejected ( promise )
199
176
. then ( function ( error ) {
@@ -202,20 +179,17 @@ describe('redis', function() {
202
179
} ) ;
203
180
204
181
it ( 'resolves and sets the current revision to the revision key provided' , function ( ) {
205
- var recentRevisions = [ 'a' , 'b' , 'c' ] ;
206
182
var redisKey , redisValue ;
207
183
208
-
209
184
var redis = new Redis ( { } , new FakeRedis ( FakeClient . extend ( {
210
- zrevrange : function ( ) {
211
- return recentRevisions ;
212
- } ,
213
185
set : function ( key , value ) {
214
186
redisKey = key ;
215
187
redisValue = value ;
216
188
}
217
189
} ) ) ) ;
218
190
191
+ redis . _client . recentRevisions = [ 'a' , 'b' , 'c' ] ;
192
+
219
193
var promise = redis . activate ( 'key-prefix' , 'c' ) ;
220
194
return assert . isFulfilled ( promise )
221
195
. then ( function ( ) {
@@ -227,14 +201,11 @@ describe('redis', function() {
227
201
228
202
describe ( '#fetchRevisions' , function ( ) {
229
203
it ( 'lists the last existing revisions' , function ( ) {
230
- var recentRevisions = [ 'a' , 'b' , 'c' ] ;
231
-
232
204
var redis = new Redis ( { } , new FakeRedis ( FakeClient . extend ( {
233
- zrevrange : function ( ) {
234
- return recentRevisions ;
235
- }
236
205
} ) ) ) ;
237
206
207
+ redis . _client . recentRevisions = [ 'a' , 'b' , 'c' ] ;
208
+
238
209
var promise = redis . fetchRevisions ( 'key-prefix' ) ;
239
210
return assert . isFulfilled ( promise )
240
211
. then ( function ( result ) {
@@ -257,18 +228,16 @@ describe('redis', function() {
257
228
} ) ;
258
229
259
230
it ( 'lists revisions and marks the active one' , function ( ) {
260
- var recentRevisions = [ 'a' , 'b' ] ;
261
231
var currentRevision = 'b' ;
262
232
263
233
var redis = new Redis ( { } , new FakeRedis ( FakeClient . extend ( {
264
- zrevrange : function ( ) {
265
- return recentRevisions ;
266
- } ,
267
234
get : function ( ) {
268
235
return currentRevision ;
269
236
}
270
237
} ) ) ) ;
271
238
239
+ redis . _client . recentRevisions = [ 'a' , 'b' ] ;
240
+
272
241
var promise = redis . fetchRevisions ( 'key-prefix' ) ;
273
242
return assert . isFulfilled ( promise )
274
243
. then ( function ( result ) {
0 commit comments