Created
March 18, 2016 18:31
-
-
Save jhyland87/5f6c84713e71e73af38f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
// Tools | |
const _ = require( 'lodash' ) | |
const appRoot = require( 'app-root-path' ) | |
const Util = require( 'util' ) | |
// Unit test related | |
const Code = require( 'code' ) | |
const Lab = require( 'lab' ) | |
const lab = exports.lab = Lab.script() | |
const suite = lab.suite | |
const it = lab.test | |
const before = lab.before | |
const describe = lab.experiment | |
const after = lab.after | |
const expect = Code.expect | |
const beforeEach = lab.beforeEach | |
const afterEach = lab.afterEach | |
// Hapi related | |
const Hapi = require( 'hapi' ) | |
const Glue = require( 'glue' ) | |
before( done => { | |
done() | |
}) | |
describe('Invia', () => { | |
describe('initiation', () => { | |
it('should fail when no `routeDir` is defined and the default routes path (`./routes`) is not valid', done => { | |
const server = new Hapi.Server(); | |
server.connection(); | |
server.register([ { | |
register: require('../') | |
} ], err => { | |
expect( err ).to.exist() | |
done() | |
}) | |
}) | |
it('should fail with an incorrect `routeDir` value', done => { | |
const server = new Hapi.Server(); | |
server.connection(); | |
server.register([ { | |
register: require('../'), | |
options: { | |
routeDir: './test/test_routes-fake' | |
} | |
} ], err => { | |
expect( err ).to.exist() | |
done() | |
}) | |
}) | |
it('should load the routes successfully with the routes in root.js as the root resource', done => { | |
const server = new Hapi.Server(); | |
const connection = server.connection(); | |
server.register([ { | |
register: require('../'), | |
options: { | |
routeDir: './test/test_routes', | |
rootResources: 'root' | |
} | |
},{ | |
register: require('blipp') | |
} ], err => { | |
expect( err ).to.not.exist() | |
server.start( err => { | |
expect( err ).to.not.exist() | |
const knownRoutes = ['/','/bar/baz','/bar/baz/test','/foo','/foo/test','/test'] | |
const table = server.table()[0].table | |
expect(table).to.be.an.array() | |
expect(table).to.have.length(6) | |
_.forEach( table, t => { | |
// Make sure this path is one thats expected to exist | |
expect( knownRoutes ).to.include(t.path) | |
// Remove it from the known routes | |
_.pull( knownRoutes, t.path ) | |
}) | |
// The knownRoutes should be 0, since they were pulled as they were processed | |
expect( knownRoutes ).to.have.length( 0 ) | |
server.stop( stopErr => done( stopErr )) | |
}) | |
}) | |
}) | |
it('should load the routes successfully with no root resources', done => { | |
const server = new Hapi.Server(); | |
const connection = server.connection(); | |
server.register([ { | |
register: require('../'), | |
options: { | |
routeDir: './test/test_routes' | |
} | |
},{ | |
register: require('blipp') | |
} ], err => { | |
expect( err ).to.not.exist() | |
server.start( err => { | |
expect( err ).to.not.exist() | |
const knownRoutes = ['/root','/bar/baz','/bar/baz/test','/foo','/foo/test','/root/test'] | |
const table = server.table()[0].table | |
expect(table).to.be.an.array() | |
expect(table).to.have.length(6) | |
_.forEach( table, t => { | |
// Make sure this path is one thats expected to exist | |
expect( knownRoutes ).to.include(t.path) | |
// Remove it from the known routes | |
_.pull( knownRoutes, t.path ) | |
}) | |
// The knownRoutes should be 0, since they were pulled as they were processed | |
expect( knownRoutes ).to.have.length( 0 ) | |
server.stop( stopErr => done( stopErr )) | |
}) | |
}) | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment