mirror of
https://github.com/SunRed/haste-server.git
synced 2024-11-01 01:30:21 +01:00
Start in on the tests
This commit is contained in:
parent
43e5667ff9
commit
565830214b
2 changed files with 26 additions and 9 deletions
|
@ -3,13 +3,16 @@ var winston = require('winston');
|
||||||
// For handling serving stored documents
|
// For handling serving stored documents
|
||||||
|
|
||||||
var DocumentHandler = function(options) {
|
var DocumentHandler = function(options) {
|
||||||
if (options) {
|
if (!options) {
|
||||||
this.keyLength = options.keyLength || 10;
|
options = {};
|
||||||
this.maxLength = options.maxLength; // none by default
|
|
||||||
this.store = options.store;
|
|
||||||
}
|
}
|
||||||
|
this.keyLength = options.keyLength || DocumentHandler.defaultKeyLength;
|
||||||
|
this.maxLength = options.maxLength; // none by default
|
||||||
|
this.store = options.store;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
DocumentHandler.defaultKeyLength = 10;
|
||||||
|
|
||||||
// Handle retrieving a document
|
// Handle retrieving a document
|
||||||
DocumentHandler.prototype.handleGet = function(key, response, skipExpire) {
|
DocumentHandler.prototype.handleGet = function(key, response, skipExpire) {
|
||||||
this.store.get(key, function(ret) {
|
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
|
// Generate a random key
|
||||||
DocumentHandler.prototype.randomKey = function() {
|
DocumentHandler.prototype.randomKey = function() {
|
||||||
var text = '';
|
var text = '';
|
||||||
|
|
19
spec/document_handler_spec.js
Normal file
19
spec/document_handler_spec.js
Normal file
|
@ -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);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
Loading…
Reference in a new issue