Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
edoparearyee committed Jun 1, 2017
1 parent 1b57a75 commit ee75e92
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 52 deletions.
4 changes: 2 additions & 2 deletions app/js/api/factories/PlayerSpotifyAlbumResource.js
Expand Up @@ -22,7 +22,7 @@ angular.module("FM.api.PlayerSpotifyAlbumResource", [
function ($resource, env) {

return $resource(
env.FM_API_SERVER_ADDRESS + "spotify/album/:id",
env.FM_API_SERVER_ADDRESS + "spotify/albums/:id",
{
id: "@id"
},
Expand All @@ -32,7 +32,7 @@ angular.module("FM.api.PlayerSpotifyAlbumResource", [
},
getTracks: {
method: "GET",
url: env.FM_API_SERVER_ADDRESS + "spotify/album/:id/tracks",
url: env.FM_API_SERVER_ADDRESS + "spotify/albums/:id/tracks",
}
}
);
Expand Down
4 changes: 2 additions & 2 deletions app/js/api/factories/PlayerSpotifyArtistResource.js
Expand Up @@ -22,7 +22,7 @@ angular.module("FM.api.PlayerSpotifyArtistResource", [
function ($resource, env) {

return $resource(
env.FM_API_SERVER_ADDRESS + "spotify/artist/:id",
env.FM_API_SERVER_ADDRESS + "spotify/artists/:id",
{
id: "@id"
},
Expand All @@ -32,7 +32,7 @@ angular.module("FM.api.PlayerSpotifyArtistResource", [
},
getAlbums: {
method: "GET",
url: env.FM_API_SERVER_ADDRESS + "spotify/artist/:id/albums",
url: env.FM_API_SERVER_ADDRESS + "spotify/artists/:id/albums",
}
}
);
Expand Down
2 changes: 1 addition & 1 deletion app/js/api/factories/RequestInterceptor.js
Expand Up @@ -119,7 +119,7 @@ angular.module("FM.api.RequestInterceptor", [
AlertService.set(ERRORS.STATUS_404_MESSAGE, "info");
break;
default:
AlertService.set(response.statusText + ": " + response.data && response.data.message ? response.data.message: "There was an error", "warning");
AlertService.set(response.statusText + ": " + (response.data && response.data.message ? response.data.message: "There was an error"), "warning");
break;
}

Expand Down
9 changes: 5 additions & 4 deletions app/js/search/controllers/AlbumDetailCtrl.js
Expand Up @@ -49,11 +49,11 @@ angular.module("FM.search.AlbumDetailCtrl", [
*/
.controller("AlbumDetailCtrl", [
"$scope",
"Spotify",
"PlayerSpotifyAlbumResource",
"album",
"albumTracks",
"env",
function ($scope, Spotify, album, albumTracks, env) {
function ($scope, PlayerSpotifyAlbumResource, album, albumTracks, env) {

/**
* Album data
Expand Down Expand Up @@ -88,10 +88,11 @@ angular.module("FM.search.AlbumDetailCtrl", [
*/
$scope.loadMore = function loadMore(){
$scope.loadDisabled = true;
Spotify.getAlbumTracks($scope.album.id, {
PlayerSpotifyAlbumResource.getTracks({
id: $scope.album.id,
limit: env.SEARCH_LIMIT,
offset: $scope.albumTracks.length
}).then(function (response) {
}).$promise.then(function (response) {
$scope.albumTracks = $scope.albumTracks.concat(response.items);
$scope.meta = response;
$scope.loadDisabled = false;
Expand Down
10 changes: 6 additions & 4 deletions app/js/search/controllers/AlbumSearchCtrl.js
Expand Up @@ -48,10 +48,10 @@ angular.module("FM.search.AlbumSearchCtrl", [
.controller("AlbumSearchCtrl", [
"$scope",
"$location",
"Spotify",
"PlayerSpotifySearchResource",
"search",
"env",
function ($scope, $location, Spotify, search, env) {
function ($scope, $location, PlayerSpotifySearchResource, search, env) {

/**
* Route search params
Expand Down Expand Up @@ -86,11 +86,13 @@ angular.module("FM.search.AlbumSearchCtrl", [
*/
$scope.loadMore = function loadMore(){
$scope.loadDisabled = true;
Spotify.search($scope.search.query, "album", {
PlayerSpotifySearchResource.query({
q: $scope.search.query + "*",
type: "album",
limit: env.SEARCH_LIMIT,
offset: $scope.albums.length,
market: env.REGION_CODE
}).then(function (response) {
}).$promise.then(function (response) {
$scope.albums = $scope.albums.concat(response.albums.items);
$scope.meta = response.albums;
$scope.loadDisabled = false;
Expand Down
14 changes: 8 additions & 6 deletions app/js/search/controllers/ArtistDetailCtrl.js
Expand Up @@ -74,14 +74,14 @@ angular.module("FM.search.ArtistDetailCtrl", [
.controller("ArtistDetailCtrl", [
"$scope",
"$location",
"Spotify",
"PlayerSpotifyArtistResource",
"artist",
"albums",
"singles",
"topTracks",
"relatedArtists",
"env",
function ($scope, $location, Spotify, artist, albums, singles, topTracks, relatedArtists, env) {
function ($scope, $location, PlayerSpotifyArtistResource, artist, albums, singles, topTracks, relatedArtists, env) {

/**
* Artist data
Expand Down Expand Up @@ -143,12 +143,13 @@ angular.module("FM.search.ArtistDetailCtrl", [
*/
$scope.loadMoreSingles = function loadMoreSingles(){
$scope.loadDisabled = true;
Spotify.getArtistAlbums($scope.artist.id, {
PlayerSpotifyArtistResource.getAlbums({
id: $scope.artist.id,
limit: env.SEARCH_LIMIT,
album_type: "single", // jshint ignore:line
offset: $scope.singles.length,
country: env.REGION_CODE
}).then(function (response) {
}).$promise.then(function (response) {
$scope.singles = $scope.singles.concat(response.items);
$scope.singlesMeta = response;
$scope.loadDisabled = false;
Expand All @@ -161,12 +162,13 @@ angular.module("FM.search.ArtistDetailCtrl", [
*/
$scope.loadMoreAlbums = function loadMoreAlbums(){
$scope.loadDisabled = true;
Spotify.getArtistAlbums($scope.artist.id, {
PlayerSpotifyArtistResource.getAlbums({
id: $scope.artist.id,
limit: env.SEARCH_LIMIT,
album_type: "album", // jshint ignore:line
offset: $scope.albums.length,
country: env.REGION_CODE
}).then(function (response) {
}).$promise.then(function (response) {
$scope.albums = $scope.albums.concat(response.items);
$scope.albumsMeta = response;
$scope.loadDisabled = false;
Expand Down
10 changes: 6 additions & 4 deletions app/js/search/controllers/ArtistSearchCtrl.js
Expand Up @@ -48,10 +48,10 @@ angular.module("FM.search.ArtistSearchCtrl", [
.controller("ArtistSearchCtrl", [
"$scope",
"$location",
"Spotify",
"PlayerSpotifySearchResource",
"search",
"env",
function ($scope, $location, Spotify, search, env) {
function ($scope, $location, PlayerSpotifySearchResource, search, env) {

/**
* Route search params
Expand Down Expand Up @@ -86,11 +86,13 @@ angular.module("FM.search.ArtistSearchCtrl", [
*/
$scope.loadMore = function loadMore(){
$scope.loadDisabled = true;
Spotify.search($scope.search.query, "artist", {
PlayerSpotifySearchResource.query({
id: $scope.search.query,
type: "artist",
limit: env.SEARCH_LIMIT,
offset: $scope.artists.length,
market: env.REGION_CODE
}).then(function (response) {
}).$promise.then(function (response) {
$scope.artists = $scope.artists.concat(response.artists.items);
$scope.meta = response.artists;
$scope.loadDisabled = false;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -18,7 +18,7 @@
"grunt-contrib-concat": "~0.5.1",
"grunt-contrib-connect": "~0.11.2",
"grunt-contrib-copy": "~0.8.0",
"grunt-contrib-jasmine": "~0.9.2",
"grunt-contrib-jasmine": "~1.1.0",
"grunt-contrib-jshint": "~0.11.1",
"grunt-contrib-less": "~1.0.1",
"grunt-contrib-uglify": "~0.9.1",
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/search/controllers/AlbumDetailCtrl.js
Expand Up @@ -2,7 +2,7 @@

describe("FM.search.AlbumDetailCtrl", function() {

var $scope, $route, $rootScope, $httpBackend, Spotify, $location, album, tracks;
var $scope, $route, $rootScope, $httpBackend, PlayerSpotifyAlbumResource, $location, album, tracks;

beforeEach(function (){
module("FM.search.AlbumDetailCtrl");
Expand All @@ -11,8 +11,8 @@ describe("FM.search.AlbumDetailCtrl", function() {
beforeEach(inject(function (_$httpBackend_) {
$httpBackend = _$httpBackend_;
$httpBackend.whenGET(/partials\/.*/).respond(200, "");
$httpBackend.whenGET(/api.spotify.com\/v1\/albums\/.*\/tracks/).respond(200, { items: [{},{}] });
$httpBackend.whenGET(/api.spotify.com\/v1\/albums\/.*/).respond(200, { id: "123" });
$httpBackend.whenGET(/.*\/albums\/.*\/tracks/).respond(200, { items: [{},{}] });
$httpBackend.whenGET(/.*\/albums\/.*/).respond(200, { id: "123" });
}));

beforeEach(inject(function ( _$location_, _$route_, _$rootScope_, $injector, $controller ) {
Expand All @@ -23,7 +23,7 @@ describe("FM.search.AlbumDetailCtrl", function() {

$location = $injector.get("$location");

Spotify = $injector.get("Spotify");
PlayerSpotifyAlbumResource = $injector.get("PlayerSpotifyAlbumResource");

tracks = {
items: [{},{}]
Expand All @@ -36,7 +36,7 @@ describe("FM.search.AlbumDetailCtrl", function() {
$controller("AlbumDetailCtrl", {
$scope: $scope,
$location: $location,
Spotify: Spotify,
PlayerSpotifyAlbumResource: PlayerSpotifyAlbumResource,
album: album,
albumTracks: tracks
});
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/search/controllers/AlbumSearchCtrl.js
Expand Up @@ -2,7 +2,7 @@

describe("FM.search.AlbumSearchCtrl", function() {

var $scope, $route, $rootScope, $httpBackend, Spotify, $location, search;
var $scope, $route, $rootScope, $httpBackend, PlayerSpotifySearchResource, $location, search;

beforeEach(function (){
module("FM.search.AlbumSearchCtrl");
Expand All @@ -11,7 +11,7 @@ describe("FM.search.AlbumSearchCtrl", function() {
beforeEach(inject(function (_$httpBackend_) {
$httpBackend = _$httpBackend_;
$httpBackend.whenGET(/partials\/.*/).respond(200, "");
$httpBackend.whenGET(/api.spotify.com\/v1\/search.*/).respond(200, { albums: { items: [{},{}] }});
$httpBackend.whenGET(/.*\/search.*/).respond(200, { albums: { items: [{},{}] }});
}));

beforeEach(inject(function ( _$location_, _$route_, _$rootScope_, $injector, $controller ) {
Expand All @@ -22,7 +22,7 @@ describe("FM.search.AlbumSearchCtrl", function() {

$location = $injector.get("$location");

Spotify = $injector.get("Spotify");
PlayerSpotifySearchResource = $injector.get("PlayerSpotifySearchResource");

search = {
albums: {
Expand All @@ -33,7 +33,7 @@ describe("FM.search.AlbumSearchCtrl", function() {
$controller("AlbumSearchCtrl", {
$scope: $scope,
$location: $location,
Spotify: Spotify,
PlayerSpotifySearchResource: PlayerSpotifySearchResource,
search: search
});
}));
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/search/controllers/ArtistDetailCtrl.js
Expand Up @@ -2,7 +2,7 @@

describe("FM.search.ArtistDetailCtrl", function() {

var $scope, $route, $rootScope, $httpBackend, Spotify, $location,
var $scope, $route, $rootScope, $httpBackend, PlayerSpotifyArtistResource, $location,
artist, artists, albums, singles, topTracks;

beforeEach(function (){
Expand All @@ -19,9 +19,9 @@ describe("FM.search.ArtistDetailCtrl", function() {

$httpBackend.whenGET(/partials\/.*/).respond(200, "");
$httpBackend.whenGET(/api.spotify.com\/v1\/artists\/.*\/top-tracks/).respond(200, topTracks);
$httpBackend.whenGET(/api.spotify.com\/v1\/artists\/.*\/related-artists/).respond(200, artists);
$httpBackend.whenGET(/api.spotify.com\/v1\/artists\/.*\/albums/).respond(200, albums);
$httpBackend.whenGET(/api.spotify.com\/v1\/artists\/.*/).respond(200, artist);
$httpBackend.whenGET(/.*\/artists\/.*\/related-artists/).respond(200, artists);
$httpBackend.whenGET(/.*\/artists\/.*\/albums/).respond(200, albums);
$httpBackend.whenGET(/.*\/artists\/.*/).respond(200, artist);
}));

beforeEach(inject(function ( _$location_, _$route_, _$rootScope_, $injector, $controller ) {
Expand All @@ -32,12 +32,12 @@ describe("FM.search.ArtistDetailCtrl", function() {

$location = $injector.get("$location");

Spotify = $injector.get("Spotify");
PlayerSpotifyArtistResource = $injector.get("PlayerSpotifyArtistResource");

$controller("ArtistDetailCtrl", {
$scope: $scope,
$location: $location,
Spotify: Spotify,
PlayerSpotifyArtistResource: PlayerSpotifyArtistResource,
artist: artist,
albums: albums,
singles: albums,
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/search/controllers/ArtistSearchCtrl.js
Expand Up @@ -2,7 +2,7 @@

describe("FM.search.ArtistSearchCtrl", function() {

var $scope, $route, $rootScope, $httpBackend, Spotify, $location, search;
var $scope, $route, $rootScope, $httpBackend, PlayerSpotifySearchResource, $location, search;

beforeEach(function (){
module("FM.search.ArtistSearchCtrl");
Expand All @@ -11,7 +11,7 @@ describe("FM.search.ArtistSearchCtrl", function() {
beforeEach(inject(function (_$httpBackend_) {
$httpBackend = _$httpBackend_;
$httpBackend.whenGET(/partials\/.*/).respond(200, "");
$httpBackend.whenGET(/api.spotify.com\/v1\/search.*/).respond(200, { artists: { items: [{},{}] }});
$httpBackend.whenGET(/.*\/search.*/).respond(200, { artists: { items: [{},{}] }});
}));

beforeEach(inject(function ( _$location_, _$route_, _$rootScope_, $injector, $controller ) {
Expand All @@ -22,7 +22,7 @@ describe("FM.search.ArtistSearchCtrl", function() {

$location = $injector.get("$location");

Spotify = $injector.get("Spotify");
PlayerSpotifySearchResource = $injector.get("PlayerSpotifySearchResource");

search = {
artists: {
Expand All @@ -33,7 +33,7 @@ describe("FM.search.ArtistSearchCtrl", function() {
$controller("ArtistSearchCtrl", {
$scope: $scope,
$location: $location,
Spotify: Spotify,
PlayerSpotifySearchResource: PlayerSpotifySearchResource,
search: search
});
}));
Expand Down
20 changes: 11 additions & 9 deletions tests/unit/search/controllers/SearchCtrl.js
Expand Up @@ -2,7 +2,7 @@

describe("FM.search.SearchCtrl", function() {

var $scope, $rootScope, $location, $httpBackend, $q, FM_API_SERVER_ADDRESS, Spotify, PlayerQueueResource, searchResults;
var $scope, $rootScope, $location, $httpBackend, $q, FM_API_SERVER_ADDRESS, PlayerSpotifySearchResource, PlayerQueueResource, searchResults;

beforeEach(function (){
module("FM.search.SearchCtrl");
Expand All @@ -19,8 +19,8 @@ describe("FM.search.SearchCtrl", function() {
}

$httpBackend.whenGET(/partials\/.*/).respond(200, "");
$httpBackend.whenGET(/api.spotify.com\/v1\/search.*/).respond(200, searchResults);
$httpBackend.whenGET(/api.spotify.com\/v1\/albums.*/).respond(200, searchResults.albums.items[0]);
$httpBackend.whenGET(/.*\/search.*/).respond(200, searchResults);
$httpBackend.whenGET(/.*\/albums.*/).respond(200, searchResults.albums.items[0]);
$httpBackend.whenPOST(FM_API_SERVER_ADDRESS + "player/queue").respond(200);
}));

Expand All @@ -33,10 +33,12 @@ describe("FM.search.SearchCtrl", function() {
$q = $injector.get("$q");
$location = $injector.get("$location");

Spotify = $injector.get("Spotify");
spyOn(Spotify, "search").and.callFake(function() {
PlayerSpotifySearchResource = $injector.get("PlayerSpotifySearchResource");
spyOn(PlayerSpotifySearchResource, "query").and.callFake(function() {
return {
then: function(callback) { return callback(searchResults); }
$promise: {
then: function(callback) { return callback(searchResults); }
}
};
});

Expand All @@ -48,7 +50,7 @@ describe("FM.search.SearchCtrl", function() {
$rootScope: $rootScope,
$q: $q,
$location: $location,
Spotify: Spotify,
PlayerSpotifySearchResource: PlayerSpotifySearchResource,
PlayerQueueResource: PlayerQueueResource
});
}));
Expand All @@ -62,7 +64,7 @@ describe("FM.search.SearchCtrl", function() {
$scope.search("foo");
$httpBackend.flush();
$rootScope.$digest();
expect(Spotify.search).toHaveBeenCalled();
expect(PlayerSpotifySearchResource.query).toHaveBeenCalled();

searchResults = {
artists: undefined,
Expand All @@ -71,7 +73,7 @@ describe("FM.search.SearchCtrl", function() {
}
$scope.search("foo");
$rootScope.$digest();
expect(Spotify.search.calls.count()).toBe(2);
expect(PlayerSpotifySearchResource.query.calls.count()).toBe(2);
});

it("should add selected song to playlist", function() {
Expand Down

0 comments on commit ee75e92

Please sign in to comment.