This repository has been archived by the owner on Nov 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5fbe428
commit f9ba8db
Showing
4 changed files
with
123 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
|
||
const internals = {}; | ||
|
||
|
||
exports.register = (server, options, next) => { | ||
|
||
try { | ||
internals.bookshelf = require('bookshelf')(require('knex')(options.knex)); | ||
internals.knex = internals.bookshelf.knex; | ||
|
||
server.expose('bookshelf', internals.bookshelf); | ||
server.expose('knex', internals.knex); | ||
} | ||
catch (err) { | ||
|
||
return next(err); | ||
} | ||
|
||
return next(); | ||
}; | ||
|
||
|
||
exports.ext = internals; | ||
|
||
|
||
exports.register.attributes = { | ||
pkg: require('../package.json') | ||
}; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
'use strict'; | ||
|
||
const Hapi = require('hapi'); | ||
const Code = require('code'); | ||
const Lab = require('lab'); | ||
const Plugin = require('..'); | ||
|
||
const expect = Code.expect; | ||
const lab = exports.lab = Lab.script(); | ||
const beforeEach = lab.beforeEach; | ||
const describe = lab.describe; | ||
const it = lab.it; | ||
|
||
describe('lib', () => { | ||
|
||
let server; | ||
|
||
beforeEach((done) => { | ||
|
||
server = new Hapi.Server(); | ||
server.connection(); | ||
server.initialize(); | ||
|
||
return done(); | ||
}); | ||
|
||
const register = (options, next) => { | ||
|
||
server.register({ | ||
register: Plugin, | ||
options: options | ||
}, (err) => { | ||
|
||
return next(err); | ||
}); | ||
}; | ||
|
||
it('errors if options are invalid', (done) => { | ||
|
||
register({ | ||
test: 'value' | ||
}, (err) => { | ||
|
||
expect(err).to.exist(); | ||
|
||
return done(); | ||
}); | ||
}); | ||
|
||
it('registers with option', (done) => { | ||
|
||
register({ | ||
knex: { | ||
client: 'pg', | ||
searchPath: 'public', | ||
connection: 'postgres://postgres:postgres@localhost:5432/postgres' | ||
} | ||
}, (err) => { | ||
|
||
expect(err).to.not.exist(); | ||
expect(server.plugins.knekshelf.bookshelf).to.exist(); | ||
expect(server.plugins.knekshelf.knex).to.exist(); | ||
|
||
const Reload = require('..'); | ||
|
||
expect(Reload.ext.bookshelf).to.exist(); | ||
expect(Reload.ext.knex).to.exist(); | ||
|
||
return done(); | ||
}); | ||
}); | ||
}); |