From 7cc68d1968ad1590127801616cb8ecb6632e9755 Mon Sep 17 00:00:00 2001 From: Jonathan Cremin Date: Thu, 4 Dec 2014 16:29:39 +0000 Subject: [PATCH] Add tests for Beats --- lib/googleplaymusic.js | 4 ++++ lib/spotify.js | 4 ++++ package.json | 2 +- test/test.js | 53 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 1 deletion(-) diff --git a/lib/googleplaymusic.js b/lib/googleplaymusic.js index eabda90..3889b37 100644 --- a/lib/googleplaymusic.js +++ b/lib/googleplaymusic.js @@ -62,6 +62,10 @@ module.exports.search = function(data, next) { return a.score < b.score; }).shift(); + if (!result.album && !result.track) { + next({service:"googleplaymusic"}); + } + var id; if (type == "album") { id = result.album.albumId; diff --git a/lib/spotify.js b/lib/spotify.js index 3f575ab..abb05c1 100644 --- a/lib/spotify.js +++ b/lib/spotify.js @@ -58,6 +58,10 @@ module.exports.search = function(data, next) { return; } + if (!data[type + "s"].items[0]) { + next({service:"spotify"}); + } + var item = data[type + "s"].items[0]; module.exports.lookupId(item.id, type, next); diff --git a/package.json b/package.json index 60a4643..567dffb 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "private": true, "scripts": { "start": "node ./bin/www", - "test": "./node_modules/mocha/bin/mocha" + "test": "./node_modules/mocha/bin/mocha --timeout=5000" }, "engines": { "node": "0.10.x" diff --git a/test/test.js b/test/test.js index 3eebf08..12bcbc9 100644 --- a/test/test.js +++ b/test/test.js @@ -4,6 +4,7 @@ var should = require('should'); var spotify = require("../lib/spotify"); var rdio = require("../lib/rdio"); var googleplaymusic = require("../lib/googleplaymusic"); +var beats = require("../lib/beats"); describe('Spotify', function(){ describe('lookupId', function(){ @@ -112,3 +113,55 @@ describe('Google Play Music', function(){ }); }); }); + +describe('Beats Music', function(){ + describe('lookupId', function(){ + it('should find album by ID', function(done){ + beats.lookupId("al920431", function(result) { + result.name.should.equal("Deftones"); + done(); + }); + }); + + it('should find track by ID', function(done){ + beats.lookupId("tr6910289", function(result) { + result.name.should.equal("Californication"); + done(); + }); + }); + }); + + describe('search', function(){ + it('should find album by search', function(done){ + beats.search({type: "album", artist: {name: "Deftones"}, name: "Deftones"}, function(result) { + result.name.should.equal("Deftones"); + done(); + }); + }); + + it('should find track by search', function(done){ + beats.search({type: "track", artist: {name: "Deftones"}, album: {name: "Deftones"}, name: "Hexagram"}, function(result) { + result.name.should.equal("Hexagram"); + done(); + }); + }); + }); + + describe('lookupUrl', function(){ + describe('parseUrl', function(){ + it('should parse album url into ID', function(done){ + beats.parseUrl("https://listen.beatsmusic.com/albums/al920431", function(result) { + result.id.should.equal("al920431"); + done(); + }); + }); + + it('should parse track url into ID', function(done){ + beats.parseUrl("https://listen.beatsmusic.com/albums/al6910269/tracks/tr6910289", function(result) { + result.id.should.equal("tr6910289"); + done(); + }); + }); + }); + }); +});