flaska/test/http.test.mjs

42 lines
899 B
JavaScript
Raw Normal View History

2021-10-09 00:12:56 +00:00
import { Eltro as t, assert} from 'eltro'
import { Flaska } from '../flaska.mjs'
import Client from './client.mjs'
const port = 51024
const flaska = new Flaska({})
const client = new Client(port)
let reqBody = null
2021-10-09 00:12:56 +00:00
flaska.get('/', function(ctx) {
ctx.body = { status: true }
})
flaska.post('/test', function(ctx) {
ctx.body = { success: true }
// console.log(ctx)
})
2021-10-09 00:12:56 +00:00
t.before(function() {
return flaska.listenAsync(port)
2021-10-09 00:12:56 +00:00
})
t.describe('/', function() {
t.test('should return status true', function() {
return client.get('/').then(function(body) {
2021-10-09 00:12:56 +00:00
assert.deepEqual(body, { status: true })
})
})
})
t.describe('/test', function() {
t.test('should return success and store body', async function() {
reqBody = null
let body = await client.post('/test')
assert.deepEqual(body, { success: true })
})
})
t.after(function() {
return flaska.closeAsync()
2021-10-09 00:12:56 +00:00
})