Skip to content

Commit

Permalink
#5 covering empty queue for /queue command
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdevwords authored and chrisdevwords committed May 7, 2017
1 parent 86699c7 commit 7a996d8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const {
CURRENT_PL,
PL_SET,
QUEUE,
NONE_QUEUED,
SHUFFLING,
NOT_SHUFFLING,
PAUSED,
Expand Down Expand Up @@ -118,7 +119,7 @@ function getQueue() {
})
.then(({ tracks }) => {
if (!tracks.length) {
return 'No tracks currently queued.';
return NONE_QUEUED;
}
// eslint-disable-next-line babel/new-cap
return QUEUE(tracks);
Expand Down
2 changes: 2 additions & 0 deletions src/slack-resp.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const INVALID_TOKEN = 'Token is invalid.';
const CMD_NOT_SUPPORTED = 'Command not supported.';
const SHUFFLING = 'Spotify player is now shuffling.';
const NOT_SHUFFLING = 'Spotify player is no longer shuffling.';
const NONE_QUEUED = 'No tracks currently queued.';

const TRACK = ({ name, artist, requestedBy }) =>
`"${name}" by ${artist} requested by ${requestedBy}`;
Expand Down Expand Up @@ -75,6 +76,7 @@ module.exports = {
PAUSED,
RESUMED,
QUEUE,
NONE_QUEUED,
printQueue,
slackResp
};
3 changes: 3 additions & 0 deletions test/mock/local/spotify/api/queue/empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"tracks": []
}
28 changes: 27 additions & 1 deletion test/test_commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const dotenv = require('dotenv');
const { exec, setAPIRoot } = require('../src/commands');
const {
ADDED,
NONE_QUEUED,
ALBUM_ADDED,
NOW_PLAYING,
PL_SET,
Expand Down Expand Up @@ -140,7 +141,7 @@ describe('The Slack commands for Spotify Local ', () => {
describe('the /queue command', () => {
const command = '/queue';

context('when the spotify local server is running', () => {
context('when there are tracks in the queue', () => {
beforeEach((done) => {
sinon.stub(request, 'get')
.callsFake(() =>
Expand Down Expand Up @@ -171,6 +172,31 @@ describe('The Slack commands for Spotify Local ', () => {
.catch(done);
});
});

context('when there no are tracks in the queue', () => {
beforeEach((done) => {
sinon.stub(request, 'get')
.callsFake(() =>
openMock('local/spotify/api/queue/empty')
);
done();
});

afterEach((done) => {
request.get.restore();
done();
});

it('resolves with text for slack', (done) => {
exec({ command })
.then((text) => {
expect(text).to.be.a('string');
expect(text).to.eq(NONE_QUEUED);
done();
})
.catch(done);
});
});
});

describe('the /add command', () => {
Expand Down

0 comments on commit 7a996d8

Please sign in to comment.