Renames all tests according to angularseed's style convention.

Refactors subsonic service's getStarred method to use angular $http and to limit results on the client side since we can't do it with Subsonic's API.

Adds a working unit test for this new method.
This commit is contained in:
Hyzual 2014-11-04 23:15:07 +01:00
parent fb8bf0ef24
commit 2c6276cced
8 changed files with 89 additions and 40 deletions

View file

@ -41,7 +41,7 @@ module.exports = function (grunt) {
}
},
jsTest: {
files: ['test/**/*.js'],
files: ['test/**/*_test.js'],
tasks: ['karma:continuous:run'], //'newer:jshint:test']
},
styles: {
@ -52,14 +52,14 @@ module.exports = function (grunt) {
files: ['Gruntfile.js']
},
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: [
'<%= yeoman.app %>/{,*/}*.html',
'.tmp/styles/{,*/}*.css',
'<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
]
},
options: {
livereload: '<%= connect.options.livereload %>'
}
},
@ -126,7 +126,7 @@ module.exports = function (grunt) {
options: {
jshintrc: 'test/.jshintrc'
},
src: ['test/spec/{,*/}*.js']
src: ['test/{,*/}*.js']
}
},

View file

@ -427,7 +427,7 @@ Jamstash.factory('subsonic', function ($rootScope, $http, $q, globals, utils, ma
if (genre !== '' && genre != 'Random') {
genreParams = '&genre=' + genre;
}
folderParams = '';
var folderParams = '';
if (typeof folder == 'number' && folder !== '' && folder != 'all') {
//alert(folder);
folderParams = '&musicFolderId=' + folder;
@ -556,6 +556,30 @@ Jamstash.factory('subsonic', function ($rootScope, $http, $q, globals, utils, ma
});
return deferred.promise;
},
getStarred: function (action, type) {
var deferred = $q.defer();
// TODO: JMA: GET variant
$http.jsonp(globals.BaseURL() + '/getStarred.view?callback=JSON_CALLBACK&' + globals.BaseParams(),
{
timeout: globals.settings.Timeout
})
.success(function(data, status) {
console.log("blu");
console.log(data);
if(data['subsonic-response'] !== undefined && data['subsonic-response'].status === 'ok') {
console.log('green');
// Return only first X starred songs
var starredSongs = data['subsonic-response'].starred.song.slice(0, globals.settings.AutoPlaylistSize);
deferred.resolve(starredSongs);
} else {
deferred.reject();
}
}).error(function(data, status) {
deferred.reject();
});
return deferred.promise;
},
/*
getStarred: function (action, type) {
var deferred = $q.defer();
var size = globals.settings.AutoPlaylistSize;
@ -621,11 +645,13 @@ Jamstash.factory('subsonic', function ($rootScope, $http, $q, globals, utils, ma
break;
}
}
console.log("getStarred: ", content);
deferred.resolve(content);
}
});
return deferred.promise;
},
*/
newPlaylist: function (data, event) {
var deferred = $q.defer();
var reply = prompt("Choose a name for your new playlist.", "");

View file

@ -70,7 +70,7 @@ jamstash.service('utils', function ($rootScope, $cookieStore, globals) {
this.switchTheme = function (theme) {
switch (theme.toLowerCase()) {
case 'dark':
$('link[data-name=theme]').attr('href', 'style/Dark.css');
$('link[data-name=theme]').attr('href', 'styles/Dark.css');
break;
case 'default':
$('link[data-name=theme]').attr('href', '');

View file

@ -1,4 +1,4 @@
describe("Subsonic controller", function() {
'use strict';
});

View file

@ -29,7 +29,7 @@ module.exports = function(config) {
'bower_components/jplayer/jquery.jplayer/jquery.jplayer.js',
'bower_components/notify.js/notify.js',
'js/**/*.js',
'test/**/*.js'
'test/**/*_test.js'
],
// list of files / patterns to exclude
@ -64,7 +64,7 @@ module.exports = function(config) {
// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel: config.LOG_INFO,
logLevel: config.LOG_INFO
// Uncomment the following lines if you are using grunt's server to run the tests
// proxies: {

View file

@ -7,12 +7,12 @@ describe("globals service", function() {
globals = _globals_;
}));
it("given 'http://subsonic.org/demo', when calling BaseURL() then I get 'http://subsonic.org/demo/rest'", function() {
it("Given 'http://subsonic.org/demo', when calling BaseURL() then I get 'http://subsonic.org/demo/rest'", function() {
globals.settings.Server = "http://subsonic.org/demo";
expect(globals.BaseURL()).toBe("http://subsonic.org/demo/rest");
});
it("given a username, password, protocol, api version and application name, when calling BaseParams() then I get a concatenated string of url params", function () {
it("Given a username, password, protocol, api version and application name, when calling BaseParams() then I get a concatenated string of url params", function () {
globals.settings.Username = "jdoe";
globals.settings.Password = "testpassword";
globals.settings.Protocol = "jsonp";
@ -20,4 +20,6 @@ describe("globals service", function() {
globals.settings.ApplicationName = "MyApp";
expect(globals.BaseParams()).toBe("u=jdoe&p=testpassword&f=jsonp&v=1.10.2&c=MyApp");
});
//TODO: JMA: add callback param if jsonp
});

View file

@ -1,15 +0,0 @@
describe("subsonicService", function() {
'use strict';
/*
var Subsonic;
beforeEach(module('JamStash'));
beforeEach(inject(function (subsonic) {
Subsonic = subsonic;
}));
it("should exist", inject(function(subsonic) {
expect(subsonic).toBeDefined();
}));
*/
});

View file

@ -1,15 +1,51 @@
describe("subsonicService", function() {
'use strict';
/*
var Subsonic;
beforeEach(module('JamStash'));
beforeEach(inject(function (subsonic) {
Subsonic = subsonic;
}));
describe("subsonic service -", function() {
'use strict';
it("should exist", inject(function(subsonic) {
expect(subsonic).toBeDefined();
}));
*/
var subsonic, mockBackend;
describe("Given that the global setting AutoPlaylist Size is 3", function() {
var mockGlobals = {
settings: {
AutoPlaylistSize: 3,
protocol: 'jsonp'
},
BaseURL: function () {
return 'http://subsonic.furinax.com/rest';
},
BaseParams: function () {
return 'u=Hyzual&p=enc:7375622e6461726b353079306432&v=1.10.2&c=Jamstash&f=jsonp';
}
};
beforeEach(function() {
module('JamStash', function ($provide) {
$provide.value('globals', mockGlobals);
});
inject(function (_subsonic_, $httpBackend) {
subsonic = _subsonic_;
mockBackend = $httpBackend;
});
});
afterEach(function() {
mockBackend.verifyNoOutstandingExpectation();
mockBackend.verifyNoOutstandingRequest();
});
it("and given that I have more than 3 starred songs in my library, when getting the starred artists, the result should be limited to 3 starred artists", function() {
var url = 'http://subsonic.furinax.com/rest/getStarred.view?'+
'callback=JSON_CALLBACK&u=Hyzual&p=enc:7375622e6461726b353079306432&v=1.10.2&c=Jamstash&f=jsonp';
var response = '{"subsonic-response": {"status": "ok","version": "1.10.2","starred": {"song": [{"id": "11841"},{"id": "12061"},{"id": "17322"},{"id": "1547"}]}}}';
var limitedStarred = [{id: "11841"},{id: "12061"},{id: "17322"}];
mockBackend.whenJSONP(url).respond(200, response);
var success = jasmine.createSpy('success');
subsonic.getStarred().then(success);
mockBackend.flush();
expect(success).toHaveBeenCalledWith(limitedStarred);
});
});
});