From 565830214b633d82921b2ea51559439a97d975b5 Mon Sep 17 00:00:00 2001 From: John Crepezzi Date: Mon, 28 Nov 2011 16:46:59 -0500 Subject: [PATCH] Start in on the tests --- lib/document_handler.js | 16 +++++++--------- spec/document_handler_spec.js | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 spec/document_handler_spec.js diff --git a/lib/document_handler.js b/lib/document_handler.js index 0a2ef27..07e824f 100644 --- a/lib/document_handler.js +++ b/lib/document_handler.js @@ -3,13 +3,16 @@ var winston = require('winston'); // For handling serving stored documents var DocumentHandler = function(options) { - if (options) { - this.keyLength = options.keyLength || 10; - this.maxLength = options.maxLength; // none by default - this.store = options.store; + if (!options) { + options = {}; } + this.keyLength = options.keyLength || DocumentHandler.defaultKeyLength; + this.maxLength = options.maxLength; // none by default + this.store = options.store; }; +DocumentHandler.defaultKeyLength = 10; + // Handle retrieving a document DocumentHandler.prototype.handleGet = function(key, response, skipExpire) { this.store.get(key, function(ret) { @@ -78,11 +81,6 @@ DocumentHandler.prototype.chooseKey = function(callback) { }); }; -// Return a boolean indicating whether or not something can be a key -DocumentHandler.potentialKey = function(key) { - return key.match(/^[a-zA-Z0-9]+(\.[a-zA-Z]+)?$/); -}; - // Generate a random key DocumentHandler.prototype.randomKey = function() { var text = ''; diff --git a/spec/document_handler_spec.js b/spec/document_handler_spec.js new file mode 100644 index 0000000..2e1fab6 --- /dev/null +++ b/spec/document_handler_spec.js @@ -0,0 +1,19 @@ +var DocumentHandler = require('../lib/document_handler'); + +describe('document_handler', function() { + + describe('randomKey', function() { + + it('should choose a key of the proper length', function() { + var dh = new DocumentHandler({ keyLength: 6 }); + expect(dh.randomKey().length).toBe(6); + }); + + it('should choose a default key length', function() { + var dh = new DocumentHandler(); + expect(dh.keyLength).toBe(DocumentHandler.defaultKeyLength); + }); + + }); + +});