2021-07-03 13:56:53 +00:00
|
|
|
import { Eltro as t, assert} from 'eltro'
|
|
|
|
|
2022-08-13 21:52:45 +00:00
|
|
|
import { createClient, startServer, log, 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()
|
2022-08-13 21:52:45 +00:00
|
|
|
|
|
|
|
return startServer()
|
2021-07-03 13:56:53 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.test('should run', async function() {
|
2021-10-11 00:21:57 +00:00
|
|
|
resetLog()
|
2022-08-13 21:52:45 +00:00
|
|
|
assert.strictEqual(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)
|
2022-08-13 21:52:45 +00:00
|
|
|
assert.strictEqual(log.info.callCount, 1)
|
|
|
|
assert.strictEqual(log.info.lastCall[0].status, 200)
|
|
|
|
assert.match(log.info.lastCall[1], /\<-- GET \//)
|
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()
|
2022-08-13 21:52:45 +00:00
|
|
|
assert.strictEqual(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/)
|
2022-08-13 21:52:45 +00:00
|
|
|
assert.strictEqual(log.error.firstCall[0].message, 'This is a test')
|
|
|
|
assert.strictEqual(log.error.callCount, 2)
|
|
|
|
assert.strictEqual(log.error.secondCall[0].status, 500)
|
|
|
|
assert.match(log.error.secondCall[1], /\<-- 500 GET \/error/)
|
2021-07-03 13:56:53 +00:00
|
|
|
})
|
|
|
|
})
|