2021-07-03 13:56:53 +00:00
|
|
|
import { Eltro as t, assert} from 'eltro'
|
|
|
|
|
2021-10-11 00:21:57 +00:00
|
|
|
import { createClient, server, resetLog } from './helper.server.mjs'
|
2021-07-03 13:56:53 +00:00
|
|
|
|
|
|
|
t.describe('Server', function() {
|
|
|
|
let client
|
|
|
|
|
|
|
|
t.before(function() {
|
2021-10-11 00:21:57 +00:00
|
|
|
client = createClient()
|
2021-07-03 13:56:53 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.test('should run', async function() {
|
2021-10-11 00:21:57 +00:00
|
|
|
resetLog()
|
|
|
|
assert.strictEqual(server.log.info.callCount, 0)
|
2021-07-03 13:56:53 +00:00
|
|
|
let data = await client.get('/')
|
|
|
|
|
|
|
|
assert.ok(data)
|
|
|
|
assert.ok(data.name)
|
|
|
|
assert.ok(data.version)
|
2021-10-11 00:21:57 +00:00
|
|
|
assert.strictEqual(server.log.info.callCount, 1)
|
|
|
|
assert.strictEqual(server.log.info.lastCall[0].status, 200)
|
|
|
|
assert.strictEqual(server.log.info.lastCall[0].path, '/')
|
|
|
|
assert.strictEqual(typeof(server.log.info.lastCall[0].ms), 'number')
|
2021-07-03 13:56:53 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.test('should handle errors fine', async function() {
|
2021-10-11 00:21:57 +00:00
|
|
|
resetLog()
|
|
|
|
assert.strictEqual(server.log.warn.callCount, 0)
|
2021-07-03 13:56:53 +00:00
|
|
|
let data = await assert.isRejected(client.get('/error'))
|
|
|
|
|
|
|
|
assert.ok(data)
|
|
|
|
assert.ok(data.body)
|
2021-10-11 00:21:57 +00:00
|
|
|
assert.strictEqual(data.body.status, 500)
|
2021-07-03 13:56:53 +00:00
|
|
|
assert.match(data.body.message, /test/)
|
2021-10-11 00:21:57 +00:00
|
|
|
assert.strictEqual(server.log.warn.callCount, 1)
|
|
|
|
assert.strictEqual(server.log.warn.lastCall[0].status, 500)
|
|
|
|
assert.strictEqual(server.log.warn.lastCall[0].path, '/error')
|
|
|
|
assert.strictEqual(typeof(server.log.warn.lastCall[0].ms), 'number')
|
2021-07-03 13:56:53 +00:00
|
|
|
})
|
|
|
|
})
|