Skip to content

Commit 44c7c02

Browse files
committed
Testing with promises sucks. Karma seems to interfere. Also, inserting all episodes takes too long apparently. slimmed it down to one episode per season.
1 parent c4efd1a commit 44c7c02

13 files changed

+71
-90
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"single-instance": true,
7272
"node-main": "",
7373
"scripts": {
74-
"test": "node_modules/.bin/karma start --single-run --browsers PhantomJS",
74+
"test": "node_modules/.bin/karma start --single-run --browsers Chrome",
7575
"test-watch": "node_modules/.bin/karma start --no-single-run --auto-watch --browsers PhantomJS"
7676
}
7777
}

tests/FavoritesService.test.js

+56-79
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
describe('FavoritesService', function() {
2323

24-
var FavoritesService, TraktTVv2, $httpBackend;
24+
var FavoritesService, TraktTVv2, $httpBackend, $q, $rootScope, $scope;
2525

2626
beforeEach(module('DuckieTV.providers.favorites'));
2727
beforeEach(module('DuckieTV.providers.trakttvv2'));
@@ -40,8 +40,14 @@ describe('FavoritesService', function() {
4040
FavoritesService = _FavoritesService_;
4141
TraktTVv2 = _TraktTVv2_;
4242
$httpBackend = _$httpBackend_;
43+
44+
}));
45+
46+
afterEach(inject(function($rootScope) {
47+
$rootScope.$apply();
4348
}));
4449

50+
4551
describe('It should be initialized', function() {
4652

4753
it('should have a favorites property', function() {
@@ -52,103 +58,74 @@ describe('FavoritesService', function() {
5258
FavoritesService.getSeries().then(function(result) {
5359
expect(angular.isArray(result)).toBe(true);
5460
});
55-
5661
});
5762

5863
});
5964

6065
describe("It should be able to add Doctor Who to the database", function() {
6166

62-
it('Should be able to add Doctor Who from a parsed search result', function() {
67+
it('Should be able to add Doctor Who from a parsed search result', function(done) {
68+
var serie = null;
6369
TraktTVv2.serie('doctor-who-2005').then(function(searchResults) {
64-
expect(searchResults.title).toMatch('Doctor Who');
6570
return searchResults;
66-
}).then(FavoritesService.addFavorite).then(function(serie) {
67-
expect(
68-
serie.id !== false &&
69-
serie.banner == '' &&
70-
serie.overview == '' &&
71-
serie.TVDB_ID == '' &&
72-
serie.networkid == '' &&
73-
serie.actors == '' &&
74-
serie.airs_dayofweek == '' &&
75-
serie.airs_time == '' &&
76-
serie.contentrating == '' &&
77-
serie.firstaired == '' &&
78-
serie.genre == '' &&
79-
serie.language == '' &&
80-
serie.network == '' &&
81-
serie.rating == '' &&
82-
serie.ratingcount == '' &&
83-
serie.runtime == '' &&
84-
serie.status == '' &&
85-
serie.fanart == '' &&
86-
serie.poster == '' &&
87-
serie.displaycalendar == 1).toBe(true);
88-
/** merge this
89-
air_day: "Saturday"
90-
air_day_utc: "Saturday"
91-
air_time: "20:30"
92-
air_time_utc: "20:30"
93-
certification: "TV-PG"
94-
country: "gb"
95-
first_aired: 1111869000
96-
first_aired_iso: "2005-03-26T12:30:00-08:00"
97-
first_aired_utc: 1111869000
98-
genres: ["action", "adventure", "drama", "science fiction"]
99-
images: {,…}
100-
banner: "https://walter.trakt.us/images/shows/000/056/872/banners/original/eb6561d0ee.jpg?1420722414"
101-
fanart: "https://walter.trakt.us/images/shows/000/056/872/fanarts/original/f5b14363ae.jpg?1420722413"
102-
poster: "https://walter.trakt.us/images/shows/000/056/872/posters/original/8c421e339d.jpg?1420722412"
103-
imdb_id: "tt0436992"
104-
in_watchlist: false
105-
last_updated: 1421256819
106-
network: "BBC One"
107-
overview: "The Doctor is an alien Time Lord from the planet Gallifrey who travels through all of time and space in his TARDIS. His current travel companion is Clara Oswald, though he has a long list of friends and companions who have shared journeys with him. Instead of dying, the Doctor is able to “regenerate” into a new body, taking on a new personality with each regeneration. Twelve actors, plus John Hurt, have played The Doctor thus far."
108-
people: {actors: [{name: "Peter Capaldi", images: {,…}, character: "The Doctor"},…]}
109-
actors: [{name: "Peter Capaldi", images: {,…}, character: "The Doctor"},…]
110-
poster: "https://walter.trakt.us/images/shows/000/056/872/posters/original/8c421e339d.jpg?1420722412"
111-
rating: false
112-
rating_advanced: false
113-
ratings: {percentage: 91, votes: 10210, loved: 0, hated: 0}
114-
runtime: 50
115-
seasons: [{season: 9, episodes: [,…]}, {season: 8,…},…]
116-
stats: {watchers: 0, plays: 0, scrobbles: 0, scrobbles_unique: 0, checkins: 0, checkins_unique: 0,…}
117-
checkins: 0
118-
checkins_unique: 0
119-
collection: 0
120-
collection_unique: 0
121-
plays: 0
122-
scrobbles: 0
123-
scrobbles_unique: 0
124-
watchers: 0
125-
status: "returning series"
126-
title: "Doctor Who"
127-
top_episodes: null
128-
top_watchers: null
129-
tvdb_id: 78804
130-
tvrage_id: 3332
131-
url: "http://trakt.tv/shows/doctor-who-2005"
132-
year: 2005
133-
*/
134-
71+
}).then(function(result) {
72+
return FavoritesService.addFavorite(result);
73+
}).then(function(serie) {
74+
expect(serie).toEqual(true);
75+
done();
13576
});
13677

13778
$httpBackend.flush();
79+
80+
13881
});
13982

140-
it('should have added 10 seasons', function() {
141-
CRUD.Find(Season, {
83+
it('Shoud have finished adding it', function() {
84+
var serie = null;
85+
CRUD.FindOne('Serie', {
86+
name: 'Doctor Who'
87+
}).then(function(serie) {
88+
89+
expect(
90+
serie.overview == "The Doctor is an alien Time Lord from the planet Gallifrey who travels through all of time and space in his TARDIS. His current travel companion is Clara Oswald, though he has a long list of friends and companions who have shared journeys with him. Instead of dying, the Doctor is able to “regenerate” into a new body, taking on a new personality with each regeneration. Twelve actors, plus John Hurt, have played The Doctor thus far." &&
91+
serie.runtime == 50 &&
92+
serie.network == 'BBC One' &&
93+
serie.status == 'Continuing' &&
94+
serie.rating == 9.11989 &&
95+
serie.language == 'gb' &&
96+
serie.fanart == 'https://walter.trakt.us/images/shows/000/056/872/fanarts/original/f5b14363ae.jpg?1420722413' &&
97+
serie.poster == 'https://walter.trakt.us/images/shows/000/056/872/posters/thumb/8c421e339d.jpg?1420722412' &&
98+
serie.banner == 'https://walter.trakt.us/images/shows/000/056/872/banners/original/eb6561d0ee.jpg?1420722414' &&
99+
serie.TVDB_ID == 78804 &&
100+
serie.TVRage_ID == 3332 &&
101+
serie.IMDB_ID == 'tt0436992' &&
102+
serie.contentrating == 'TV-PG' &&
103+
serie.name == 'Doctor Who' &&
104+
/* serie.firstaired == NaN && */
105+
serie.ratingcount == 10176 &&
106+
serie.genre == 'action|adventure|drama|science-fiction' &&
107+
serie.ID_Serie == 1
108+
).toBe(true);
109+
done();
110+
});
111+
112+
});
113+
114+
it("Should have added 10 seasons", function(done) {
115+
116+
CRUD.FindOne('Season', {
142117
Serie: {
143-
name: 'Doctor Who'
118+
title: 'Doctor Who'
144119
}
145-
}).then(function(seasons) {
146-
expect(seasons.length == 9).toBe(true);
147-
return seasons;
120+
}).then(function(result) {
121+
expect(result.length).toEqual(9);
122+
done();
148123
});
149124

125+
150126
});
151127

128+
152129
it('should have added xx episodes', function() {
153130
expect(false).toBe(true); // placeholder
154131
});

tests/fixtures/httpsapitrakttvshowsdoctorwho2005seasons0episodesextendedfullimages.json

+1-1
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)