summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/PodcastView.js4
-rw-r--r--package.json5
-rw-r--r--test/PodcastView.js63
3 files changed, 69 insertions, 3 deletions
diff --git a/lib/PodcastView.js b/lib/PodcastView.js
index 15970cf..1236abd 100644
--- a/lib/PodcastView.js
+++ b/lib/PodcastView.js
@@ -15,10 +15,10 @@ var DDB_VIEWS_TABLE = 'podcast-views';
* template.
* @constructor
*/
-modules.exports = function PodcastView(view) {
+var PodcastView = module.exports = function PodcastView(view) {
for (var property in view) {
if (view.hasOwnProperty(property)) {
- this[property] = source[property];
+ this[property] = view[property];
}
}
};
diff --git a/package.json b/package.json
index c0ec870..cc649c6 100644
--- a/package.json
+++ b/package.json
@@ -4,13 +4,16 @@
"description": "Podcast Service provides a restful interface for managing a set of podcasts.",
"main": "index.js",
"scripts": {
- "test": "echo \"Error: no test specified\" && exit 1"
+ "test": "./node_modules/.bin/mocha --require sinon --require mockery --reporter spec --bail"
},
"author": "",
"license": "ISC",
"dependencies": {
"aws-sdk": "^2.1.40",
"dynamodb-doc": "^1.0.0",
+ "mocha": "^2.2.5",
+ "mockery": "^1.4.0",
+ "sinon": "^1.15.4",
"underscore": "^1.8.3"
}
}
diff --git a/test/PodcastView.js b/test/PodcastView.js
new file mode 100644
index 0000000..b1ef22a
--- /dev/null
+++ b/test/PodcastView.js
@@ -0,0 +1,63 @@
+var assert = require('assert');
+var mockery = require('mockery');
+var sinon = require('sinon');
+
+var PodcastView; // Subject of the test
+
+var dynamoStub = {
+ getItem: sinon.stub()
+};
+
+describe('PodcastView', function() {
+ before(function() {
+ mockery.enable();
+ });
+
+ beforeEach(function() {
+ mockery.registerAllowable('underscore');
+ mockery.registerMock('dynamodb-doc', { DynamoDB: function() { return dynamoStub } });
+ mockery.registerAllowable('../lib/PodcastView', true);
+
+ PodcastView = require('../lib/PodcastView');
+
+ });
+
+ it('calls the callback with a view when findById is called with a valid viewId', function() {
+ // Setup stubs
+ dynamoStub
+ .getItem
+ .withArgs({
+ TableName: 'podcast-views',
+ Key: { feedId: '123', viewId: '456' }
+ })
+ .callsArgWith(1, null, {
+ Item: {
+ feedId: '123',
+ viewId: '456',
+ name: 'Test View',
+ template: 'Hello World'
+ }
+ });
+
+ var callback = sinon.spy();
+
+ // Call findById
+ PodcastView.findById({ feedId: '123', viewId: '456' }, callback);
+
+ // Assertions
+ assert(callback.calledOnce);
+
+ var error = callback.getCall(0).args[0];
+ var view = callback.getCall(0).args[1];
+ assert.equal(error, null);
+ assert.equal(view.feedId, '123');
+ assert.equal(view.viewId, '456');
+ assert.equal(view.name, 'Test View');
+ assert.equal(view.template, 'Hello World');
+ });
+
+ after(function() {
+ mockery.deregisterAll();
+ mockery.disable();
+ });
+});