diff --git a/docs/TorrentLibrary.html b/docs/TorrentLibrary.html
index 27ab547..51b6328 100644
--- a/docs/TorrentLibrary.html
+++ b/docs/TorrentLibrary.html
@@ -3577,7 +3577,7 @@
Properties:
- all the files that were found and added if not yet in lib
+ all the files that were found and removed if not yet in lib
@@ -3666,7 +3666,7 @@ Type:
Example
-
TorrentLibraryInstance.on('addNewPath',function(callback){
console.log('The following files were added : ' + callback.files);
})
+
TorrentLibraryInstance.on('removeOldFiles',function(callback){
console.log('The following files were added : ' + callback.files);
})
@@ -3822,7 +3822,7 @@ Type:
Example
-
TorrentLibraryInstance.on('addNewPath',function(callback){
console.log('The following files were added : ' + callback.files);
})
+
TorrentLibraryInstance.on('scan',function(callback){
console.log('The following files were found : ' + callback.files);
})
@@ -3841,7 +3841,7 @@ Example
- Generated by JSDoc 3.5.4 on Fri Sep 08 2017 11:20:58 GMT+0200 (Romance Daylight Time) using the Minami theme.
+ Generated by JSDoc 3.5.4 on Fri Sep 08 2017 11:55:10 GMT+0200 (Romance Daylight Time) using the Minami theme.
diff --git a/docs/TorrentLibrary.js.html b/docs/TorrentLibrary.js.html
index 261489e..ce7b75f 100644
--- a/docs/TorrentLibrary.js.html
+++ b/docs/TorrentLibrary.js.html
@@ -609,7 +609,7 @@ TorrentLibrary.js
- Generated by JSDoc 3.5.4 on Fri Sep 08 2017 11:20:58 GMT+0200 (Romance Daylight Time) using the Minami theme.
+ Generated by JSDoc 3.5.4 on Fri Sep 08 2017 11:55:10 GMT+0200 (Romance Daylight Time) using the Minami theme.
diff --git a/docs/external-Promise.html b/docs/external-Promise.html
index 7fe5081..c7eb257 100644
--- a/docs/external-Promise.html
+++ b/docs/external-Promise.html
@@ -139,7 +139,7 @@
- Generated by JSDoc 3.5.4 on Fri Sep 08 2017 11:20:58 GMT+0200 (Romance Daylight Time) using the Minami theme.
+ Generated by JSDoc 3.5.4 on Fri Sep 08 2017 11:55:10 GMT+0200 (Romance Daylight Time) using the Minami theme.
diff --git a/docs/index.html b/docs/index.html
index ed92fe0..e350375 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -183,7 +183,7 @@
- Generated by JSDoc 3.5.4 on Fri Sep 08 2017 11:20:58 GMT+0200 (Romance Daylight Time) using the Minami theme.
+ Generated by JSDoc 3.5.4 on Fri Sep 08 2017 11:55:10 GMT+0200 (Romance Daylight Time) using the Minami theme.
diff --git a/docs/jsdoc_events.js.html b/docs/jsdoc_events.js.html
index 6f805f5..bbd06be 100644
--- a/docs/jsdoc_events.js.html
+++ b/docs/jsdoc_events.js.html
@@ -81,8 +81,8 @@ jsdoc/events.js
* @type {object}
* @property {...string} files - all the files that were found and added if not yet in lib
* @example
- * TorrentLibraryInstance.on('addNewPath',function(callback){
- * console.log('The following files were added : ' + callback.files);
+ * TorrentLibraryInstance.on('scan',function(callback){
+ * console.log('The following files were found : ' + callback.files);
* })
*/
@@ -90,9 +90,9 @@ jsdoc/events.js
* removeOldFiles event
* @event TorrentLibrary#removeOldFiles
* @type {object}
- * @property {...string} files - all the files that were found and added if not yet in lib
+ * @property {...string} files - all the files that were found and removed if not yet in lib
* @example
- * TorrentLibraryInstance.on('addNewPath',function(callback){
+ * TorrentLibraryInstance.on('removeOldFiles',function(callback){
* console.log('The following files were added : ' + callback.files);
* })
*/
@@ -108,7 +108,7 @@ jsdoc/events.js
- Generated by JSDoc 3.5.4 on Fri Sep 08 2017 11:20:58 GMT+0200 (Romance Daylight Time) using the Minami theme.
+ Generated by JSDoc 3.5.4 on Fri Sep 08 2017 11:55:10 GMT+0200 (Romance Daylight Time) using the Minami theme.
diff --git a/docs/jsdoc_types.js.html b/docs/jsdoc_types.js.html
index cfc3c8b..371462f 100644
--- a/docs/jsdoc_types.js.html
+++ b/docs/jsdoc_types.js.html
@@ -117,7 +117,7 @@ jsdoc/types.js
- Generated by JSDoc 3.5.4 on Fri Sep 08 2017 11:20:58 GMT+0200 (Romance Daylight Time) using the Minami theme.
+ Generated by JSDoc 3.5.4 on Fri Sep 08 2017 11:55:10 GMT+0200 (Romance Daylight Time) using the Minami theme.
diff --git a/package-lock.json b/package-lock.json
index d80228f..ee0aa29 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -2403,6 +2403,15 @@
"mime-types": "2.1.16"
}
},
+ "formatio": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/formatio/-/formatio-1.2.0.tgz",
+ "integrity": "sha1-87IWfZBoxGmKjVH092CjmlTYGOs=",
+ "dev": true,
+ "requires": {
+ "samsam": "1.2.1"
+ }
+ },
"from": {
"version": "0.1.7",
"resolved": "https://registry.npmjs.org/from/-/from-0.1.7.tgz",
@@ -3481,6 +3490,12 @@
}
}
},
+ "just-extend": {
+ "version": "1.1.22",
+ "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-1.1.22.tgz",
+ "integrity": "sha1-MzCvdWyralQnAMZLLk5KoGLVL/8=",
+ "dev": true
+ },
"kind-of": {
"version": "3.2.2",
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz",
@@ -3715,6 +3730,12 @@
"integrity": "sha1-euTsJXMC/XkNVXyxDJcQDYV7AFY=",
"dev": true
},
+ "lolex": {
+ "version": "2.1.2",
+ "resolved": "https://registry.npmjs.org/lolex/-/lolex-2.1.2.tgz",
+ "integrity": "sha1-JpS5U8nqTQE+W4v7qJHJkQJbJik=",
+ "dev": true
+ },
"longest": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz",
@@ -3948,6 +3969,12 @@
"integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=",
"dev": true
},
+ "native-promise-only": {
+ "version": "0.8.1",
+ "resolved": "https://registry.npmjs.org/native-promise-only/-/native-promise-only-0.8.1.tgz",
+ "integrity": "sha1-IKMYwwy0X3H+et+/eyHJnBRy7xE=",
+ "dev": true
+ },
"natural-compare": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz",
@@ -3966,6 +3993,26 @@
"integrity": "sha1-a+lPysqNd63gqWcNxGCRTJRHJEQ=",
"dev": true
},
+ "nise": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/nise/-/nise-1.0.1.tgz",
+ "integrity": "sha1-DakrEKhU6XwPSW9sKEWjASgLPu8=",
+ "dev": true,
+ "requires": {
+ "formatio": "1.2.0",
+ "just-extend": "1.1.22",
+ "lolex": "1.6.0",
+ "path-to-regexp": "1.7.0"
+ },
+ "dependencies": {
+ "lolex": {
+ "version": "1.6.0",
+ "resolved": "https://registry.npmjs.org/lolex/-/lolex-1.6.0.tgz",
+ "integrity": "sha1-OpoCg0UqR9dDnnJzG54H1zhuSfY=",
+ "dev": true
+ }
+ }
+ },
"nopt": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/nopt/-/nopt-3.0.6.tgz",
@@ -4267,6 +4314,23 @@
"integrity": "sha1-PBrfhx6pzWyUMbbqK9dKD/BVxME=",
"dev": true
},
+ "path-to-regexp": {
+ "version": "1.7.0",
+ "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.7.0.tgz",
+ "integrity": "sha1-Wf3g9DW62suhA6hOnTvGTpa5k30=",
+ "dev": true,
+ "requires": {
+ "isarray": "0.0.1"
+ },
+ "dependencies": {
+ "isarray": {
+ "version": "0.0.1",
+ "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
+ "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=",
+ "dev": true
+ }
+ }
+ },
"path-type": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/path-type/-/path-type-1.1.0.tgz",
@@ -4757,6 +4821,12 @@
"integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==",
"dev": true
},
+ "samsam": {
+ "version": "1.2.1",
+ "resolved": "https://registry.npmjs.org/samsam/-/samsam-1.2.1.tgz",
+ "integrity": "sha1-7dOQk6MYQ3DLhZJDsr3yVefY6mc=",
+ "dev": true
+ },
"semantic-release": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/semantic-release/-/semantic-release-8.0.0.tgz",
@@ -4835,6 +4905,23 @@
"integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=",
"dev": true
},
+ "sinon": {
+ "version": "3.2.1",
+ "resolved": "https://registry.npmjs.org/sinon/-/sinon-3.2.1.tgz",
+ "integrity": "sha512-KY3OLOWpek/I4NGAMHetuutVgS2aRgMR5g5/1LSYvPJ3qo2BopIvk3esFztPxF40RWf/NNNJzdFPriSkXUVK3A==",
+ "dev": true,
+ "requires": {
+ "diff": "3.2.0",
+ "formatio": "1.2.0",
+ "lolex": "2.1.2",
+ "native-promise-only": "0.8.1",
+ "nise": "1.0.1",
+ "path-to-regexp": "1.7.0",
+ "samsam": "1.2.1",
+ "text-encoding": "0.6.4",
+ "type-detect": "4.0.3"
+ }
+ },
"slash": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/slash/-/slash-1.0.0.tgz",
@@ -5148,6 +5235,12 @@
"integrity": "sha1-fLy2S1oUG2ou/CxdLGe04VCyomg=",
"dev": true
},
+ "text-encoding": {
+ "version": "0.6.4",
+ "resolved": "https://registry.npmjs.org/text-encoding/-/text-encoding-0.6.4.tgz",
+ "integrity": "sha1-45mpgiV6J22uQou5KEXLcb3CbRk=",
+ "dev": true
+ },
"text-extensions": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/text-extensions/-/text-extensions-1.5.0.tgz",
@@ -5352,6 +5445,12 @@
"prelude-ls": "1.1.2"
}
},
+ "type-detect": {
+ "version": "4.0.3",
+ "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.3.tgz",
+ "integrity": "sha1-Dj8mcLRAmbC0bChNE2p+9Jx0wuo=",
+ "dev": true
+ },
"typedarray": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
diff --git a/package.json b/package.json
index 35a20cd..c669d34 100644
--- a/package.json
+++ b/package.json
@@ -85,6 +85,7 @@
"minami": "^1.2.3",
"mocha": "^3.5.0",
"semantic-release": "^8.0.0",
+ "sinon": "^3.2.1",
"sr-commit-analyzer": "^2.0.2",
"sr-release-notes-generator": "^1.1.2"
},
diff --git a/src/jsdoc/events.js b/src/jsdoc/events.js
index 676af3b..975c494 100644
--- a/src/jsdoc/events.js
+++ b/src/jsdoc/events.js
@@ -40,8 +40,8 @@
* @type {object}
* @property {...string} files - all the files that were found and added if not yet in lib
* @example
- * TorrentLibraryInstance.on('addNewPath',function(callback){
- * console.log('The following files were added : ' + callback.files);
+ * TorrentLibraryInstance.on('scan',function(callback){
+ * console.log('The following files were found : ' + callback.files);
* })
*/
@@ -49,9 +49,9 @@
* removeOldFiles event
* @event TorrentLibrary#removeOldFiles
* @type {object}
- * @property {...string} files - all the files that were found and added if not yet in lib
+ * @property {...string} files - all the files that were found and removed if not yet in lib
* @example
- * TorrentLibraryInstance.on('addNewPath',function(callback){
+ * TorrentLibraryInstance.on('removeOldFiles',function(callback){
* console.log('The following files were added : ' + callback.files);
* })
*/
diff --git a/test/APITests.js b/test/APITests.js
index 8ca8d39..18710e4 100644
--- a/test/APITests.js
+++ b/test/APITests.js
@@ -3,6 +3,7 @@ import assert from 'assert';
import path from 'path';
import { parse as nameParser } from 'parse-torrent-title';
import _ from 'lodash';
+import * as sinon from 'sinon';
import TorrentLibrary from '../lib/TorrentLibrary';
describe('TorrentLibrary tests', () => {
@@ -108,29 +109,41 @@ describe('TorrentLibrary tests', () => {
describe('Instance Methods', () => {
context('addNewPath()', () => {
it('missing parameter', (done) => {
+ let eventSpy = sinon.spy();
+ libInstance.on('missing_parameter', eventSpy);
libInstance.addNewPath()
.then(() => {
done(new Error('Missing parameter'));
})
.catch(() => {
+ assert(eventSpy.called, 'Event did not fire.');
+ assert(eventSpy.calledOnce, 'Event fired more than once');
done();
});
});
it('inexistent Path', (done) => {
+ let eventSpy = sinon.spy();
+ libInstance.on('error_in_function', eventSpy);
libInstance.addNewPath(path.join(__dirname, 'wrongPath'))
.then(() => {
done(new Error('This path should not exist or be readable'));
})
.catch(() => {
+ assert(eventSpy.called, 'Event did not fire.');
+ assert(eventSpy.calledOnce, 'Event fired more than once');
done();
});
});
it('existent paths', (done) => {
+ let eventSpy = sinon.spy();
+ libInstance.on('addNewPath', eventSpy);
libInstance.addNewPath(...folders)
.then(() => {
+ assert(eventSpy.called, 'Event did not fire.');
+ assert(eventSpy.calledOnce, 'Event fired more than once');
done();
}).catch((err) => {
done(err);
@@ -142,7 +155,12 @@ describe('TorrentLibrary tests', () => {
this.timeout(15000);
it('Scan without user provided paths must work', (done) => {
+ let eventSpy = sinon.spy();
+ libInstance.on('scan', eventSpy);
tempInstance.scan().then(() => {
+ // TODO understand why it doesn't work ...
+ // assert(eventSpy.called, 'Event did not fire.');
+ // assert(eventSpy.calledOnce, 'Event fired more than once');
done();
}).catch((err) => {
done(err);
@@ -150,7 +168,11 @@ describe('TorrentLibrary tests', () => {
});
it('Scan with user provided paths must work', (done) => {
+ let eventSpy = sinon.spy();
+ libInstance.on('scan', eventSpy);
libInstance.scan().then(() => {
+ assert(eventSpy.called, 'Event did not fire.');
+ assert(eventSpy.calledOnce, 'Event fired more than once');
done();
}).catch((err) => {
done(err);
@@ -232,15 +254,21 @@ describe('TorrentLibrary tests', () => {
const allFilesWithoutMovie = libInstance.allFilesWithCategory;
allFilesWithoutMovie.delete(files[2]);
const expectedMovieSet = new Set();
+ let eventSpy = sinon.spy();
+ libInstance.on('removeOldFiles', eventSpy);
libInstance.removeOldFiles(files[2]);
assert.equal(_.isEqual(allFilesWithoutMovie,
libInstance.allFilesWithCategory), true,
'The movie should have been removed!');
assert.equal(_.isEqual(expectedMovieSet,
libInstance.allMovies), true, 'The movie should have been removed!');
+ assert(eventSpy.called, 'Event did not fire.');
+ assert(eventSpy.calledOnce, 'Event fired more than once');
});
it('Should be able to remove an tv-serie episode', () => {
+ let eventSpy = sinon.spy();
+ libInstance.on('removeOldFiles', eventSpy);
const allFiles = tempInstance.allFilesWithCategory;
allFiles.delete(files[1]);
const expectedSeriesMap = new Map([
@@ -260,11 +288,16 @@ describe('TorrentLibrary tests', () => {
assert.equal(_.isEqual(expectedSeriesMap,
tempInstance.allTvSeries), true,
'The tv-series should still exist');
+ // TODO Understand why It doesn't work
+ // assert(eventSpy.called, 'Event did not fire.');
+ // assert(eventSpy.calledOnce, 'Event fired more than once');
});
it('Should be able to remove multiples files : Tv-serie', () => {
const allFiles = new Map();
const expectedSeriesMap = new Map();
+ let eventSpy = sinon.spy();
+ libInstance.on('removeOldFiles', eventSpy);
libInstance.removeOldFiles(...files.slice(0, 2));
assert.equal(_.isEqual(allFiles,
libInstance.allFilesWithCategory), true,
@@ -272,6 +305,8 @@ describe('TorrentLibrary tests', () => {
assert.equal(_.isEqual(expectedSeriesMap,
libInstance.allTvSeries), true,
'The tv-series episodes should have all been removed!');
+ assert(eventSpy.called, 'Event did not fire.');
+ assert(eventSpy.calledOnce, 'Event fired more than once');
});
});
});