added the first login tests

ref #45
This commit is contained in:
Nicolai Ort 2020-12-22 16:56:02 +01:00
parent 8d73a9dd59
commit af2744885f

View File

@ -0,0 +1,49 @@
import axios from 'axios';
import { config } from '../../config';
const base = "http://localhost:" + config.internal_port
let axios_config;
beforeAll(async () => {
axios_config = {
validateStatus: undefined
};
});
describe('POST /api/auth/login valid', () => {
it('valid login should return 200', async () => {
const res = await axios.post(base + '/api/auth/login', { username: "demo", password: "demo" }, axios_config);
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json")
});
});
// ---------------
describe('POST /api/auth/login invalid body', () => {
it('Loging without a body should return 400', async () => {
const res = await axios.post(base + '/api/auth/login', null, axios_config);
expect(res.status).toEqual(400);
});
it('Loging without a password should return 400', async () => {
const res = await axios.post(base + '/api/auth/login', { username: "demo" }, axios_config);
expect(res.status).toEqual(400);
});
it('Loging with invalid mail format should return 400', async () => {
const res = await axios.post(base + '/api/auth/login', { email: "demo", password: "demo" }, axios_config);
expect(res.status).toEqual(400);
});
it('Loging without a username/mail should return 404', async () => {
const res = await axios.post(base + '/api/auth/login', { password: "demo" }, axios_config);
expect(res.status).toEqual(404);
});
});
// ---------------
describe('POST /api/auth/login nonexistant user', () => {
it('login with nonexistant username should return 404', async () => {
const res = await axios.post(base + '/api/auth/login', { username: "-1", password: "demo" }, axios_config);
expect(res.status).toEqual(404);
});
it('login with nonexistant mail should return 404', async () => {
const res = await axios.post(base + '/api/auth/login', { email: "test@example.com", password: "demo" }, axios_config);
expect(res.status).toEqual(404);
});
});