From 91f9a8cbdecf74a74e68b80f3aec675de59e46d4 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Fri, 5 Mar 2021 18:42:53 +0100 Subject: [PATCH] Added tests ref #5 --- src/tests/selfservice_forgot_mail.spec.ts | 75 +++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/tests/selfservice_forgot_mail.spec.ts diff --git a/src/tests/selfservice_forgot_mail.spec.ts b/src/tests/selfservice_forgot_mail.spec.ts new file mode 100644 index 0000000..fcf89a3 --- /dev/null +++ b/src/tests/selfservice_forgot_mail.spec.ts @@ -0,0 +1,75 @@ +import axios from 'axios'; +import { config } from '../config'; +const base = "http://localhost:" + config.internal_port + +const axios_config = { + validateStatus: undefined +}; + +describe('POST /registration_forgot without auth', () => { + it('Post without auth should return 401', async () => { + const res = await axios.post(base + '/registration_forgot', null, axios_config); + expect(res.status).toEqual(401); + }); +}); + +describe('POST /registration_forgot with auth but wrong body', () => { + it('Post with auth but no body should return 400', async () => { + const res = await axios.post(base + '/registration_forgot?key=' + config.api_key, null, axios_config); + expect(res.status).toEqual(400); + }); + it('Post with auth but no mail should return 400', async () => { + const res = await axios.post(base + '/registration_forgot?key=' + config.api_key, { selfserviceToken: "test" }, axios_config); + expect(res.status).toEqual(400); + }); + it('Post with auth but no reset key should return 400', async () => { + const res = await axios.post(base + '/registration_forgot?key=' + config.api_key, { address: "test@dev.lauf-fuer-kaya.de" }, axios_config); + expect(res.status).toEqual(400); + }); + it('Post with auth but invalid mail should return 400', async () => { + const res = await axios.post(base + '/registration_forgot?key=' + config.api_key, { selfserviceToken: "test", address: "testdev.l.de" }, axios_config); + expect(res.status).toEqual(400); + }); +}); + +describe('POST /reset with auth and vaild body', () => { + it('Post with auth, body and no locale should return 200', async () => { + const res = await axios.post(base + '/registration_forgot?key=' + config.api_key, { + selfserviceToken: "test", + address: "test@dev.lauf-fuer-kaya.de" + }, axios_config); + expect(res.status).toEqual(200); + expect(res.data).toEqual({ + success: true, + message: "Sent!", + locale: "en", + type: "RUNNER_FORGOT" + }) + }); + it('Post with auth, body and locale=en should return 200', async () => { + const res = await axios.post(base + '/registration_forgot?locale=en&key=' + config.api_key, { + selfserviceToken: "test", + address: "test@dev.lauf-fuer-kaya.de" + }, axios_config); + expect(res.status).toEqual(200); + expect(res.data).toEqual({ + success: true, + message: "Sent!", + locale: "en", + type: "RUNNER_FORGOT" + }) + }); + it('Post with auth, body and locale=de should return 200', async () => { + const res = await axios.post(base + '/registration_forgot?locale=de&key=' + config.api_key, { + selfserviceToken: "test", + address: "test@dev.lauf-fuer-kaya.de" + }, axios_config); + expect(res.status).toEqual(200); + expect(res.data).toEqual({ + success: true, + message: "Sent!", + locale: "de", + type: "RUNNER_FORGOT" + }) + }); +}); \ No newline at end of file