Skip to content

Commit d4c78b0

Browse files
committed
refactor: Extract repeating constant
1 parent 295cf27 commit d4c78b0

File tree

1 file changed

+100
-98
lines changed

1 file changed

+100
-98
lines changed

test/test.js

Lines changed: 100 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
var spotify = require('../lib/spotify-node-applescript.js');
22
var expect = require('chai').expect;
33

4-
describe('Spotify Controller', function(){
4+
var COLDPLAY_TROUBLE_ID = 'spotify:track:0R8P9KfGJCDULmlEoBagcO'
5+
6+
describe('Spotify Controller', function () {
57

68
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
79
// Make sure spotify is open before running these tests
810
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
911

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 () {
1214
done();
1315
});
1416
});
1517

16-
after(function(done){
17-
spotify.pause(function(){
18+
after(function (done) {
19+
spotify.pause(function () {
1820
done();
1921
});
2022
spotify.setRepeating(false);
@@ -23,9 +25,9 @@ describe('Spotify Controller', function(){
2325

2426
// Open and get track
2527

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) {
2931
expect(track.name).to.equal('Never Gonna Give You Up');
3032
done();
3133
});
@@ -34,32 +36,32 @@ describe('Spotify Controller', function(){
3436

3537
// Playback control
3638

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) {
4042
expect(state.state).to.equal('paused');
4143
done();
4244
});
4345
});
4446
});
4547

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) {
5052
expect(state.state).to.equal('playing');
5153
done();
5254
});
5355
});
5456
});
5557
});
5658

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) {
6062
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) {
6365
expect(state.state).to.equal('playing');
6466
done();
6567
});
@@ -68,54 +70,54 @@ describe('Spotify Controller', function(){
6870
});
6971
});
7072

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) {
7375
expect(track.artist).to.equal('Coldplay');
7476
expect(track.name).to.equal('Trouble');
7577
done();
7678
});
7779
});
7880

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) {
8082
// spotify needs some time to catch up with the jump or it will
8183
// 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) {
8587
expect(state.position).to.equal(15);
8688
done();
8789
});
8890
});
8991
}, 1100);
9092
});
9193

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) {
9597
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+
});
109111

110112
// Volumen control
111113

112-
it('should turn volume up', function(done){
114+
it('should turn volume up', function (done) {
113115
// 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) {
116118
var volume = state.volume;
117-
spotify.volumeUp(function(){
118-
spotify.getState(function(error, state){
119+
spotify.volumeUp(function () {
120+
spotify.getState(function (error, state) {
119121
expect(state.volume).to.be.greaterThan(volume);
120122
done();
121123
});
@@ -124,13 +126,13 @@ describe('Spotify Controller', function(){
124126
});
125127
});
126128

127-
it('should turn volume down', function(done){
129+
it('should turn volume down', function (done) {
128130
// 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) {
131133
var volume = state.volume;
132-
spotify.volumeDown(function(){
133-
spotify.getState(function(error, state){
134+
spotify.volumeDown(function () {
135+
spotify.getState(function (error, state) {
134136
expect(state.volume).to.be.lessThan(volume);
135137
done();
136138
});
@@ -139,13 +141,13 @@ describe('Spotify Controller', function(){
139141
});
140142
});
141143

142-
it('should not overflow on volume up', function(done){
144+
it('should not overflow on volume up', function (done) {
143145
// 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) {
146148
var volume = state.volume;
147-
spotify.volumeUp(function(){
148-
spotify.getState(function(error, state){
149+
spotify.volumeUp(function () {
150+
spotify.getState(function (error, state) {
149151
expect(state.volume).to.be.greaterThan(volume);
150152
done();
151153
});
@@ -154,13 +156,13 @@ describe('Spotify Controller', function(){
154156
});
155157
});
156158

157-
it('should not overflow on volume down', function(done){
159+
it('should not overflow on volume down', function (done) {
158160
// 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) {
161163
var volume = state.volume;
162-
spotify.volumeDown(function(){
163-
spotify.getState(function(error, state){
164+
spotify.volumeDown(function () {
165+
spotify.getState(function (error, state) {
164166
expect(state.volume).to.be.lessThan(volume);
165167
done();
166168
});
@@ -169,9 +171,9 @@ describe('Spotify Controller', function(){
169171
});
170172
});
171173

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) {
175177
if (err) throw err;
176178

177179
expect(state.volume).to.equal(0);
@@ -180,17 +182,17 @@ describe('Spotify Controller', function(){
180182
});
181183
});
182184

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) {
187189
if (err) throw err;
188190

189191
// volume now should be 0
190192
expect(state.volume).to.equal(0);
191193

192-
spotify.unmuteVolume(function(err, state){
193-
spotify.getState(function(err, state){
194+
spotify.unmuteVolume(function (err, state) {
195+
spotify.getState(function (err, state) {
194196
if (err) throw err;
195197

196198
// volume now should be 50 again
@@ -206,8 +208,8 @@ describe('Spotify Controller', function(){
206208

207209
// State retrieval
208210

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) {
211213
expect(track.name).to.equal('Trouble');
212214
expect(track.artist).to.equal('Coldplay');
213215
expect(track.album).to.equal('Parachutes');
@@ -216,7 +218,7 @@ describe('Spotify Controller', function(){
216218
expect(track.played_count).to.be.a('number');
217219
expect(track.track_number).to.equal(6);
218220
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);
220222
expect(track.album_artist).to.equal('Coldplay');
221223
expect(track.artwork_url).to.contain('image/495b0549379fc4c324445fd7d2bfa219a8c18a90');
222224
expect(track.spotify_url).to.equal('spotify:track:0R8P9KfGJCDULmlEoBagcO');
@@ -225,8 +227,8 @@ describe('Spotify Controller', function(){
225227
});
226228
});
227229

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) {
230232
expect(state.state).to.equal('playing');
231233
expect(state.volume).to.be.a('number');
232234
expect(state.position).to.be.a('number');
@@ -236,17 +238,17 @@ describe('Spotify Controller', function(){
236238
});
237239
});
238240

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) {
241243
expect(error).to.be.null;
242244
expect(isRunning).to.be.true;
243245
done();
244246
});
245247
});
246248

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) {
250252
if (err) throw err;
251253

252254
expect(repeating).to.equal(false);
@@ -255,9 +257,9 @@ describe('Spotify Controller', function(){
255257
});
256258
});
257259

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) {
261263
if (err) throw err;
262264

263265
expect(repeating).to.equal(true);
@@ -266,9 +268,9 @@ describe('Spotify Controller', function(){
266268
});
267269
});
268270

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) {
272274
if (err) throw err;
273275

274276
expect(shuffling).to.equal(false);
@@ -277,9 +279,9 @@ describe('Spotify Controller', function(){
277279
});
278280
});
279281

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) {
283285
if (err) throw err;
284286

285287
expect(shuffling).to.equal(true);
@@ -288,10 +290,10 @@ describe('Spotify Controller', function(){
288290
});
289291
});
290292

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) {
295297
if (err) throw err;
296298

297299
expect(repeating).to.equal(true);
@@ -301,10 +303,10 @@ describe('Spotify Controller', function(){
301303
});
302304
});
303305

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) {
308310
if (err) throw err;
309311

310312
expect(shuffling).to.equal(true);

0 commit comments

Comments
 (0)