Skip to content

Commit

Permalink
bugfix/tests — Fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeandat committed Jul 21, 2016
1 parent 711a70d commit 8c95e93
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 35 deletions.
2 changes: 2 additions & 0 deletions app/character/character.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
32 changes: 15 additions & 17 deletions app/character/character.factory.spec.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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();
Expand Down
30 changes: 14 additions & 16 deletions app/comic/comic.factory.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('comicService: ', function () {

var comicService, $httpBackend;
var comicService, $httpBackend, prefix = 'sp';

beforeEach(inject(function ($injector) {
comicService = $injector.get('comicService');
Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions app/common/utils/utils.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
2 changes: 1 addition & 1 deletion app/favourite/favourite.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

var unsyncedCreatedFaves = localStorageService.get('faves.created') || [];
var unsyncedDeletedFaves = localStorageService.get('faves.deleted') || [];

var service = {
init: init,
getFaveByModelId: getFaveByModelId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"data": {
"offset": 0,
"limit": 20,
"total": 196,
"total": 33,
"count": 20,
"results": [
{
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions test/unit/global.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
window.fixturesPath = 'test/unit/fixtures';
// jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000;

beforeEach(module('app'));

Expand Down

0 comments on commit 8c95e93

Please sign in to comment.