Jamstash/app/common/model-service_test.js
Hyzual 841336cafd Refactors subsonic-service's search() to use subsonicRequest()
So we can move closer to consistent error-reporting and protocol usage.
- refactors subonic-controller's search().
- Adds a mapAlbumss() method to model-service.js. Just as mapSongs(), it maps an array of albums and returns it.
- Refactors the SearchTypes so their id is an int (0,1,2), just like we already expected it in subsonic-service. This means it might invalidate the existing setting saved in localStorage, so people would have an empty option selected by default until they save their settings.
- Adds unit-tests.
2015-03-24 18:35:48 +01:00

70 lines
2.6 KiB
JavaScript

describe("model service", function() {
'use strict';
var model, map;
beforeEach(function() {
module('jamstash.model');
inject(function (_model_, _map_) {
model = _model_;
map = _map_;
});
});
it("given all the arguments, when calling Song() then the composite attributes are computed", function() {
model.Song(21, 43, 3, "Know Your Enemy", "Yoko Kanno", "27", "Ghost in the Shell - Stand Alone Complex OST 3",
"51", "cover.jpg", "big-cover.jpg", "385", "5", true, "mp3", "specs", "url", "0", "Awesome track");
expect(model.selected).toBe(false);
expect(model.playing).toBe(false);
expect(model.time).toBe("06:25");
expect(model.displayName).toBe("Know Your Enemy - Ghost in the Shell - Stand Alone Complex OST 3 - Yoko Kanno");
});
it("Given multiple songs, when I map them, then mapSong is called for each song", function() {
var songs = [
{ id: 2912 },
{ id: 1450 },
{ id: 6663 }
];
spyOn(map, 'mapSong').and.callFake(function (song) { return song; });
var result = map.mapSongs(songs);
expect(map.mapSong.calls.count()).toEqual(3);
expect(map.mapSong).toHaveBeenCalledWith({id: 2912});
expect(map.mapSong).toHaveBeenCalledWith({id: 1450});
expect(map.mapSong).toHaveBeenCalledWith({id: 6663});
expect(result).toEqual(songs);
});
it("Given multiple podcast episodes, when I map them, then mapPodcast is called for each episode", function() {
var episodes = [
{ id: 63 },
{ id: 24 },
{ id: 80 }
];
spyOn(map, 'mapPodcast').and.callFake(function (episode) { return episode; });
var result = map.mapPodcasts(episodes);
expect(map.mapPodcast.calls.count()).toEqual(3);
expect(map.mapPodcast).toHaveBeenCalledWith({ id: 63 });
expect(map.mapPodcast).toHaveBeenCalledWith({ id: 24 });
expect(map.mapPodcast).toHaveBeenCalledWith({ id: 80 });
expect(result).toEqual(episodes);
});
it("Given multiple albums, when I map them, then mapAlbum is called for each album", function() {
var albums = [
{ id: 941 },
{ id: 967 },
{ id: 545 }
];
spyOn(map, 'mapAlbum').and.callFake(function (album) { return album; });
var result = map.mapAlbums(albums);
expect(map.mapAlbum.calls.count()).toEqual(3);
expect(map.mapAlbum).toHaveBeenCalledWith({ id: 941 });
expect(map.mapAlbum).toHaveBeenCalledWith({ id: 967 });
expect(map.mapAlbum).toHaveBeenCalledWith({ id: 545 });
expect(result).toEqual(albums);
});
});