@@ -4,6 +4,19 @@ var Promise = require('ember-cli/lib/ext/promise');
4
4
5
5
var assert = require ( 'ember-cli/tests/helpers/assert' ) ;
6
6
7
+ function hooks ( plugin ) {
8
+ return Object . keys ( plugin ) . filter ( function ( key ) {
9
+ return ( key !== 'name' ) && ( key . charAt ( 0 ) !== '_' ) && ( typeof plugin [ key ] === 'function' ) ;
10
+ } ) ;
11
+ }
12
+
13
+ var stubUi = { write : function ( ) { } , writeLine : function ( ) { } } ;
14
+ var stubProject = {
15
+ name : function ( ) {
16
+ return 'my-project' ;
17
+ }
18
+ } ;
19
+
7
20
describe ( 'redis plugin' , function ( ) {
8
21
var subject ;
9
22
@@ -20,28 +33,24 @@ describe('redis plugin', function() {
20
33
} ) ;
21
34
22
35
it ( 'implements the correct hooks' , function ( ) {
23
- var result = subject . createDeployPlugin ( {
36
+ var plugin = subject . createDeployPlugin ( {
24
37
name : 'test-plugin'
25
38
} ) ;
26
39
27
- assert . equal ( typeof result . configure , 'function' ) ;
28
- assert . equal ( typeof result . upload , 'function' ) ;
40
+ assert . equal ( hooks ( plugin ) . length , 3 ) ;
41
+ assert . sameMembers ( hooks ( plugin ) , [ 'configure' , ' upload' , 'activate' ] ) ;
29
42
} ) ;
30
43
31
- describe ( 'willDeploy hook' , function ( ) {
44
+ describe ( 'configure hook' , function ( ) {
32
45
it ( 'resolves if config is ok' , function ( ) {
33
46
var plugin = subject . createDeployPlugin ( {
34
47
name : 'redis'
35
48
} ) ;
36
49
37
50
var context = {
38
51
deployment : {
39
- ui : { write : function ( ) { } , writeLine : function ( ) { } } ,
40
- project : {
41
- name : function ( ) {
42
- return 'my-project' ;
43
- }
44
- } ,
52
+ ui : stubUi ,
53
+ project : stubProject ,
45
54
config : {
46
55
redis : {
47
56
host : 'somehost' ,
@@ -53,6 +62,96 @@ describe('redis plugin', function() {
53
62
54
63
return assert . isFulfilled ( plugin . configure . call ( plugin , context ) )
55
64
} ) ;
65
+
66
+ describe ( 'resolving data from the pipeline' , function ( ) {
67
+ it ( 'uses the config data if it already exists' , function ( ) {
68
+ var plugin = subject . createDeployPlugin ( {
69
+ name : 'redis'
70
+ } ) ;
71
+
72
+ var config = {
73
+ host : 'somehost' ,
74
+ port : 1234 ,
75
+ revisionKey : '12345'
76
+ } ;
77
+ var context = {
78
+ deployment : {
79
+ ui : stubUi ,
80
+ project : stubProject ,
81
+ config : {
82
+ redis : config
83
+ }
84
+ } ,
85
+
86
+ revisionKey : 'something-else'
87
+ } ;
88
+
89
+ return assert . isFulfilled ( plugin . configure . call ( plugin , context ) )
90
+ . then ( function ( ) {
91
+ assert . equal ( config . revisionKey , '12345' ) ;
92
+ } ) ;
93
+ } ) ;
94
+
95
+ it ( 'uses the commandLineArgs value if it exists' , function ( ) {
96
+ var plugin = subject . createDeployPlugin ( {
97
+ name : 'redis'
98
+ } ) ;
99
+
100
+ var config = {
101
+ host : 'somehost' ,
102
+ port : 1234
103
+ } ;
104
+ var context = {
105
+ deployment : {
106
+ ui : stubUi ,
107
+ project : stubProject ,
108
+ config : {
109
+ redis : config
110
+ } ,
111
+ commandLineArgs : {
112
+ revisionKey : 'abcd'
113
+ }
114
+ } ,
115
+
116
+ revisionKey : 'something-else'
117
+ } ;
118
+
119
+ return assert . isFulfilled ( plugin . configure . call ( plugin , context ) )
120
+ . then ( function ( ) {
121
+ assert . typeOf ( config . revisionKey , 'function' ) ;
122
+ assert . equal ( config . revisionKey ( context ) , 'abcd' ) ;
123
+ } ) ;
124
+ } )
125
+
126
+ it ( 'uses the context value if it exists and commandLineArgs don\'t' , function ( ) {
127
+ var plugin = subject . createDeployPlugin ( {
128
+ name : 'redis'
129
+ } ) ;
130
+
131
+ var config = {
132
+ host : 'somehost' ,
133
+ port : 1234
134
+ } ;
135
+ var context = {
136
+ deployment : {
137
+ ui : stubUi ,
138
+ project : stubProject ,
139
+ config : {
140
+ redis : config
141
+ } ,
142
+ commandLineArgs : { }
143
+ } ,
144
+
145
+ revisionKey : 'something-else'
146
+ } ;
147
+
148
+ return assert . isFulfilled ( plugin . configure . call ( plugin , context ) )
149
+ . then ( function ( ) {
150
+ assert . typeOf ( config . revisionKey , 'function' ) ;
151
+ assert . equal ( config . revisionKey ( context ) , 'something-else' ) ;
152
+ } ) ;
153
+ } )
154
+ } ) ;
56
155
} ) ;
57
156
58
157
describe ( 'upload hook' , function ( ) {
@@ -66,34 +165,95 @@ describe('redis plugin', function() {
66
165
67
166
context = {
68
167
redisClient : {
69
- upload : function ( ) {
70
- return Promise . resolve ( 'redis-key' ) ;
168
+ upload : function ( keyPrefix , revisionKey ) {
169
+ return Promise . resolve ( keyPrefix + ':' + revisionKey ) ;
71
170
}
72
171
} ,
73
172
tag : 'some-tag' ,
74
173
deployment : {
75
- ui : { write : function ( ) { } } ,
76
- project : { name : function ( ) { return 'test-project' ; } } ,
174
+ ui : stubUi ,
175
+ project : stubProject ,
77
176
config : {
78
177
redis : {
178
+ keyPrefix : 'test-prefix' ,
79
179
filePattern : 'tests/index.html' ,
180
+ revisionKey : '123abc'
80
181
}
81
182
}
82
- }
183
+ } ,
83
184
} ;
84
185
} ) ;
85
186
86
- it ( 'uploads the index to redis ' , function ( ) {
187
+ it ( 'uploads the index' , function ( ) {
87
188
return assert . isFulfilled ( plugin . upload . call ( plugin , context ) )
88
189
. then ( function ( result ) {
89
- assert . deepEqual ( result , { redisKey : 'redis-key ' } ) ;
190
+ assert . deepEqual ( result , { redisKey : 'test-prefix:123abc ' } ) ;
90
191
} ) ;
91
192
} ) ;
193
+ } ) ;
92
194
93
- it ( 'returns the uploaded key' , function ( ) {
94
- return assert . isFulfilled ( plugin . upload . call ( plugin , context ) )
95
- . then ( function ( result ) {
96
- assert . deepEqual ( result . redisKey , 'redis-key' ) ;
195
+ describe ( 'activate hook' , function ( ) {
196
+ it ( 'activates revision' , function ( ) {
197
+ var activateCalled = false ;
198
+
199
+ var plugin = subject . createDeployPlugin ( {
200
+ name : 'redis'
201
+ } ) ;
202
+
203
+ var context = {
204
+ redisClient : {
205
+ activate : function ( ) {
206
+ activateCalled = true ;
207
+ }
208
+ } ,
209
+ tag : 'some-tag' ,
210
+ deployment : {
211
+ ui : stubUi ,
212
+ project : stubProject ,
213
+ config : {
214
+ redis : {
215
+ keyPrefix : 'test-prefix' ,
216
+ filePattern : 'tests/index.html' ,
217
+ revisionKey : '123abc'
218
+ }
219
+ }
220
+ }
221
+ } ;
222
+
223
+ return assert . isFulfilled ( plugin . activate . call ( plugin , context ) )
224
+ . then ( function ( ) {
225
+ assert . ok ( activateCalled ) ;
226
+ } ) ;
227
+ } ) ;
228
+
229
+ it ( 'rejects if an error is thrown when activating' , function ( ) {
230
+ var plugin = subject . createDeployPlugin ( {
231
+ name : 'redis'
232
+ } ) ;
233
+
234
+ var context = {
235
+ redisClient : {
236
+ activate : function ( ) {
237
+ return Promise . reject ( 'some-error' ) ;
238
+ }
239
+ } ,
240
+ tag : 'some-tag' ,
241
+ deployment : {
242
+ ui : stubUi ,
243
+ project : stubProject ,
244
+ config : {
245
+ redis : {
246
+ keyPrefix : 'test-prefix' ,
247
+ filePattern : 'tests/index.html' ,
248
+ revisionKey : '123abc'
249
+ }
250
+ }
251
+ }
252
+ } ;
253
+
254
+ return assert . isRejected ( plugin . activate . call ( plugin , context ) )
255
+ . then ( function ( error ) {
256
+ assert . equal ( error , 'some-error' ) ;
97
257
} ) ;
98
258
} ) ;
99
259
} ) ;
0 commit comments