From 8c95e9398698fda1d6ce36b1b564b05783444406 Mon Sep 17 00:00:00 2001 From: jdat82 Date: Thu, 21 Jul 2016 10:27:14 +0200 Subject: [PATCH] =?UTF-8?q?bugfix/tests=20=E2=80=94=20Fixed=20unit=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/character/character.factory.js | 2 ++ app/character/character.factory.spec.js | 32 +++++++++---------- app/comic/comic.factory.spec.js | 30 ++++++++--------- app/common/utils/utils.factory.js | 1 + app/favourite/favourite.factory.js | 2 +- .../characters/{s_0.json => sp_0.json} | 2 +- .../characters/{s_20.json => sp_20.json} | 0 .../fixtures/comics/{s_0.json => sp_0.json} | 0 .../fixtures/comics/{s_20.json => sp_20.json} | 0 test/unit/global.js | 1 + 10 files changed, 35 insertions(+), 35 deletions(-) rename test/unit/fixtures/characters/{s_0.json => sp_0.json} (99%) rename test/unit/fixtures/characters/{s_20.json => sp_20.json} (100%) rename test/unit/fixtures/comics/{s_0.json => sp_0.json} (100%) rename test/unit/fixtures/comics/{s_20.json => sp_20.json} (100%) diff --git a/app/character/character.factory.js b/app/character/character.factory.js index c81d604..64dbd8e 100644 --- a/app/character/character.factory.js +++ b/app/character/character.factory.js @@ -21,6 +21,8 @@ function findByName(prefix, offset) { var criteria = {}; prefix && (criteria.nameStartsWith = prefix); + console.log('prefix:', prefix); + console.log('offset:', offset); offset && (criteria.offset = offset); return characters.getList(criteria).then(utils.cacheThumbnails); } diff --git a/app/character/character.factory.spec.js b/app/character/character.factory.spec.js index 23bad1f..bff6610 100644 --- a/app/character/character.factory.spec.js +++ b/app/character/character.factory.spec.js @@ -1,7 +1,7 @@ describe('characterService: ', function () { - var characterService, $httpBackend; - + var characterService, $httpBackend, prefix = 'sp'; + beforeEach(inject(function ($injector) { characterService = $injector.get('characterService'); $httpBackend = $injector.get('$httpBackend'); @@ -22,27 +22,25 @@ describe('characterService: ', function () { $httpBackend.flush(); }); - it('should have multiple pages', function (done) { - var fixture1 = readJSON(fixturesPath + '/characters/s_0.json'); - var fixture2 = readJSON(fixturesPath + '/characters/s_20.json'); + it('should get the twenty first results', function (done) { + var fixture1 = readJSON(fixturesPath + '/characters/sp_0.json'); $httpBackend.expectGET(/\/characters/).respond(fixture1); - $httpBackend.expectGET(/\/characters/).respond(fixture2); - var prefix = 'sp'; - var offset = 0; - var list = []; characterService.findByName(prefix).then(function (results) { expect(results).toBeTruthy(); expect(results.length).toBe(20); - list = list.concat(results); - }).then(function () { - offset = 20; - return characterService.findByName(prefix, offset); - }).then(function (results) { + expect(results[0].id).toBe(1009552); + done(); + }); + $httpBackend.flush(); + }); + + it('should get the remaining results', function(done){ + var fixture2 = readJSON(fixturesPath + '/characters/sp_20.json'); + $httpBackend.expectGET(/\/characters.*offset=20/).respond(fixture2); + characterService.findByName(prefix, 20).then(function (results) { expect(results).toBeTruthy(); expect(results.length).toBe(13); - expect(list[0].id).not.toBe(results[0].id); - list = list.concat(results); - expect(list.length).toBe(33); + expect(results[0].id).toBe(1016181); done(); }); $httpBackend.flush(); diff --git a/app/comic/comic.factory.spec.js b/app/comic/comic.factory.spec.js index b47fd34..bda5ae4 100644 --- a/app/comic/comic.factory.spec.js +++ b/app/comic/comic.factory.spec.js @@ -1,6 +1,6 @@ describe('comicService: ', function () { - var comicService, $httpBackend; + var comicService, $httpBackend, prefix = 'sp'; beforeEach(inject(function ($injector) { comicService = $injector.get('comicService'); @@ -22,27 +22,25 @@ describe('comicService: ', function () { $httpBackend.flush(); }); - it('should have multiple pages', function (done) { - var fixture1 = readJSON(fixturesPath + '/comics/s_0.json'); - var fixture2 = readJSON(fixturesPath + '/comics/s_20.json'); + it('should get the twenty first results', function (done) { + var fixture1 = readJSON(fixturesPath + '/comics/sp_0.json'); $httpBackend.expectGET(/\/comics/).respond(fixture1); - $httpBackend.expectGET(/\/comics/).respond(fixture2); - var prefix = 'sp'; - var offset = 0; - var list = []; comicService.findByName(prefix).then(function (results) { expect(results).toBeTruthy(); expect(results.length).toBe(20); - list = list.concat(results); - }).then(function () { - offset = 20; - return comicService.findByName(prefix, {offset:offset}); - }).then(function (results) { + expect(results[0].id).toBe(56169); + done(); + }); + $httpBackend.flush(); + }); + + it('should get the remaining results', function(done){ + var fixture2 = readJSON(fixturesPath + '/comics/sp_20.json'); + $httpBackend.expectGET(/\/comics/).respond(fixture2); + comicService.findByName(prefix, 20).then(function (results) { expect(results).toBeTruthy(); expect(results.length).toBe(20); - expect(list[0].id).not.toBe(results[0].id); - list = list.concat(results); - expect(list.length).toBe(40); + expect(results[0].id).toBe(55717); done(); }); $httpBackend.flush(); diff --git a/app/common/utils/utils.factory.js b/app/common/utils/utils.factory.js index 9d2707a..1046c4a 100644 --- a/app/common/utils/utils.factory.js +++ b/app/common/utils/utils.factory.js @@ -58,6 +58,7 @@ } function cacheThumbnails(items, properties){ + $log.debug('Caching thumbnails'); if(_.isEmpty(items)) return items; // Avoid configuring everyone for these very common properties. if(_.isEmpty(properties)) properties = ['thumbnailUrl', 'thumbnailUrlInPortraitUncanny']; diff --git a/app/favourite/favourite.factory.js b/app/favourite/favourite.factory.js index 4432b84..2d8835d 100644 --- a/app/favourite/favourite.factory.js +++ b/app/favourite/favourite.factory.js @@ -12,7 +12,7 @@ var unsyncedCreatedFaves = localStorageService.get('faves.created') || []; var unsyncedDeletedFaves = localStorageService.get('faves.deleted') || []; - + var service = { init: init, getFaveByModelId: getFaveByModelId, diff --git a/test/unit/fixtures/characters/s_0.json b/test/unit/fixtures/characters/sp_0.json similarity index 99% rename from test/unit/fixtures/characters/s_0.json rename to test/unit/fixtures/characters/sp_0.json index 52d1d02..cc6b08f 100644 --- a/test/unit/fixtures/characters/s_0.json +++ b/test/unit/fixtures/characters/sp_0.json @@ -8,7 +8,7 @@ "data": { "offset": 0, "limit": 20, - "total": 196, + "total": 33, "count": 20, "results": [ { diff --git a/test/unit/fixtures/characters/s_20.json b/test/unit/fixtures/characters/sp_20.json similarity index 100% rename from test/unit/fixtures/characters/s_20.json rename to test/unit/fixtures/characters/sp_20.json diff --git a/test/unit/fixtures/comics/s_0.json b/test/unit/fixtures/comics/sp_0.json similarity index 100% rename from test/unit/fixtures/comics/s_0.json rename to test/unit/fixtures/comics/sp_0.json diff --git a/test/unit/fixtures/comics/s_20.json b/test/unit/fixtures/comics/sp_20.json similarity index 100% rename from test/unit/fixtures/comics/s_20.json rename to test/unit/fixtures/comics/sp_20.json diff --git a/test/unit/global.js b/test/unit/global.js index 4034eff..1db783d 100644 --- a/test/unit/global.js +++ b/test/unit/global.js @@ -1,4 +1,5 @@ window.fixturesPath = 'test/unit/fixtures'; +// jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000; beforeEach(module('app'));