Skip to content

Commit

Permalink
[Tests] Added new tests and extended an old one.
Browse files Browse the repository at this point in the history
  • Loading branch information
nabil1337 committed Sep 29, 2013
1 parent cc73052 commit 43226ca
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 4 deletions.
55 changes: 51 additions & 4 deletions tests/greppy/lib/app/worker/appTests.js
Expand Up @@ -18,6 +18,12 @@ describe('app', function() {

beforeEach(function () {
exApp = express();

// setting global needed by some tests
logger = {
debug: function(s) {
}
};
});

function getFuncName(fun) {
Expand All @@ -43,22 +49,23 @@ describe('app', function() {

it('should only allow digits for id-parameters', function(done) {

/*var contextMockup = {
var contextMockup = {
routes: [
{
path: '/just/some/test/',
method: 'get'
}
]
};*/
};

app = new App();
//app = new App();
app = new App(contextMockup);

app.configure(exApp, null, null);

// assume the last element in the stack is the greppy middleware.
// remove it, so our test will run.
exApp.stack.pop();
//exApp.stack.pop();

exApp.get('/just/some/test/:id', function(req, res) {
res.send(req.params.id);
Expand All @@ -80,6 +87,46 @@ describe('app', function() {
});
});

it('should only allow valid uuids for uuid-parameters', function(done) {

var contextMockup = {
routes: [
{
path: '/another/test',
method: 'get'
}
]
};

//app = new App();
app = new App(contextMockup);

app.configure(exApp, null, null);

// assume the last element in the stack is the greppy middleware.
// remove it, so our test will run.
//exApp.stack.pop();

exApp.get('/another/test/:uuid', function(req, res) {
res.send(req.params.uuid);
});

request(exApp)
.get('/another/test/550e8400-e29b-11d4-a716-446655440000')
.end(function(err, res) {
should.not.exist(err);
res.text.should.equal('550e8400-e29b-11d4-a716-446655440000');

request(exApp)
.get('another/test/5508400-e29b-11d4-a716-446655440000')
.end(function(err, res) {
should.exist(err);
should.not.exist(res);
done();
});
});
});


});

63 changes: 63 additions & 0 deletions tests/greppy/lib/app/worker/contextTests.js
@@ -0,0 +1,63 @@
/**
* Tests for lib/app/worker/context.js
*
* @author Nabil Krause <nabil.krause@silberlicht.eu>
*/

var should = require('should');
var path = require('path');
var root = path.resolve('./');
var express = require('express');
var Context = require(root + '/lib/app/worker/context');


describe('context', function() {

var context = null;

it('should have a property name which is based on the provided constructor-parameter', function() {
var param = 'i/am/some/path/to/a/file.js';

context = new Context(param);

context.name.should.equal('file');
});

it('should have a property description which should be a string', function() {
context = new Context();

context.description.should.be.a('string');
});

it('should have a property backends which should be an empty object', function() {
context = new Context();

context.backends.should.eql({});
});

it('should have a property modules which should be an empty array', function() {
context = new Context();

context.modules.should.eql([]);
});

it('should have a property controllers which should be an empty object', function() {
context = new Context();

context.controllers.should.eql({});
});

it('should have a property routes which should be an empty object', function() {
context = new Context();

context.modules.should.eql({});
});

it('should have a method configure which calls a given callback', function(done) {
context = new Context();

context.configure(null, null, function() {
done();
});
});
});
51 changes: 51 additions & 0 deletions tests/greppy/lib/http/mvc/controllerTests.js
@@ -0,0 +1,51 @@
/**
* Tests for lib/http/mvc/controller.js
*
* @author Nabil Krause <nabil.krause@silberlicht.eu>
*/

var should = require('should');
var path = require('path');
var root = path.resolve('./');
var Controller = require(root + '/lib/http/mvc/controller');
var controller = null;

describe('controller', function() {

beforeEach(function() {
controller = new Controller();
});

it('should have an options property with the correct structure and values', function() {
controller.options.should.have.property('path');
controller.options.should.have.property('auth');
controller.options.auth.should.have.property('handler');
controller.options.auth.should.have.property('routes');
controller.options.path.should.equal('');
should.equal(controller.options.auth.handler, null);
should.equal(controller.options.auth.routes, null);
});

it('should have an actions object', function() {
controller.actions.should.be.a('object');
});

it('should have a viewPath property', function() {
controller.viewPath.should.be.a('string');
});

it('should have a configure method which calls the provided callback', function(done) {
controller.configure(null, null, function() {
done();
});
});

it('should have a method view which returns the view-path for a given file', function() {
controller.view('xyz.jade').should.equal('/xyz.jade');

controller.viewPath = '/some/path/';

controller.view('myView.jade').should.equal('/some/path/myView.jade');
});
});

0 comments on commit 43226ca

Please sign in to comment.