From cbd6a8d009d73c60af9da9dbafda4d28be52fae9 Mon Sep 17 00:00:00 2001 From: Dallon Feldner Date: Wed, 21 Nov 2012 08:53:05 -0700 Subject: [PATCH] Fixed unit tests --- HISTORY.md | 6 ++++-- lib/config-loader.js | 6 +++++- lib/module-loader.js | 2 +- lib/resources/collection/index.js | 1 - lib/resources/internal-resources.js | 8 ++++---- test/config-loader.unit.js | 14 +++++++++++--- test/resource.unit.js | 4 ++++ test/server.unit.js | 1 + 8 files changed, 30 insertions(+), 12 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index a4fd07f..460ae04 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,8 +2,6 @@ ## 0.7.0 -### Breaking Changes - ### New Features - New utilities for extending Resource Types. - Added `Resource.extend("ResourceName", { /* members */ })` syntax for extending Resources. The `init()` function is used as a constructor. The old `util.inherits()` syntax will continue to work. @@ -13,4 +11,8 @@ - Modules can define multiple Resource Types with `this.addResourceType()` - [TODO] Modules can register their own dashboards. +### Breaking Changes +- All configuration properties on the `Resource` class have been moved to the prototype: `external`, `events`, `label`, `defaultPath`, `basicDashboard`, and `dashboard`. + + ### Major Bugfixes \ No newline at end of file diff --git a/lib/config-loader.js b/lib/config-loader.js index 77ef1d1..25a67c4 100644 --- a/lib/config-loader.js +++ b/lib/config-loader.js @@ -34,6 +34,10 @@ module.exports.loadConfig = function(basepath, server, fn) { throw new Error("Error reading app.dpd: " + ex.message); } } + }, function(err) { + if (err.code === "ENOENT") { + throw "Expected app.dpd file"; + } }); }); @@ -128,7 +132,7 @@ function loadResources(resourceTypesQ, basepath, server) { var type = config.type; if (!types[type]) throw new Error("Cannot find type \"" + type + "\" for resource " + resourceName); - o = { + var o = { config: config , server: server , db: server.db diff --git a/lib/module-loader.js b/lib/module-loader.js index 0c85c57..db85e8d 100644 --- a/lib/module-loader.js +++ b/lib/module-loader.js @@ -75,7 +75,7 @@ function loadModule(file, fn) { throw ex; } module = module || {}; - if (!module.id) module.id = path.basename(file, '.js'); + if (!module.id) module.id = (typeof module === 'function' && module.name) || path.basename(file, '.js'); return module; } else { return null; diff --git a/lib/resources/collection/index.js b/lib/resources/collection/index.js index 2afd07c..7c20a73 100644 --- a/lib/resources/collection/index.js +++ b/lib/resources/collection/index.js @@ -32,7 +32,6 @@ function Collection(name, options) { } } util.inherits(Collection, Resource); -Collection.id = "Collection"; Collection.external = {}; Collection.prototype.clientGeneration = true; diff --git a/lib/resources/internal-resources.js b/lib/resources/internal-resources.js index 964638d..e39402d 100644 --- a/lib/resources/internal-resources.js +++ b/lib/resources/internal-resources.js @@ -33,10 +33,10 @@ util.inherits(InternalResources, Resource); module.exports = InternalResources; var excludedTypes = { - 'dashboard': 1, - 'files': 1, - 'client-lib': 1, - 'internal-resources': 1 + Dashboard: 1, + Files: 1, + ClientLib: 1, + InternalResources: 1 }; InternalResources.prototype.handle = function(ctx, next) { diff --git a/test/config-loader.unit.js b/test/config-loader.unit.js index 0d9fe6d..9e4e9ea 100644 --- a/test/config-loader.unit.js +++ b/test/config-loader.unit.js @@ -17,6 +17,7 @@ describe('config-loader', function() { sh.rm('-rf', basepath); } sh.mkdir('-p', basepath); + ('{}').to(path.join(basepath, 'app.dpd')); this.server = new Server(); }); @@ -31,8 +32,9 @@ describe('config-loader', function() { JSON.stringify({type: "Collection", val: 1}).to(path.join(basepath, 'resources/foo/config.json')); JSON.stringify({type: "Collection", val: 2}).to(path.join(basepath, 'resources/bar/config.json')); - configLoader.loadConfig(basepath, this.server, function(err, resources) { + configLoader.loadConfig(basepath, this.server, function(err, result) { if (err) return done(err); + var resources = result.resources; expect(resources).to.have.length(6); expect(resources.filter(function(r) { return r.name == 'foo';})).to.have.length(1); expect(resources.filter(function(r) { return r.name == 'bar';})).to.have.length(1); @@ -44,7 +46,10 @@ describe('config-loader', function() { sh.mkdir('-p', path.join(basepath, 'resources/foo')); JSON.stringify({type: "Collection", properties: {}}).to(path.join(basepath, 'resources/foo/config.json')); - configLoader.loadConfig(basepath, {db: db}, function(err, resourceList) { + configLoader.loadConfig(basepath, {db: db}, function(err, result) { + + var resourceList = result.resources; + expect(resourceList).to.have.length(5); expect(resourceList[0].config.properties).to.be.a('object'); @@ -57,8 +62,11 @@ describe('config-loader', function() { it('should add internal resources', function(done) { sh.mkdir('-p', path.join(basepath, 'resources')); - configLoader.loadConfig(basepath, {}, function(err, resourceList) { + configLoader.loadConfig(basepath, {}, function(err, result) { if (err) return done(err); + + var resourceList = result.resources; + expect(resourceList).to.have.length(4); expect(resourceList[0] instanceof Files).to.equal(true); diff --git a/test/resource.unit.js b/test/resource.unit.js index 590caae..6b747f1 100644 --- a/test/resource.unit.js +++ b/test/resource.unit.js @@ -41,6 +41,10 @@ describe('resource', function(){ describe('.handle(ctx, next)', function(){ it('should respond with 200 OK', function(done) { var r = new Resource({path: '/foo'}); + + r.get = function(ctx, next) { + ctx.done(); + }; freq('/foo', null, function (req, res) { r.handle(new Context(r, req, res, {})); diff --git a/test/server.unit.js b/test/server.unit.js index cd476d7..1076a23 100644 --- a/test/server.unit.js +++ b/test/server.unit.js @@ -10,6 +10,7 @@ describe('Server', function() { sh.cd('./test/support/proj'); sh.rm('-rf', 'resources'); sh.mkdir('resources'); + '{}'.to('app.dpd'); }); it('should start a new deployd server', function(done) {