Skip to content

Commit

Permalink
Implement ChangesType and Changes models and test coverage for them
Browse files Browse the repository at this point in the history
  • Loading branch information
tormozz48 committed Mar 1, 2015
1 parent 619fd9d commit 220fa42
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"main": "index.js",
"scripts": {
"config": "cp config/common/_app.json config/common/app.json",
"mocha": "node_modules/.bin/mocha",
"mocha": "NODE_ENV=testing node_modules/.bin/mocha",
"istanbul": "istanbul cover ./node_modules/mocha/bin/_mocha",
"codestyle": "node_modules/.bin/jshint . && node_modules/.bin/jscs -c .jscs.js .",
"cover": "istanbul cover _mocha",
Expand Down
46 changes: 46 additions & 0 deletions src/model/changes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
var ChangeType = require('./type'),
Changes = function () {
this._docs = new ChangeType('docs');
this._pages = new ChangeType('pages');
this._libraries = new ChangeType('libraries');
};

Changes.prototype = {
_docs: undefined,
_pages: undefined,
_libraries: undefined,

/**
* Returns modified state of changes
* @returns {*|Boolean}
*/
areModified: function () {
return this.docs.areModified() || this.pages.areModified() || this.libraries.areModified();
},

/**
* Returns documentation changes
* @returns {Array<ChangeType>}
*/
get docs() {
return this._docs;
},

/**
* Returns page changes
* @returns {Array<ChangeType>}
*/
get pages() {
return this._pages;
},

/**
* Returns library changes
* @returns {Array<ChangeType>}
*/
get libraries() {
return this._libraries;
}
};

module.exports = Changes;
77 changes: 77 additions & 0 deletions src/model/changes/type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
var ChangeType = function (type) {
this._type = type;
this._added = [];
this._modified = [];
this._removed = [];
};

ChangeType.prototype = {
_type: undefined,
_added: undefined,
_modified: undefined,
_removed: undefined,

/**
* Verify if data of given type were modified
* @returns {Boolean}
*/
areModified: function () {
return this._added.length || this._modified.length || this._removed.length;
},

/**
* Add new items to added group
* @param {Object} item
* @returns {ChangeType}
*/
addAdded: function (item) {
this._added.push(item);
return this;
},

/**
* Add new items to modified group
* @param {Object} item
* @returns {ChangeType}
*/
addModified: function (item) {
this._modified.push(item);
return this;
},

/**
* Add new items to removed group
* @param {Object} item
* @returns {ChangeType}
*/
addRemoved: function (item) {
this._removed.push(item);
return this;
},

/**
* Returns items of added group
* @returns {*}
*/
get added() {
return this._added;
},

/**
* Returns items of modified group
* @returns {*}
*/
get modified() {
return this._modified;
},

/**
* Returns items of removed group
* @returns {*}
*/
get removed() {
return this._removed;
}
};

module.exports = ChangeType;
3 changes: 0 additions & 3 deletions src/scripts/send-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ var fs = require('fs'),
};

SendModel.prototype = {
_link: undefined,
_logger: undefined,

/**
* Executes current script
* @param {Function} callback function
Expand Down
1 change: 1 addition & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
require('./scripts/send-model');
require('./model/changes/type');
31 changes: 31 additions & 0 deletions test/model/changes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
var ChangesType = require('../../../src/model/changes/type'),
Changes = require('../../../src/model/changes');

describe('model/changes', function () {
it('should be initialized successfully', function () {
new Changes();
});

it('should have docs changes model', function () {
var changes = new Changes();
changes.should.have.property('docs');
changes.docs.should.be.instanceof(ChangesType);
});

it('should have pages changes model', function () {
var changes = new Changes();
changes.should.have.property('pages');
changes.pages.should.be.instanceof(ChangesType);
});

it('should have libraries changes model', function () {
var changes = new Changes();
changes.should.have.property('libraries');
changes.libraries.should.be.instanceof(ChangesType);
});

it('should not be in modified state', function () {
var changes = new Changes();
changes.areModified().should.not.be.ok;
});
});
49 changes: 49 additions & 0 deletions test/model/changes/type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
var ChangesType = require('../../../src/model/changes/type');

describe('model/changes/type', function () {
it('should be initialized successfully by given type', function () {
var ct = new ChangesType('pages');
ct._type.should.equal('pages');
});

it('should not be in modified state', function () {
var ct = new ChangesType('pages');
ct.areModified().should.not.be.ok;
});

it('should have added empty collection', function () {
var ct = new ChangesType('pages');
ct.added.should.be.instanceof(Array).and.have.length(0);
});

it('should have modified empty collection', function () {
var ct = new ChangesType('pages');
ct.modified.should.be.instanceof(Array).and.have.length(0);
});

it('should have removed empty collection', function () {
var ct = new ChangesType('pages');
ct.removed.should.be.instanceof(Array).and.have.length(0);
});

it('should add new added items', function () {
var ct = new ChangesType('pages');
ct.addAdded('url1');
ct.added.should.have.length(1);
ct.areModified().should.be.ok;
});

it('should add new modified items', function () {
var ct = new ChangesType('pages');
ct.addModified('url1');
ct.modified.should.have.length(1);
ct.areModified().should.be.ok;
});

it('should add new removed items', function () {
var ct = new ChangesType('pages');
ct.addRemoved('url1');
ct.removed.should.have.length(1);
ct.areModified().should.be.ok;
});
});

0 comments on commit 220fa42

Please sign in to comment.