@@ -78,164 +78,91 @@ describe('redis-index-adpater', function(){
78
78
} ) ;
79
79
80
80
describe ( '#upload' , function ( ) {
81
- it ( 'proceeds if index is uploaded and returns the key' , function ( ) {
82
- adapterOptions . _uploadIfNotInVersionList = succeeded ;
83
- adapterOptions . _updateVersionList = succeeded ;
84
- adapterOptions . _trimVersionList = succeeded ;
81
+ it ( 'rejects if the version is already uploaded' , function ( ) {
82
+ mockClient . set ( 'aaa' , 'data' ) ;
83
+ mockClient . lpush ( adapterOptions . appId , 'aaa' ) ;
85
84
86
85
var subject = new Adapter ( adapterOptions ) ;
87
86
88
- return subject . upload ( 'data' )
89
- . then ( function ( key ) {
90
- assert . ok ( / [ 0 - 9 a - f ] { 10 } / . test ( key ) ) ;
91
- } , function ( error ) {
92
- assert . ok ( false , 'Should have resolved upload' ) ;
93
- } ) ;
94
- } ) ;
95
-
96
- it ( 'rejects if index is not uploaded' , function ( ) {
97
- adapterOptions . _uploadIfNotInVersionList = failed ;
98
- adapterOptions . _updateVersionList = succeeded ;
99
- adapterOptions . _trimVersionList = succeeded ;
100
-
101
- var subject = new Adapter ( adapterOptions ) ;
87
+ subject . _key = function ( ) {
88
+ return 'aaa' ;
89
+ } ;
102
90
103
91
return subject . upload ( 'data' )
104
92
. then ( function ( ) {
105
- assert . ok ( false , 'Should have rejected upload ' ) ;
93
+ assert . ok ( false , 'Should have rejected due to version already being uploaded ' ) ;
106
94
} , function ( error ) {
107
- assert . equal ( error , 'failed ' ) ;
95
+ assert . equal ( error . message , 'Version for key [aaa] has already been uploaded\n ' ) ;
108
96
} ) ;
109
97
} ) ;
110
98
111
- it ( 'rejects if version list is not updated' , function ( ) {
112
- adapterOptions . _uploadIfNotInVersionList = succeeded ;
113
- adapterOptions . _updateVersionList = failed ;
114
- adapterOptions . _trimVersionList = succeeded ;
115
-
99
+ it ( 'maintains the version list to be at the specified number of versions' , function ( ) {
100
+ for ( var i = 0 ; i < 4 ; i ++ ) {
101
+ mockClient . lpush ( adapterOptions . appId , 'version-' + i ) ;
102
+ }
116
103
var subject = new Adapter ( adapterOptions ) ;
117
104
118
- return subject . upload ( 'data' )
119
- . then ( function ( ) {
120
- assert . ok ( false , 'Should have rejected upload' ) ;
121
- } , function ( error ) {
122
- assert . equal ( error , 'failed' ) ;
123
- } ) ;
124
- } ) ;
125
-
126
- it ( 'rejects if version list is not trimmed' , function ( ) {
127
- adapterOptions . _uploadIfNotInVersionList = succeeded ;
128
- adapterOptions . _updateVersionList = succeeded ;
129
- adapterOptions . _trimVersionList = failed ;
105
+ subject . _key = function ( ) {
106
+ return 'aaa' ;
107
+ } ;
130
108
131
- var subject = new Adapter ( adapterOptions ) ;
109
+ assert . equal ( mockClient . get ( adapterOptions . appId ) . indexOf ( 'aaa' ) , - 1 ) ;
132
110
133
111
return subject . upload ( 'data' )
134
112
. then ( function ( ) {
135
- assert . ok ( false , 'Should have rejected upload' ) ;
113
+ assert . equal ( mockClient . get ( adapterOptions . appId ) . length , 4 ) ;
114
+ assert . equal ( mockClient . get ( adapterOptions . appId ) [ 0 ] , 'aaa' ) ;
136
115
} , function ( error ) {
137
- assert . equal ( error , 'failed ' ) ;
116
+ assert . ok ( false , 'Should have resolved ' ) ;
138
117
} ) ;
139
118
} ) ;
140
- } ) ;
141
119
142
- describe ( '#_key' , function ( ) {
143
- it ( 'returns the current git hash' , function ( ) {
120
+ it ( 'returns the key for which the data was uploaded' , function ( ) {
144
121
var subject = new Adapter ( adapterOptions ) ;
145
122
146
- var sha = subject . _key ( ) ;
123
+ subject . _key = function ( ) {
124
+ return 'aaa' ;
125
+ } ;
147
126
148
- assert . ok ( / [ 0 - 9 a - f ] { 10 } / . test ( sha ) , 'Should return hash' ) ;
149
- } ) ;
150
- } ) ;
151
-
152
- describe ( '#_uploadIfNotInVersionList' , function ( ) {
153
- it ( 'resolves on a successful upload' , function ( ) {
154
- var subject = new Adapter ( adapterOptions ) ;
155
-
156
- return subject . _uploadIfNotInVersionList ( 'new-key' , 'value' )
157
- . then ( function ( ) {
158
- assert . equal ( mockClient . key , 'my-app:new-key' ) ;
159
- assert . equal ( mockClient . value , 'value' ) ;
127
+ return subject . upload ( 'data' )
128
+ . then ( function ( key ) {
129
+ assert . equal ( key , 'aaa' ) ;
160
130
} , function ( ) {
161
- assert . ok ( false , 'Should have uploaded successfully' ) ;
162
- } ) ;
163
- } ) ;
164
-
165
- it ( 'rejects if a version already exists for the current git sha' , function ( ) {
166
- var subject = new Adapter ( adapterOptions ) ;
167
-
168
- return subject . _uploadIfNotInVersionList ( 'key' , 'value' )
169
- . then ( function ( ) {
170
- assert . ok ( false , 'Should have rejected due to version already being uploaded' ) ;
171
- } , function ( error ) {
172
- assert . equal ( error . message , 'Version for key [key] has already been uploaded\n' ) ;
131
+ assert . ok ( false , 'Should have resolved with upload key' ) ;
173
132
} ) ;
174
133
} ) ;
175
134
} ) ;
176
135
177
- describe ( '#_updateVersionList ' , function ( ) {
178
- it ( 'resolves on a successful update ' , function ( ) {
136
+ describe ( '#setCurrent ' , function ( ) {
137
+ it ( 'rejects if the version has not been previously uploaded ' , function ( ) {
179
138
var subject = new Adapter ( adapterOptions ) ;
180
139
181
- return subject . _updateVersionList ( 'new-key ')
140
+ return subject . setCurrent ( 'aaa ')
182
141
. then ( function ( ) {
183
- assert . equal ( mockClient . appId , 'my-app' ) ;
184
- assert . equal ( mockClient . key , 'new-key' ) ;
185
- } , function ( ) {
186
- assert . ok ( false , 'Should have updated versions successfully' ) ;
187
- } ) ;
188
- } ) ;
189
-
190
- it ( 'rejects if a version already exists for the current git sha' , function ( ) {
191
- var subject = new Adapter ( adapterOptions ) ;
192
-
193
- return subject . _updateVersionList ( 'key' )
194
- . then ( function ( ) {
195
- assert . ok ( false , 'Should have rejected due to version already being in version list' ) ;
142
+ assert . ok ( false , 'Should have rejected' ) ;
196
143
} , function ( error ) {
197
- assert . equal ( error . message , 'Version for key [key] has already been uploaded\n' ) ;
198
- } ) ;
199
- } ) ;
200
- } ) ;
201
-
202
- describe ( '#_trimVersions' , function ( ) {
203
- it ( 'resolves on a successful call' , function ( ) {
204
- adapterOptions . versionCount = 5 ;
205
-
206
- var subject = new Adapter ( adapterOptions ) ;
207
-
208
- return subject . _trimVersionList ( )
209
- . then ( function ( ) {
210
- assert . equal ( mockClient . appId , 'my-app' ) ;
211
- assert . equal ( mockClient . min , 0 ) ;
212
- assert . equal ( mockClient . max , 4 ) ;
213
- } , function ( ) {
214
- assert . ok ( false , 'Should have trimmed the version list successfully' ) ;
144
+ assert . equal ( error . message , 'Version for key [aaa] does not exist\n' ) ;
145
+ var currentKey = mockClient . get ( adapterOptions . appId + ':current' ) ;
146
+ assert . equal ( currentKey , null ) ;
215
147
} ) ;
216
148
} ) ;
217
- } ) ;
218
149
219
- describe ( '#_listVersions' , function ( ) {
220
- it ( 'returns the number of versions specified' , function ( ) {
150
+ it ( 'sets the specified version as the current version' , function ( ) {
221
151
var subject = new Adapter ( adapterOptions ) ;
222
152
223
- return subject . _listVersions ( 3 )
224
- . then ( function ( result ) {
225
- assert . equal ( result . length , 3 ) ;
226
- } , function ( ) {
227
- assert . ok ( false , 'Should have returned specified number of versions' ) ;
228
- } ) ;
229
- } ) ;
230
-
231
- it ( 'returns the default number of versions when count not specified' , function ( ) {
232
- var subject = new Adapter ( adapterOptions ) ;
153
+ subject . _key = function ( ) {
154
+ return 'aaa' ;
155
+ } ;
233
156
234
- return subject . _listVersions ( )
235
- . then ( function ( result ) {
236
- assert . equal ( result . length , 4 ) ;
237
- } , function ( ) {
238
- assert . ok ( false , 'Should have returned specified number of versions' ) ;
157
+ return subject . upload ( 'data' )
158
+ . then ( function ( key ) {
159
+ return subject . setCurrent ( key )
160
+ . then ( function ( ) {
161
+ var currentKey = mockClient . get ( adapterOptions . appId + ':current' ) ;
162
+ assert . equal ( currentKey , key ) ;
163
+ } , function ( ) {
164
+ assert . ok ( false , 'Should have resolved' ) ;
165
+ } ) ;
239
166
} ) ;
240
167
} ) ;
241
168
} ) ;
0 commit comments