Skip to content

Commit

Permalink
Fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tormozz48 committed Feb 10, 2016
1 parent 2e963de commit edb7897
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 45 deletions.
4 changes: 2 additions & 2 deletions src/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export default class Model {
* @returns {Boolean}
*/
hasChanges() {
var changes = this.getChanges();
return changes.added.length || changes.modified.length || changes.removed.length;
const changes = this.getChanges();
return !!changes.added.length || !!changes.modified.length || !!changes.removed.length;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/tasks/docs/load-from-github.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ export default function loadSourcesFromGithub(model, options = {}) {
return Q(cache.fileName);
} else if(!cache.sha) {
debug('Doc added: %s %s', page.url, page.title);
model.pushChangeAdd({type: 'doc', url: page.url, title: page.title});
model.pushChangeToAddedGroup({type: 'doc', url: page.url, title: page.title});
} else {
debug('Doc modified: %s %s %s', page.url, page.title);
model.pushChangeModify({type: 'doc', url: page.url, title: page.title});
model.pushChangeToModifiedGroup({type: 'doc', url: page.url, title: page.title});
}

return Q()
Expand Down
8 changes: 4 additions & 4 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function _readFile(method, filePath, fallbackValue) {
/**
* Reads file from local filesystem
* @param {String} filePath - path to file on local filesystem
* @param {*} fallbackValue - value which will be returned if file does not exist on local filesystem
* @param {*} [fallbackValue] - value which will be returned if file does not exist on local filesystem
* @returns {*|Promise.<T>}
*/
export function readFile(filePath, fallbackValue) {
Expand All @@ -68,7 +68,7 @@ export function readFile(filePath, fallbackValue) {
/**
* Read JSON file from local filesystem
* @param {String} filePath - path to file
* @param {*} fallbackValue - value which will be returned if file does not exist on local filesystem
* @param {*} [fallbackValue] - value which will be returned if file does not exist on local filesystem
* @returns {*|Promise.<T>}
*/
export function readJSONFile(filePath, fallbackValue) {
Expand Down Expand Up @@ -129,8 +129,8 @@ export function writeFile(filePath, content) {
export function processPagesAsync(model, criteria, processFunc, portionSize = 5) {
criteria = criteria || (() => true);

return _(criteria)
.thru(model.getPages().filter)
return _(model.getPages())
.filter(criteria)
.chunk(portionSize)
.reduce((prev, portion, index) => {
return prev.then(() => {
Expand Down
42 changes: 6 additions & 36 deletions test/src/model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,32 @@ describe('Model', function() {
});

it('should add new items to changes add collection', function() {
model.pushChangeAdd('url1');
model.pushChangeToAddedGroup('url1');
model.getChanges().added[0].should.be.equal('url1');
});

it('should mark changes as modified after pushing new item into added collection', function() {
model.pushChangeAdd('url1');
model.pushChangeToAddedGroup('url1');
model.hasChanges().should.be.equal(true);
});

it('should add new items to modified collection', function() {
model.pushChangeModify('url1');
model.pushChangeToModifiedGroup('url1');
model.getChanges().modified[0].should.be.equal('url1');
});

it('should mark changes as modified after pushing new item into modified collection', function() {
model.pushChangeModify('url1');
model.pushChangeToModifiedGroup('url1');
model.hasChanges().should.be.equal(true);
});

it('should add new items to removed collection', function() {
model.pushChangeRemove('url1');
model.pushChangeToRemovedGroup('url1');
model.getChanges().removed[0].should.be.equal('url1');
});

it('should mark changes as modified after pushing new item into removed collection', function() {
model.pushChangeRemove('url1');
model.pushChangeToRemovedGroup('url1');
model.hasChanges().should.be.equal(true);
});

Expand Down Expand Up @@ -146,18 +146,6 @@ describe('Model', function() {
model.setPages([_.merge(pageProperty, commonPageProperties)]);
}

it('should add / to end of url if it was not already set', function() {
prepareModelPages({});
model.normalize();
model.getPages().shift().url.should.equal('/url1/');
});

it('should not add / to end of url if it was already set', function() {
prepareModelPages([{url: '/url1/'}]);
model.normalize();
model.getPages().shift().url.should.equal('/url1/');
});

it('should set given "aliases" property value as is if it was set', function() {
prepareModelPages({aliases: ['/url11', '/url22']});
model.normalize();
Expand All @@ -176,28 +164,10 @@ describe('Model', function() {
model.getPages().shift().view.should.be.equal('index');
});

it('should set default "view" property value as "post"', function() {
prepareModelPages({});
model.normalize();
model.getPages().shift().view.should.be.equal('post');
});

it('should set given "published" property value as is', function() {
prepareModelPages({published: true, title: 'Hello World'});
model.normalize();
model.getPages().shift().published.should.be.true;
});

it('should set default "published" property value as false', function() {
prepareModelPages({});
model.normalize();
model.getPages().shift().published.should.be.false;
});

it('should set "published" false when title as missed', function() {
prepareModelPages({published: true});
model.normalize();
model.getPages().shift().published.should.be.false;
});
});
});
2 changes: 1 addition & 1 deletion test/src/tasks-core/merge-models.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('tasks-core/merge-models', function() {
it('should read current model from local path given by "modelPath" option', function() {
return mergeModels(model, options)().then(function() {
readJSONFileStub.should.be.calledOnce;
readJSONFileStub.should.be.calledWithExactly('./some-model.json', null);
readJSONFileStub.should.be.calledWithExactly('./some-model.json');
});
});

Expand Down

0 comments on commit edb7897

Please sign in to comment.