Skip to content

Commit

Permalink
test(dispatcher): increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBuchholz committed Apr 30, 2024
1 parent df5a4c9 commit 4c11922
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion reserve/src/dispatcher.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ const { describe, it, before } = require('mocha')
const assert = require('assert')
const { check, Request, Response } = require('./index')
const dispatcher = require('./dispatcher')
const { $configurationEventEmitter } = require('./symbols')
const { $configurationEventEmitter, $mappingMatch } = require('./symbols')
const { newEventEmitter } = require('./event')
const status = require('./handlers/status')

const textMimeType = 'text/plain'
let defaultConfigurationPromise
Expand Down Expand Up @@ -354,6 +355,46 @@ describe('dispatcher', () => {
assert.strictEqual(response.statusCode, 500)
})
)

it('supports internal failures (1)', () => dispatch({
configurationPromise: defaultConfigurationPromise
.then(configuration => {
const buggyConfiguration = {
...configuration,
mappings: [...configuration.mappings]
}
buggyConfiguration.mappings[0] = {
...buggyConfiguration.mappings[0],
[$mappingMatch]: () => { throw new Error('NOPE') }
}
return buggyConfiguration
}),
request: '/fail'
})
.then(({ emitted, response }) => {
assert.ok(hasError(emitted))
assert.strictEqual(response.statusCode, 500)
}))

it('supports internal failures (2)', () => dispatch({
configurationPromise: defaultConfigurationPromise
.then(configuration => {
const buggyConfiguration = {
...configuration,
handlers: { ...configuration.handlers }
}
buggyConfiguration.handlers.status = {
...status,
redirect: () => { throw new Error('NOPE') }
}
return buggyConfiguration
}),
request: '/fail'
})
.then(({ emitted, response }) => {
assert.ok(hasError(emitted))
assert.strictEqual(response.statusCode, 200)
}))
})

describe('No handler for the request', () => {
Expand Down

0 comments on commit 4c11922

Please sign in to comment.