backend/src/tests/auth/auth_login.spec.ts
Nicolai Ort f159252651
Some checks failed
continuous-integration/drone/pr Build is failing
Revert "Set timeout even higher b/c sqlite just kills itself during these tests"
This reverts commit 6ab60998d4.
2021-03-26 15:14:17 +01:00

57 lines
2.4 KiB
TypeScript

import axios from 'axios';
import { config } from '../../config';
const base = "http://localhost:" + config.internal_port
let axios_config;
beforeAll(async () => {
jest.setTimeout(20000);
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);
});
});
// ---------------
describe('POST /api/auth/login wrong password', () => {
it('login with wrong password should return 401', async () => {
const res = await axios.post(base + '/api/auth/login', { username: "demo", password: "totallynotthecorrectpassword" }, axios_config);
expect(res.status).toEqual(401);
});
});