Files
crates/api/src/api.test.ts
T
2022-08-17 23:22:48 +10:00

48 lines
1.2 KiB
TypeScript

import assert from 'assert/strict';
import axios from 'axios';
import createServices from './services';
import createLog from './log';
const log = createLog();
log.level('error');
const services = createServices(log);
const HOST = 'http://localhost:41337';
before(function setup() {
services.api.listen();
});
after(function teardown(done) {
services.api.server.close(done)
});
describe('api', function apiTests() {
it('listens', async function listenTest() {
const res = await axios.get(`${HOST}/health`);
assert.equal(res.status, 200);
});
it('register', async function register() {
const body = {
email: `test+${Date.now()}@user.com`,
password: 'woaaah theres no limit',
};
const { data } = await axios.post(`${HOST}/auth/register`, body);
assert.equal(data.email, body.email);
});
it('login', async function login() {
const body = {
email: `test+${Date.now()}@user.com`,
password: 'woaaah theres no limit',
};
await axios.post(`${HOST}/auth/register`, body);
const res = await axios.post(`${HOST}/auth/login`, body);
assert(res.headers['set-cookie']);
})
});