1 | 'use strict'
|
2 |
|
3 | const Test = require('tape')
|
4 | const Sinon = require('sinon')
|
5 | const Handler = require('../src/handler')
|
6 | const Module = require('../src/index')
|
7 |
|
8 | Test('error handler module', moduleTest => {
|
9 | moduleTest.test('register should', registerTest => {
|
10 | registerTest.test('wire Handler onPreResponse method to server onPreResponse event', async function (test) {
|
11 | const extStub = Sinon.stub()
|
12 | const server = { ext: extStub }
|
13 | await Module.plugin.register(server, {})
|
14 | test.ok(extStub.calledWith('onPreResponse', Handler.onPreResponse))
|
15 | test.end()
|
16 | })
|
17 |
|
18 | registerTest.test('be named error-handler', test => {
|
19 | test.equal(Module.plugin.name, 'error-handler')
|
20 | test.end()
|
21 | })
|
22 |
|
23 | registerTest.end()
|
24 | })
|
25 |
|
26 | moduleTest.test('validateRoutes should', validateRoutesTest => {
|
27 | validateRoutesTest.test('return failAction and default options', async function (test) {
|
28 | const result = await Module.validateRoutes()
|
29 |
|
30 | test.equal(result.abortEarly, false)
|
31 | test.equal(result.language.key, '{{!key}} ')
|
32 | test.end()
|
33 | })
|
34 |
|
35 | validateRoutesTest.test('set abortEarly and language key on options and pass others', test => {
|
36 | const result = Module.validateRoutes({
|
37 | abortEarly: true,
|
38 | language: {
|
39 | key: 'not name'
|
40 | },
|
41 | others: 'others'
|
42 | })
|
43 |
|
44 | test.equal(result.abortEarly, false)
|
45 | test.equal(result.language.key, '{{!key}} ')
|
46 | test.equal(result.others, 'others')
|
47 | test.end()
|
48 | })
|
49 |
|
50 | validateRoutesTest.end()
|
51 | })
|
52 |
|
53 | moduleTest.end()
|
54 | })
|