storage-upload/test/server.test.mjs

42 lines
1.2 KiB
JavaScript
Raw Normal View History

import { Eltro as t, assert} from 'eltro'
2022-08-13 21:52:45 +00:00
import { createClient, startServer, log, resetLog } from './helper.server.mjs'
t.describe('Server', function() {
let client
t.before(function() {
client = createClient()
2022-08-13 21:52:45 +00:00
return startServer()
})
t.test('should run', async function() {
resetLog()
2022-08-13 21:52:45 +00:00
assert.strictEqual(log.info.callCount, 0)
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 \//)
})
t.test('should handle errors fine', async function() {
resetLog()
2022-08-13 21:52:45 +00:00
assert.strictEqual(log.warn.callCount, 0)
let data = await assert.isRejected(client.get('/error'))
assert.ok(data)
assert.ok(data.body)
assert.strictEqual(data.body.status, 500)
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/)
})
})