2
2
3
3
var Promise = require ( 'ember-cli/lib/ext/promise' ) ;
4
4
var assert = require ( 'ember-cli/tests/helpers/assert' ) ;
5
+ var CoreObject = require ( 'core-object' ) ;
5
6
6
7
describe ( 'redis' , function ( ) {
7
8
var Redis ;
@@ -10,23 +11,29 @@ describe('redis', function() {
10
11
Redis = require ( '../../../lib/redis' ) ;
11
12
} ) ;
12
13
13
- var fakeClient = {
14
+ var FakeClient = CoreObject . extend ( {
15
+ get : function ( key ) {
16
+ return Promise . resolve ( 'some-other-value' ) ;
17
+ } ,
18
+ set : function ( ) { } ,
19
+ lpush : function ( ) { } ,
20
+ ltrim : function ( ) { }
21
+ } ) ;
22
+
23
+ var FakeRedis = CoreObject . extend ( {
24
+ init : function ( clientClass ) {
25
+ this . clientClass = clientClass || FakeClient ;
26
+ } ,
27
+
14
28
createClient : function ( options ) {
15
29
this . options = options ;
16
- return {
17
- get : function ( key ) {
18
- return Promise . resolve ( 'some-other-value' ) ;
19
- } ,
20
- set : function ( ) { } ,
21
- lpush : function ( ) { } ,
22
- ltrim : function ( ) { }
23
- }
30
+ return new this . clientClass ( )
24
31
}
25
- } ;
32
+ } ) ;
26
33
27
34
describe ( '#upload' , function ( ) {
28
35
it ( 'rejects if the key already exists in redis' , function ( ) {
29
- var redis = new Redis ( { } , fakeClient ) ;
36
+ var redis = new Redis ( { } , new FakeRedis ( ) ) ;
30
37
31
38
var promise = redis . upload ( 'key' , 'value' ) ;
32
39
return assert . isRejected ( promise , / ^ V a l u e a l r e a d y e x i s t s f o r k e y : k e y : d e f a u l t $ / ) ;
@@ -35,18 +42,14 @@ describe('redis', function() {
35
42
it ( 'uploads the contents if the key does not already exist' , function ( ) {
36
43
var fileUploaded = false ;
37
44
38
- var redis = new Redis ( {
39
- redisClient : {
40
- get : function ( key ) {
41
- return Promise . resolve ( null ) ;
42
- } ,
43
- set : function ( key , value ) {
44
- fileUploaded = true ;
45
- } ,
46
- lpush : function ( ) { } ,
47
- ltrim : function ( ) { }
45
+ var redis = new Redis ( { } , new FakeRedis ( FakeClient . extend ( {
46
+ get : function ( key ) {
47
+ return Promise . resolve ( null ) ;
48
+ } ,
49
+ set : function ( key , value ) {
50
+ fileUploaded = true ;
48
51
}
49
- } ) ;
52
+ } ) ) ) ;
50
53
51
54
var promise = redis . upload ( 'key' , 'value' ) ;
52
55
return assert . isFulfilled ( promise )
@@ -59,18 +62,12 @@ describe('redis', function() {
59
62
var fileUploaded = false ;
60
63
61
64
var redis = new Redis ( {
62
- allowOverwrite : true ,
63
- redisClient : {
64
- get : function ( key ) {
65
- return Promise . resolve ( 'some-other-value' ) ;
66
- } ,
67
- set : function ( key , value ) {
68
- fileUploaded = true ;
69
- } ,
70
- lpush : function ( ) { } ,
71
- ltrim : function ( ) { }
65
+ allowOverwrite : true
66
+ } , new FakeRedis ( FakeClient . extend ( {
67
+ set : function ( key , value ) {
68
+ fileUploaded = true ;
72
69
}
73
- } ) ;
70
+ } ) ) ) ;
74
71
75
72
var promise = redis . upload ( 'key' , 'value' ) ;
76
73
return assert . isFulfilled ( promise )
@@ -82,19 +79,14 @@ describe('redis', function() {
82
79
it ( 'updates the list of recent uploads once upload is successful' , function ( ) {
83
80
var recentUploads = [ ] ;
84
81
85
- var redis = new Redis ( {
86
- redisClient : {
87
- get : function ( key ) {
88
- return Promise . resolve ( null ) ;
89
- } ,
90
- set : function ( key , value ) {
91
- } ,
92
- lpush : function ( key , tag ) {
93
- recentUploads . push ( key + tag ) ;
94
- } ,
95
- ltrim : function ( ) { }
96
- }
97
- } ) ;
82
+ var redis = new Redis ( { } , new FakeRedis ( FakeClient . extend ( {
83
+ get : function ( key ) {
84
+ return Promise . resolve ( null ) ;
85
+ } ,
86
+ lpush : function ( key , tag ) {
87
+ recentUploads . push ( key + tag ) ;
88
+ } ,
89
+ } ) ) ) ;
98
90
99
91
var promise = redis . upload ( 'key' , 'value' ) ;
100
92
return assert . isFulfilled ( promise )
@@ -107,21 +99,17 @@ describe('redis', function() {
107
99
it ( 'trims the list of recent uploads' , function ( ) {
108
100
var recentUploads = [ 'a' , 'b' , 'c' ] ;
109
101
110
- var redis = new Redis ( {
111
- redisClient : {
112
- get : function ( key ) {
113
- return Promise . resolve ( null ) ;
114
- } ,
115
- set : function ( key , value ) {
116
- } ,
117
- lpush : function ( key , tag ) {
118
- recentUploads . push ( key + tag ) ;
119
- } ,
120
- ltrim : function ( ) {
121
- recentUploads . pop ( ) ;
122
- }
102
+ var redis = new Redis ( { } , new FakeRedis ( FakeClient . extend ( {
103
+ get : function ( key ) {
104
+ return Promise . resolve ( null ) ;
105
+ } ,
106
+ lpush : function ( key , tag ) {
107
+ recentUploads . push ( key + tag ) ;
108
+ } ,
109
+ ltrim : function ( ) {
110
+ recentUploads . pop ( ) ;
123
111
}
124
- } ) ;
112
+ } ) ) ) ;
125
113
126
114
var promise = redis . upload ( 'key' , 'value' ) ;
127
115
return assert . isFulfilled ( promise )
@@ -133,17 +121,13 @@ describe('redis', function() {
133
121
describe ( 'generating the redis key' , function ( ) {
134
122
it ( 'will use just the default tag if the tag is not provided' , function ( ) {
135
123
var redisKey = null ;
136
- var redis = new Redis ( {
137
- redisClient : {
138
- get : function ( key ) {
124
+
125
+ var redis = new Redis ( { } , new FakeRedis ( FakeClient . extend ( {
126
+ get : function ( key ) {
139
127
redisKey = key ;
140
128
return Promise . resolve ( 'some-other-value' ) ;
141
- } ,
142
- set : function ( ) { } ,
143
- lpush : function ( ) { } ,
144
- ltrim : function ( ) { }
145
129
}
146
- } ) ;
130
+ } ) ) ) ;
147
131
148
132
var promise = redis . upload ( 'key' , 'value' ) ;
149
133
return assert . isRejected ( promise )
@@ -154,17 +138,12 @@ describe('redis', function() {
154
138
155
139
it ( 'will use the key and the tag if the tag is provided' , function ( ) {
156
140
var redisKey = null ;
157
- var redis = new Redis ( {
158
- redisClient : {
159
- get : function ( key ) {
141
+ var redis = new Redis ( { } , new FakeRedis ( FakeClient . extend ( {
142
+ get : function ( key ) {
160
143
redisKey = key ;
161
144
return Promise . resolve ( 'some-other-value' ) ;
162
- } ,
163
- set : function ( ) { } ,
164
- lpush : function ( ) { } ,
165
- ltrim : function ( ) { }
166
- }
167
- } ) ;
145
+ }
146
+ } ) ) ) ;
168
147
169
148
var promise = redis . upload ( 'key' , 'tag' , 'value' ) ;
170
149
return assert . isRejected ( promise )
@@ -179,13 +158,11 @@ describe('redis', function() {
179
158
it ( 'rejects if the revisionKey doesn\t exist in list of uploaded revisions' , function ( ) {
180
159
var recentRevisions = [ 'a' , 'b' , 'c' ] ;
181
160
182
- var redis = new Redis ( {
183
- redisClient : {
184
- lrange : function ( ) {
185
- return recentRevisions ;
186
- }
161
+ var redis = new Redis ( { } , new FakeRedis ( FakeClient . extend ( {
162
+ lrange : function ( ) {
163
+ return recentRevisions ;
187
164
}
188
- } ) ;
165
+ } ) ) ) ;
189
166
190
167
var promise = redis . activate ( 'key-prefix' , 'revision-key' ) ;
191
168
return assert . isRejected ( promise )
@@ -198,17 +175,16 @@ describe('redis', function() {
198
175
var recentRevisions = [ 'a' , 'b' , 'c' ] ;
199
176
var redisKey , redisValue ;
200
177
201
- var redis = new Redis ( {
202
- redisClient : {
203
- lrange : function ( ) {
204
- return recentRevisions ;
205
- } ,
206
- set : function ( key , value ) {
207
- redisKey = key ;
208
- redisValue = value ;
209
- }
178
+
179
+ var redis = new Redis ( { } , new FakeRedis ( FakeClient . extend ( {
180
+ lrange : function ( ) {
181
+ return recentRevisions ;
182
+ } ,
183
+ set : function ( key , value ) {
184
+ redisKey = key ;
185
+ redisValue = value ;
210
186
}
211
- } ) ;
187
+ } ) ) ) ;
212
188
213
189
var promise = redis . activate ( 'key-prefix' , 'c' ) ;
214
190
return assert . isFulfilled ( promise )
0 commit comments