From af2744885fd047467b948c5414d308487c49abc4 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 22 Dec 2020 16:56:02 +0100 Subject: [PATCH] added the first login tests ref #45 --- src/tests/auth/auth_login.spec.ts | 49 +++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/tests/auth/auth_login.spec.ts diff --git a/src/tests/auth/auth_login.spec.ts b/src/tests/auth/auth_login.spec.ts new file mode 100644 index 0000000..dcb5d99 --- /dev/null +++ b/src/tests/auth/auth_login.spec.ts @@ -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); + }); +}); \ No newline at end of file