Skip to content

Commit

Permalink
Added tests for Spotify.getUser
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiemoore committed Sep 3, 2014
1 parent 1fc423a commit f6ba0e4
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions test/spec/angular-spotify.spec.js
Expand Up @@ -916,6 +916,64 @@ describe('angular-spotify', function () {

});

describe('User Profiles', function() {
var $httpBackend;
var Spotify;
var api = 'https://api.spotify.com/v1';

beforeEach(inject(function(_Spotify_, _$httpBackend_) {
Spotify = _Spotify_;
$httpBackend = _$httpBackend_;
}));

describe('Spotify.getUser', function() {
it('should make an ajax call to https://api.spotify.com/v1/users/{id}', function () {

$httpBackend.when('GET', api + '/users/wizzler').respond({});

expect(Spotify.getUser('wizzler')).toBeDefined();
});

it('should resolve to an object of a user', function () {
$httpBackend.when('GET', api + '/users/wizzler').respond(200, { });

var promise = Spotify.getUser('wizzler'),
result;

promise.then(function (data) {
result = data;
});

$httpBackend.flush();
expect(result).toBeDefined();
expect(result instanceof Object).toBeTruthy();
});

it('should reject the promise and respond with error', function () {
$httpBackend.when('GET', api + '/users/:":ADSAD').respond(404, {
'error': {
'status': 404,
'message': 'No such user'
}
});

var promise = Spotify.getUser(':":ADSAD'),
result;

promise.then(function (data) {
result = data;
}, function (reason) {
result = reason;
});

$httpBackend.flush();
expect(result).toBeDefined();
expect(result instanceof Object).toBeTruthy();
expect(result.error.status).toBe(404);
});
});
});

});

});

0 comments on commit f6ba0e4

Please sign in to comment.