-
Notifications
You must be signed in to change notification settings - Fork 17
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
09b09da
commit 626965c
Showing
7 changed files
with
152 additions
and
37 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
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,94 @@ | ||
const test = require('test'); | ||
test.setup(); | ||
|
||
describe('Hooks', () => { | ||
var tappInfo | ||
function setup(opts) { | ||
tappInfo = require('../support/spec_helper').getRandomSqliteBasedApp({ | ||
hooks: opts.hooks | ||
}, {}); | ||
} | ||
|
||
var triggered = { | ||
beforeSetupRoute: false | ||
}; | ||
|
||
afterEach(() => { | ||
Object.keys(triggered).forEach(k => triggered[k] = false) | ||
}) | ||
|
||
const apis = [ | ||
'get', | ||
'post', | ||
'put', | ||
'del', | ||
'eget', | ||
'epost', | ||
'eput', | ||
'edel', | ||
'functionHandler' | ||
] | ||
|
||
function assert_apis_not_exist(app) { | ||
apis.forEach(k => { | ||
assert.notExist(app.api[k]) | ||
}) | ||
} | ||
|
||
function assert_apis_exist(app) { | ||
apis.forEach(k => { | ||
assert.isFunction(app.api[k]) | ||
}) | ||
|
||
assert.isFunction(app.filterRequest) | ||
} | ||
|
||
it('[beforeSetupRoute] triggered after app instanced', () => { | ||
setup({ | ||
hooks: { | ||
beforeSetupRoute () { | ||
assert.isFalse(triggered.beforeSetupRoute) | ||
triggered.beforeSetupRoute = true; | ||
|
||
assert.exist(this) | ||
assert.isObject(this) | ||
|
||
assert.isObject(this.api) | ||
assert_apis_exist(this) | ||
} | ||
} | ||
}) | ||
|
||
assert.isTrue(triggered.beforeSetupRoute); | ||
assert_apis_exist(tappInfo.app); | ||
}); | ||
|
||
it('[beforeSetupRoute] triggered after app instanced - next', () => { | ||
setup({ | ||
hooks: { | ||
beforeSetupRoute (next) { | ||
setTimeout(() => { | ||
assert.isFalse(triggered.beforeSetupRoute) | ||
triggered.beforeSetupRoute = true; | ||
|
||
assert.exist(this) | ||
assert.isObject(this) | ||
|
||
assert.isObject(this.api) | ||
assert_apis_exist(this) | ||
|
||
next() | ||
}, 100) | ||
} | ||
} | ||
}) | ||
|
||
assert.isTrue(triggered.beforeSetupRoute); | ||
assert_apis_exist(tappInfo.app); | ||
}); | ||
}) | ||
|
||
if (require.main === module) { | ||
test.run(console.DEBUG); | ||
process.exit(); | ||
} |
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
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,3 @@ | ||
const { trigger, wait } = require('@fxjs/orm/lib/orm/entry/Hook.js') | ||
|
||
export { trigger, wait } |
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