From 888cab5898caf9e552c421346934bf90f717a653 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Fri, 26 Mar 2021 20:41:36 +0100 Subject: [PATCH] Added user creation invalid tests ref #99 --- src/tests/users/user_post.spec.ts | 74 +++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/src/tests/users/user_post.spec.ts b/src/tests/users/user_post.spec.ts index 82ac7f4..8a6f7be 100644 --- a/src/tests/users/user_post.spec.ts +++ b/src/tests/users/user_post.spec.ts @@ -37,3 +37,77 @@ describe('POST /api/users valid', () => { expect(res.status).toEqual(200); }); }); +// --------------- +describe('POST /api/users invalid -> 400', () => { + it('user creation w/o firstname should return 400', async () => { + const res = await axios.post(base + '/api/users', { + "lastname": "demo_createASD123_3", + "password": "demo_createASD123_3", + "email": "demo_createASD123_3@dev.lauf-fuer-kaya.de" + }, axios_config); + expect(res.status).toEqual(400); + }); + it('user creation w/o lastname should return 400', async () => { + const res = await axios.post(base + '/api/users', { + "firstname": "demo_createASD123_3", + "password": "demo_createASD123_3", + "email": "demo_createASD123_3@dev.lauf-fuer-kaya.de" + }, axios_config); + expect(res.status).toEqual(400); + }); + it('user creation w/o password should return 400', async () => { + const res = await axios.post(base + '/api/users', { + "firstname": "demo_createASD123_3", + "lastname": "demo_createASD123_3", + "email": "demo_createASD123_3@dev.lauf-fuer-kaya.de" + }, axios_config); + expect(res.status).toEqual(400); + }); + it('user creation w/o email should return 400', async () => { + const res = await axios.post(base + '/api/users', { + "firstname": "demo_createASD123_3", + "lastname": "demo_createASD123_3", + "password": "demo_createASD123_3" + }, axios_config); + expect(res.status).toEqual(400); + }); +}); +// --------------- +describe('POST /api/users invalid -> Password errors', () => { + it('user creation w/ invalid password -> No numbers should return 406', async () => { + const res = await axios.post(base + '/api/users', { + "firstname": "demo_createASD123_4", + "lastname": "demo_createASD123_4", + "password": "demo_createASD", + "email": "demo_createASD123_4@dev.lauf-fuer-kaya.de" + }, axios_config); + expect(res.status).toEqual(406); + }); + it('user creation w/ invalid password -> No uppercase should return 406', async () => { + const res = await axios.post(base + '/api/users', { + "firstname": "demo_createASD123_4", + "lastname": "demo_createASD123_4", + "password": "demo_create_4", + "email": "demo_createASD123_4@dev.lauf-fuer-kaya.de" + }, axios_config); + expect(res.status).toEqual(406); + }); + it('user creation w/ invalid password -> No lowercase should return 406', async () => { + const res = await axios.post(base + '/api/users', { + "firstname": "demo_createASD123_4", + "lastname": "demo_createASD123_4", + "password": "DEMO123123ASD", + "email": "demo_createASD123_4@dev.lauf-fuer-kaya.de" + }, axios_config); + expect(res.status).toEqual(406); + }); + it('user creation w/ invalid password -> Too short should return 406', async () => { + const res = await axios.post(base + '/api/users', { + "firstname": "demo_createASD123_4", + "lastname": "demo_createASD123_4", + "password": "1Aa_", + "email": "demo_createASD123_4@dev.lauf-fuer-kaya.de" + }, axios_config); + expect(res.status).toEqual(406); + }); +}); \ No newline at end of file