1
1
var spotify = require ( '../lib/spotify-node-applescript.js' ) ;
2
2
var expect = require ( 'chai' ) . expect ;
3
3
4
- describe ( 'Spotify Controller' , function ( ) {
4
+ var COLDPLAY_TROUBLE_ID = 'spotify:track:0R8P9KfGJCDULmlEoBagcO'
5
+
6
+ describe ( 'Spotify Controller' , function ( ) {
5
7
6
8
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7
9
// Make sure spotify is open before running these tests
8
10
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
9
11
10
- beforeEach ( function ( done ) {
11
- spotify . playTrackInContext ( 'spotify:track:0R8P9KfGJCDULmlEoBagcO' , 'spotify:album:6ZG5lRT77aJ3btmArcykra' , function ( ) {
12
+ beforeEach ( function ( done ) {
13
+ spotify . playTrackInContext ( 'spotify:track:0R8P9KfGJCDULmlEoBagcO' , 'spotify:album:6ZG5lRT77aJ3btmArcykra' , function ( ) {
12
14
done ( ) ;
13
15
} ) ;
14
16
} ) ;
15
17
16
- after ( function ( done ) {
17
- spotify . pause ( function ( ) {
18
+ after ( function ( done ) {
19
+ spotify . pause ( function ( ) {
18
20
done ( ) ;
19
21
} ) ;
20
22
spotify . setRepeating ( false ) ;
@@ -23,9 +25,9 @@ describe('Spotify Controller', function(){
23
25
24
26
// Open and get track
25
27
26
- it ( 'play track' , function ( done ) {
27
- spotify . playTrack ( 'spotify:track:6JEK0CvvjDjjMUBFoXShNZ' , function ( ) {
28
- spotify . getTrack ( function ( error , track ) {
28
+ it ( 'play track' , function ( done ) {
29
+ spotify . playTrack ( 'spotify:track:6JEK0CvvjDjjMUBFoXShNZ' , function ( ) {
30
+ spotify . getTrack ( function ( error , track ) {
29
31
expect ( track . name ) . to . equal ( 'Never Gonna Give You Up' ) ;
30
32
done ( ) ;
31
33
} ) ;
@@ -34,32 +36,32 @@ describe('Spotify Controller', function(){
34
36
35
37
// Playback control
36
38
37
- it ( 'should pause a track' , function ( done ) {
38
- spotify . pause ( function ( ) {
39
- spotify . getState ( function ( error , state ) {
39
+ it ( 'should pause a track' , function ( done ) {
40
+ spotify . pause ( function ( ) {
41
+ spotify . getState ( function ( error , state ) {
40
42
expect ( state . state ) . to . equal ( 'paused' ) ;
41
43
done ( ) ;
42
44
} ) ;
43
45
} ) ;
44
46
} ) ;
45
47
46
- it ( 'should resume playing a track after pausing' , function ( done ) {
47
- spotify . pause ( function ( ) {
48
- spotify . play ( function ( ) {
49
- spotify . getState ( function ( error , state ) {
48
+ it ( 'should resume playing a track after pausing' , function ( done ) {
49
+ spotify . pause ( function ( ) {
50
+ spotify . play ( function ( ) {
51
+ spotify . getState ( function ( error , state ) {
50
52
expect ( state . state ) . to . equal ( 'playing' ) ;
51
53
done ( ) ;
52
54
} ) ;
53
55
} ) ;
54
56
} ) ;
55
57
} ) ;
56
58
57
- it ( 'should play and pause a track' , function ( done ) {
58
- spotify . playPause ( function ( ) {
59
- spotify . getState ( function ( error , state ) {
59
+ it ( 'should play and pause a track' , function ( done ) {
60
+ spotify . playPause ( function ( ) {
61
+ spotify . getState ( function ( error , state ) {
60
62
expect ( state . state ) . to . equal ( 'paused' ) ;
61
- spotify . playPause ( function ( ) {
62
- spotify . getState ( function ( error , state ) {
63
+ spotify . playPause ( function ( ) {
64
+ spotify . getState ( function ( error , state ) {
63
65
expect ( state . state ) . to . equal ( 'playing' ) ;
64
66
done ( ) ;
65
67
} ) ;
@@ -68,54 +70,54 @@ describe('Spotify Controller', function(){
68
70
} ) ;
69
71
} ) ;
70
72
71
- it ( 'should return playing track' , function ( done ) {
72
- spotify . getTrack ( function ( error , track ) {
73
+ it ( 'should return playing track' , function ( done ) {
74
+ spotify . getTrack ( function ( error , track ) {
73
75
expect ( track . artist ) . to . equal ( 'Coldplay' ) ;
74
76
expect ( track . name ) . to . equal ( 'Trouble' ) ;
75
77
done ( ) ;
76
78
} ) ;
77
79
} ) ;
78
80
79
- it ( 'should jump to a specific position of the song' , function ( done ) {
81
+ it ( 'should jump to a specific position of the song' , function ( done ) {
80
82
// spotify needs some time to catch up with the jump or it will
81
83
// simply return 0 as current player position
82
- setTimeout ( function ( ) {
83
- spotify . jumpTo ( 15 , function ( ) {
84
- spotify . getState ( function ( err , state ) {
84
+ setTimeout ( function ( ) {
85
+ spotify . jumpTo ( 15 , function ( ) {
86
+ spotify . getState ( function ( err , state ) {
85
87
expect ( state . position ) . to . equal ( 15 ) ;
86
88
done ( ) ;
87
89
} ) ;
88
90
} ) ;
89
91
} , 1100 ) ;
90
92
} ) ;
91
93
92
- it ( 'play next track' , function ( done ) {
93
- spotify . next ( function ( error , track ) {
94
- spotify . getTrack ( function ( error , track ) {
94
+ it ( 'play next track' , function ( done ) {
95
+ spotify . next ( function ( error , track ) {
96
+ spotify . getTrack ( function ( error , track ) {
95
97
expect ( track . name ) . to . equal ( 'Parachutes' ) ;
96
- done ( ) ;
97
- } ) ;
98
- } ) ;
99
- } ) ;
100
-
101
- it ( 'play previous track' , function ( done ) {
102
- spotify . previous ( function ( error , track ) {
103
- spotify . getTrack ( function ( error , track ) {
104
- expect ( track . name ) . to . equal ( 'Yellow' ) ;
105
- done ( ) ;
106
- } ) ;
107
- } ) ;
108
- } ) ;
98
+ done ( ) ;
99
+ } ) ;
100
+ } ) ;
101
+ } ) ;
102
+
103
+ it ( 'play previous track' , function ( done ) {
104
+ spotify . previous ( function ( error , track ) {
105
+ spotify . getTrack ( function ( error , track ) {
106
+ expect ( track . name ) . to . equal ( 'Yellow' ) ;
107
+ done ( ) ;
108
+ } ) ;
109
+ } ) ;
110
+ } ) ;
109
111
110
112
// Volumen control
111
113
112
- it ( 'should turn volume up' , function ( done ) {
114
+ it ( 'should turn volume up' , function ( done ) {
113
115
// first do volumeDown in case volume is already 100
114
- spotify . volumeDown ( function ( ) {
115
- spotify . getState ( function ( error , state ) {
116
+ spotify . volumeDown ( function ( ) {
117
+ spotify . getState ( function ( error , state ) {
116
118
var volume = state . volume ;
117
- spotify . volumeUp ( function ( ) {
118
- spotify . getState ( function ( error , state ) {
119
+ spotify . volumeUp ( function ( ) {
120
+ spotify . getState ( function ( error , state ) {
119
121
expect ( state . volume ) . to . be . greaterThan ( volume ) ;
120
122
done ( ) ;
121
123
} ) ;
@@ -124,13 +126,13 @@ describe('Spotify Controller', function(){
124
126
} ) ;
125
127
} ) ;
126
128
127
- it ( 'should turn volume down' , function ( done ) {
129
+ it ( 'should turn volume down' , function ( done ) {
128
130
// first do volumeUp in case volume is already 0
129
- spotify . volumeUp ( function ( ) {
130
- spotify . getState ( function ( error , state ) {
131
+ spotify . volumeUp ( function ( ) {
132
+ spotify . getState ( function ( error , state ) {
131
133
var volume = state . volume ;
132
- spotify . volumeDown ( function ( ) {
133
- spotify . getState ( function ( error , state ) {
134
+ spotify . volumeDown ( function ( ) {
135
+ spotify . getState ( function ( error , state ) {
134
136
expect ( state . volume ) . to . be . lessThan ( volume ) ;
135
137
done ( ) ;
136
138
} ) ;
@@ -139,13 +141,13 @@ describe('Spotify Controller', function(){
139
141
} ) ;
140
142
} ) ;
141
143
142
- it ( 'should not overflow on volume up' , function ( done ) {
144
+ it ( 'should not overflow on volume up' , function ( done ) {
143
145
// first do setVolume to emulate overflow when volume up
144
- spotify . setVolume ( 95 , function ( ) {
145
- spotify . getState ( function ( error , state ) {
146
+ spotify . setVolume ( 95 , function ( ) {
147
+ spotify . getState ( function ( error , state ) {
146
148
var volume = state . volume ;
147
- spotify . volumeUp ( function ( ) {
148
- spotify . getState ( function ( error , state ) {
149
+ spotify . volumeUp ( function ( ) {
150
+ spotify . getState ( function ( error , state ) {
149
151
expect ( state . volume ) . to . be . greaterThan ( volume ) ;
150
152
done ( ) ;
151
153
} ) ;
@@ -154,13 +156,13 @@ describe('Spotify Controller', function(){
154
156
} ) ;
155
157
} ) ;
156
158
157
- it ( 'should not overflow on volume down' , function ( done ) {
159
+ it ( 'should not overflow on volume down' , function ( done ) {
158
160
// first do setVolume to emulate overflow when volume down
159
- spotify . setVolume ( 5 , function ( ) {
160
- spotify . getState ( function ( error , state ) {
161
+ spotify . setVolume ( 5 , function ( ) {
162
+ spotify . getState ( function ( error , state ) {
161
163
var volume = state . volume ;
162
- spotify . volumeDown ( function ( ) {
163
- spotify . getState ( function ( error , state ) {
164
+ spotify . volumeDown ( function ( ) {
165
+ spotify . getState ( function ( error , state ) {
164
166
expect ( state . volume ) . to . be . lessThan ( volume ) ;
165
167
done ( ) ;
166
168
} ) ;
@@ -169,9 +171,9 @@ describe('Spotify Controller', function(){
169
171
} ) ;
170
172
} ) ;
171
173
172
- it ( 'should set the volume' , function ( done ) {
173
- spotify . setVolume ( 0 , function ( ) {
174
- spotify . getState ( function ( err , state ) {
174
+ it ( 'should set the volume' , function ( done ) {
175
+ spotify . setVolume ( 0 , function ( ) {
176
+ spotify . getState ( function ( err , state ) {
175
177
if ( err ) throw err ;
176
178
177
179
expect ( state . volume ) . to . equal ( 0 ) ;
@@ -180,17 +182,17 @@ describe('Spotify Controller', function(){
180
182
} ) ;
181
183
} ) ;
182
184
183
- it ( 'should mute and unmute the volume' , function ( done ) {
184
- spotify . setVolume ( 50 , function ( ) {
185
- spotify . muteVolume ( function ( err , state ) {
186
- spotify . getState ( function ( err , state ) {
185
+ it ( 'should mute and unmute the volume' , function ( done ) {
186
+ spotify . setVolume ( 50 , function ( ) {
187
+ spotify . muteVolume ( function ( err , state ) {
188
+ spotify . getState ( function ( err , state ) {
187
189
if ( err ) throw err ;
188
190
189
191
// volume now should be 0
190
192
expect ( state . volume ) . to . equal ( 0 ) ;
191
193
192
- spotify . unmuteVolume ( function ( err , state ) {
193
- spotify . getState ( function ( err , state ) {
194
+ spotify . unmuteVolume ( function ( err , state ) {
195
+ spotify . getState ( function ( err , state ) {
194
196
if ( err ) throw err ;
195
197
196
198
// volume now should be 50 again
@@ -206,8 +208,8 @@ describe('Spotify Controller', function(){
206
208
207
209
// State retrieval
208
210
209
- it ( 'should return current track' , function ( done ) {
210
- spotify . getTrack ( function ( error , track ) {
211
+ it ( 'should return current track' , function ( done ) {
212
+ spotify . getTrack ( function ( error , track ) {
211
213
expect ( track . name ) . to . equal ( 'Trouble' ) ;
212
214
expect ( track . artist ) . to . equal ( 'Coldplay' ) ;
213
215
expect ( track . album ) . to . equal ( 'Parachutes' ) ;
@@ -216,7 +218,7 @@ describe('Spotify Controller', function(){
216
218
expect ( track . played_count ) . to . be . a ( 'number' ) ;
217
219
expect ( track . track_number ) . to . equal ( 6 ) ;
218
220
expect ( track . popularity ) . to . be . a ( 'number' ) ;
219
- expect ( track . id ) . to . equal ( 'spotify:track:0R8P9KfGJCDULmlEoBagcO' ) ;
221
+ expect ( track . id ) . to . equal ( COLDPLAY_TROUBLE_ID ) ;
220
222
expect ( track . album_artist ) . to . equal ( 'Coldplay' ) ;
221
223
expect ( track . artwork_url ) . to . contain ( 'image/495b0549379fc4c324445fd7d2bfa219a8c18a90' ) ;
222
224
expect ( track . spotify_url ) . to . equal ( 'spotify:track:0R8P9KfGJCDULmlEoBagcO' ) ;
@@ -225,8 +227,8 @@ describe('Spotify Controller', function(){
225
227
} ) ;
226
228
} ) ;
227
229
228
- it ( 'should return player status' , function ( done ) {
229
- spotify . getState ( function ( error , state ) {
230
+ it ( 'should return player status' , function ( done ) {
231
+ spotify . getState ( function ( error , state ) {
230
232
expect ( state . state ) . to . equal ( 'playing' ) ;
231
233
expect ( state . volume ) . to . be . a ( 'number' ) ;
232
234
expect ( state . position ) . to . be . a ( 'number' ) ;
@@ -236,17 +238,17 @@ describe('Spotify Controller', function(){
236
238
} ) ;
237
239
} ) ;
238
240
239
- it ( 'should return true when spotify is running' , function ( done ) {
240
- spotify . isRunning ( function ( error , isRunning ) {
241
+ it ( 'should return true when spotify is running' , function ( done ) {
242
+ spotify . isRunning ( function ( error , isRunning ) {
241
243
expect ( error ) . to . be . null ;
242
244
expect ( isRunning ) . to . be . true ;
243
245
done ( ) ;
244
246
} ) ;
245
247
} ) ;
246
248
247
- it ( 'should set the repeating to false' , function ( done ) {
248
- spotify . setRepeating ( false , function ( ) {
249
- spotify . isRepeating ( function ( err , repeating ) {
249
+ it ( 'should set the repeating to false' , function ( done ) {
250
+ spotify . setRepeating ( false , function ( ) {
251
+ spotify . isRepeating ( function ( err , repeating ) {
250
252
if ( err ) throw err ;
251
253
252
254
expect ( repeating ) . to . equal ( false ) ;
@@ -255,9 +257,9 @@ describe('Spotify Controller', function(){
255
257
} ) ;
256
258
} ) ;
257
259
258
- it ( 'should set the repeating to true' , function ( done ) {
259
- spotify . setRepeating ( true , function ( ) {
260
- spotify . isRepeating ( function ( err , repeating ) {
260
+ it ( 'should set the repeating to true' , function ( done ) {
261
+ spotify . setRepeating ( true , function ( ) {
262
+ spotify . isRepeating ( function ( err , repeating ) {
261
263
if ( err ) throw err ;
262
264
263
265
expect ( repeating ) . to . equal ( true ) ;
@@ -266,9 +268,9 @@ describe('Spotify Controller', function(){
266
268
} ) ;
267
269
} ) ;
268
270
269
- it ( 'should set the shuffling to false' , function ( done ) {
270
- spotify . setShuffling ( false , function ( ) {
271
- spotify . isShuffling ( function ( err , shuffling ) {
271
+ it ( 'should set the shuffling to false' , function ( done ) {
272
+ spotify . setShuffling ( false , function ( ) {
273
+ spotify . isShuffling ( function ( err , shuffling ) {
272
274
if ( err ) throw err ;
273
275
274
276
expect ( shuffling ) . to . equal ( false ) ;
@@ -277,9 +279,9 @@ describe('Spotify Controller', function(){
277
279
} ) ;
278
280
} ) ;
279
281
280
- it ( 'should set the shuffling to true' , function ( done ) {
281
- spotify . setShuffling ( true , function ( ) {
282
- spotify . isShuffling ( function ( err , shuffling ) {
282
+ it ( 'should set the shuffling to true' , function ( done ) {
283
+ spotify . setShuffling ( true , function ( ) {
284
+ spotify . isShuffling ( function ( err , shuffling ) {
283
285
if ( err ) throw err ;
284
286
285
287
expect ( shuffling ) . to . equal ( true ) ;
@@ -288,10 +290,10 @@ describe('Spotify Controller', function(){
288
290
} ) ;
289
291
} ) ;
290
292
291
- it ( 'should toggle the repeating' , function ( done ) {
292
- spotify . setRepeating ( false , function ( ) {
293
- spotify . toggleRepeating ( function ( err ) {
294
- spotify . isRepeating ( function ( err , repeating ) {
293
+ it ( 'should toggle the repeating' , function ( done ) {
294
+ spotify . setRepeating ( false , function ( ) {
295
+ spotify . toggleRepeating ( function ( err ) {
296
+ spotify . isRepeating ( function ( err , repeating ) {
295
297
if ( err ) throw err ;
296
298
297
299
expect ( repeating ) . to . equal ( true ) ;
@@ -301,10 +303,10 @@ describe('Spotify Controller', function(){
301
303
} ) ;
302
304
} ) ;
303
305
304
- it ( 'should toggle the shuffling' , function ( done ) {
305
- spotify . setShuffling ( false , function ( ) {
306
- spotify . toggleShuffling ( function ( err ) {
307
- spotify . isShuffling ( function ( err , shuffling ) {
306
+ it ( 'should toggle the shuffling' , function ( done ) {
307
+ spotify . setShuffling ( false , function ( ) {
308
+ spotify . toggleShuffling ( function ( err ) {
309
+ spotify . isShuffling ( function ( err , shuffling ) {
308
310
if ( err ) throw err ;
309
311
310
312
expect ( shuffling ) . to . equal ( true ) ;
0 commit comments