From dd1258333ef67243f8a8df97c176ec5a054a5e3b Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Fri, 26 Mar 2021 16:42:01 +0100 Subject: [PATCH 1/7] Updated old hint ref #174 --- src/controllers/RunnerSelfServiceController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/RunnerSelfServiceController.ts b/src/controllers/RunnerSelfServiceController.ts index 03e0ec3..781c913 100644 --- a/src/controllers/RunnerSelfServiceController.ts +++ b/src/controllers/RunnerSelfServiceController.ts @@ -43,7 +43,7 @@ export class RunnerSelfServiceController { @ResponseSchema(ResponseSelfServiceRunner) @ResponseSchema(RunnerNotFoundError, { statusCode: 404 }) @OnUndefined(RunnerNotFoundError) - @OpenAPI({ description: 'Lists all information about yourself.
Please provide your runner jwt(that code we gave you during registration) for auth.
If you lost your jwt/personalized link please contact support.' }) + @OpenAPI({ description: 'Lists all information about yourself.
Please provide your runner jwt(that code we gave you during registration) for auth.
If you lost your jwt/personalized link please use the forgot endpoint.' }) async get(@Param('jwt') token: string) { return (new ResponseSelfServiceRunner(await this.getRunner(token))); } From dcb12b0ac289f8df148ba10ae6389727c16f53fd Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Fri, 26 Mar 2021 16:42:14 +0100 Subject: [PATCH 2/7] Added selfservice deletion endpoint ref #174 --- .../RunnerSelfServiceController.ts | 48 ++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/src/controllers/RunnerSelfServiceController.ts b/src/controllers/RunnerSelfServiceController.ts index 781c913..d96370f 100644 --- a/src/controllers/RunnerSelfServiceController.ts +++ b/src/controllers/RunnerSelfServiceController.ts @@ -1,12 +1,12 @@ import { Request } from "express"; import * as jwt from "jsonwebtoken"; -import { Body, Get, JsonController, OnUndefined, Param, Post, QueryParam, Req, UseBefore } from 'routing-controllers'; +import { Body, Delete, Get, JsonController, OnUndefined, Param, Post, QueryParam, Req, UseBefore } from 'routing-controllers'; import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi'; import { getConnectionManager, Repository } from 'typeorm'; import { config } from '../config'; import { InvalidCredentialsError, JwtNotProvidedError } from '../errors/AuthError'; import { MailSendingError } from '../errors/MailErrors'; -import { RunnerEmailNeededError, RunnerNotFoundError, RunnerSelfserviceTimeoutError } from '../errors/RunnerErrors'; +import { RunnerEmailNeededError, RunnerHasDistanceDonationsError, RunnerNotFoundError, RunnerSelfserviceTimeoutError } from '../errors/RunnerErrors'; import { RunnerOrganizationNotFoundError } from '../errors/RunnerOrganizationErrors'; import { ScanStationNotFoundError } from '../errors/ScanStationErrors'; import { JwtCreator } from '../jwtcreator'; @@ -23,6 +23,9 @@ import { ResponseScanStation } from '../models/responses/ResponseScanStation'; import { ResponseSelfServiceOrganisation } from '../models/responses/ResponseSelfServiceOrganisation'; import { ResponseSelfServiceRunner } from '../models/responses/ResponseSelfServiceRunner'; import { ResponseSelfServiceScan } from '../models/responses/ResponseSelfServiceScan'; +import { DonationController } from './DonationController'; +import { RunnerCardController } from './RunnerCardController'; +import { ScanController } from './ScanController'; @JsonController() export class RunnerSelfServiceController { @@ -48,6 +51,47 @@ export class RunnerSelfServiceController { return (new ResponseSelfServiceRunner(await this.getRunner(token))); } + @Delete('/runners/me/:jwt') + @ResponseSchema(ResponseSelfServiceRunner) + @ResponseSchema(RunnerNotFoundError, { statusCode: 404 }) + @OnUndefined(RunnerNotFoundError) + @OpenAPI({ description: 'Deletes all information about yourself.
Please provide your runner jwt(that code we gave you during registration) for auth.
If you lost your jwt/personalized link please use the forgot endpoint.' }) + async remove(@Param('jwt') token: string, @QueryParam("force") force: boolean) { + let runner = await this.getRunner(token); + runner = await this.runnerRepository.findOne({ id: runner.id }); + + if (!runner) { return null; } + const responseRunner = await this.runnerRepository.findOne(runner, { relations: ['scans', 'group', 'group.parentGroup', 'scans.track', 'cards'] }); + + if (!runner) { + throw new RunnerNotFoundError(); + } + + const runnerDonations = (await this.runnerRepository.findOne({ id: runner.id }, { relations: ["distanceDonations"] })).distanceDonations; + if (runnerDonations.length > 0 && !force) { + throw new RunnerHasDistanceDonationsError(); + } + const donationController = new DonationController(); + for (let donation of runnerDonations) { + await donationController.remove(donation.id, force); + } + + const runnerCards = (await this.runnerRepository.findOne({ id: runner.id }, { relations: ["cards"] })).cards; + const cardController = new RunnerCardController; + for (let card of runnerCards) { + await cardController.remove(card.id, force); + } + + const runnerScans = (await this.runnerRepository.findOne({ id: runner.id }, { relations: ["scans"] })).scans; + const scanController = new ScanController; + for (let scan of runnerScans) { + await scanController.remove(scan.id, force); + } + + await this.runnerRepository.delete(runner); + return new ResponseSelfServiceRunner(responseRunner); + } + @Get('/runners/me/:jwt/scans') @ResponseSchema(ResponseSelfServiceScan, { isArray: true }) @ResponseSchema(RunnerNotFoundError, { statusCode: 404 }) From ccb7ae29a39387c0f2762861565dc22996a2493a Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Fri, 26 Mar 2021 16:45:30 +0100 Subject: [PATCH 3/7] Fixed response bug ref #174 --- src/controllers/RunnerSelfServiceController.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/controllers/RunnerSelfServiceController.ts b/src/controllers/RunnerSelfServiceController.ts index d96370f..8f5509e 100644 --- a/src/controllers/RunnerSelfServiceController.ts +++ b/src/controllers/RunnerSelfServiceController.ts @@ -57,12 +57,10 @@ export class RunnerSelfServiceController { @OnUndefined(RunnerNotFoundError) @OpenAPI({ description: 'Deletes all information about yourself.
Please provide your runner jwt(that code we gave you during registration) for auth.
If you lost your jwt/personalized link please use the forgot endpoint.' }) async remove(@Param('jwt') token: string, @QueryParam("force") force: boolean) { - let runner = await this.getRunner(token); - runner = await this.runnerRepository.findOne({ id: runner.id }); + const responseRunner = await this.getRunner(token); + let runner = await this.runnerRepository.findOne({ id: responseRunner.id }); if (!runner) { return null; } - const responseRunner = await this.runnerRepository.findOne(runner, { relations: ['scans', 'group', 'group.parentGroup', 'scans.track', 'cards'] }); - if (!runner) { throw new RunnerNotFoundError(); } From 20aeed87780247dc6401bba725801fc1874e50b5 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Fri, 26 Mar 2021 16:50:12 +0100 Subject: [PATCH 4/7] Added tests for the new endpoint ref #174 --- .../selfservice/selfservice_delete.spec.ts | 249 ++++++++++++++++++ .../selfservice/selfservice_register.spec.ts | 240 ++--------------- 2 files changed, 277 insertions(+), 212 deletions(-) create mode 100644 src/tests/selfservice/selfservice_delete.spec.ts diff --git a/src/tests/selfservice/selfservice_delete.spec.ts b/src/tests/selfservice/selfservice_delete.spec.ts new file mode 100644 index 0000000..36dc7fa --- /dev/null +++ b/src/tests/selfservice/selfservice_delete.spec.ts @@ -0,0 +1,249 @@ +import axios from 'axios'; +import { config } from '../../config'; +const base = "http://localhost:" + config.internal_port + +let access_token; +let axios_config; + +beforeAll(async () => { + jest.setTimeout(20000); + const res = await axios.post(base + '/api/auth/login', { username: "demo", password: "demo" }); + access_token = res.data["access_token"]; + axios_config = { + headers: { "authorization": "Bearer " + access_token }, + validateStatus: undefined + }; +}); + +describe('register invalid citizen', () => { + it('registering as citizen without mail should return 406', async () => { + const res = await axios.post(base + '/api/runners/register', { + "firstname": "string", + "middlename": "string", + "lastname": "string", + }, axios_config); + expect(res.status).toEqual(406); + expect(res.headers['content-type']).toContain("application/json"); + }); + it('registering as citizen with invalid mail should return 400', async () => { + const res = await axios.post(base + '/api/runners/register', { + "firstname": "string", + "middlename": "string", + "lastname": "string", + "email": "user" + }, axios_config); + expect(res.status).toEqual(400); + expect(res.headers['content-type']).toContain("application/json"); + }); + it('registering as citizen without fist name should return 400', async () => { + const res = await axios.post(base + '/api/runners/register', { + "middlename": "string", + "lastname": "string", + "email": "user@example.com" + }, axios_config); + expect(res.status).toEqual(400); + expect(res.headers['content-type']).toContain("application/json"); + }); + it('registering as citizen without last name should return 400', async () => { + const res = await axios.post(base + '/api/runners/register', { + "firstname": "string", + "middlename": "string", + "email": "user@example.com" + }, axios_config); + expect(res.status).toEqual(400); + expect(res.headers['content-type']).toContain("application/json"); + }); + it('registering as citizen with invalid mail should return 400', async () => { + const res = await axios.post(base + '/api/runners/register', { + "firstname": "string", + "middlename": "string", + "lastname": "string", + "phone": "peter", + "email": "user@example.com" + }, axios_config); + expect(res.status).toEqual(400); + expect(res.headers['content-type']).toContain("application/json"); + }); +}); +// --------------- +describe('register citizen valid', () => { + it('registering as citizen with minimal params should return 200', async () => { + const res = await axios.post(base + '/api/runners/register', { + "firstname": "string", + "lastname": "string", + "email": "user@example.com" + }, axios_config); + expect(res.status).toEqual(200); + expect(res.headers['content-type']).toContain("application/json"); + }); + it('registering as citizen with all params should return 200', async () => { + const res = await axios.post(base + '/api/runners/register', { + "firstname": "string", + "middlename": "string", + "lastname": "string", + "email": "user@example.com", + "phone": "+4909132123456", + "address": { + address1: "Teststreet 1", + address2: "Testapartement", + postalcode: "91074", + city: "Herzo", + country: "Germany" + } + }, axios_config); + expect(res.status).toEqual(200); + expect(res.headers['content-type']).toContain("application/json"); + }); +}); +// --------------- +describe('register invalid company', () => { + let added_org; + it('creating a new org with just a name and registration enabled should return 200', async () => { + const res = await axios.post(base + '/api/organizations', { + "name": "test123", + "registrationEnabled": true + }, axios_config); + added_org = res.data; + expect(res.status).toEqual(200); + expect(res.headers['content-type']).toContain("application/json") + }); + it('registering with bs token should return 404', async () => { + const res = await axios.post(base + '/api/runners/register/4040404', { + "firstname": "string", + "middlename": "string", + "lastname": "string", + }, axios_config); + expect(res.status).toEqual(404); + expect(res.headers['content-type']).toContain("application/json"); + }); + it('registering without firstname should return 400', async () => { + const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { + "middlename": "string", + "lastname": "string", + }, axios_config); + expect(res.status).toEqual(400); + expect(res.headers['content-type']).toContain("application/json"); + }); + it('registering without lastname should return 400', async () => { + const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { + "middlename": "string", + "firstname": "string", + }, axios_config); + expect(res.status).toEqual(400); + expect(res.headers['content-type']).toContain("application/json"); + }); + it('registering with bs mail should return 400', async () => { + const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { + "firstname": "string", + "middlename": "string", + "lastname": "string", + "email": "true" + }, axios_config); + expect(res.status).toEqual(400); + expect(res.headers['content-type']).toContain("application/json"); + }); + it('registering with invalid team should return 404', async () => { + const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { + "firstname": "string", + "lastname": "string", + "team": 9999999999999999999999 + }, axios_config); + expect(res.status).toEqual(404); + expect(res.headers['content-type']).toContain("application/json"); + }); +}); +// --------------- +describe('register valid company', () => { + let added_org; + let added_team; + it('creating a new org with just a name and registration enabled should return 200', async () => { + const res = await axios.post(base + '/api/organizations', { + "name": "test123", + "registrationEnabled": true + }, axios_config); + added_org = res.data; + expect(res.status).toEqual(200); + expect(res.headers['content-type']).toContain("application/json") + }); + it('creating a new team with a parent org should return 200', async () => { + const res = await axios.post(base + '/api/teams', { + "name": "test_team", + "parentGroup": added_org.id + }, axios_config); + added_team = res.data; + expect(res.status).toEqual(200); + expect(res.headers['content-type']).toContain("application/json") + }); + it('registering with minimal params should return 200', async () => { + const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { + "firstname": "string", + "lastname": "string", + }, axios_config); + expect(res.status).toEqual(200); + expect(res.headers['content-type']).toContain("application/json"); + }); + it('registering with all params except team should return 200', async () => { + const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { + "firstname": "string", + "middlename": "string", + "lastname": "string", + "email": "user@example.com", + "phone": "+4909132123456", + "address": { + address1: "Teststreet 1", + address2: "Testapartement", + postalcode: "91074", + city: "Herzo", + country: "Germany" + } + }, axios_config); + expect(res.status).toEqual(200); + expect(res.headers['content-type']).toContain("application/json"); + }); + it('registering with minimal params and team should return 200', async () => { + const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { + "firstname": "string", + "lastname": "string", + "team": added_team.id + }, axios_config); + expect(res.status).toEqual(200); + expect(res.headers['content-type']).toContain("application/json"); + }); + it('registering with all params except team should return 200', async () => { + const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { + "firstname": "string", + "middlename": "string", + "lastname": "string", + "email": "user@example.com", + "phone": "+4909132123456", + "address": { + address1: "Teststreet 1", + address2: "Testapartement", + postalcode: "91074", + city: "Herzo", + country: "Germany" + } + }, axios_config); + expect(res.status).toEqual(200); + expect(res.headers['content-type']).toContain("application/json"); + }); + it('registering with all params and team should return 200', async () => { + const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { + "firstname": "string", + "middlename": "string", + "lastname": "string", + "email": "user@example.com", + "phone": "+4909132123456", + "address": { + address1: "Teststreet 1", + address2: "Testapartement", + postalcode: "91074", + city: "Herzo", + country: "Germany" + }, + "team": added_team.id + }, axios_config); + expect(res.status).toEqual(200); + expect(res.headers['content-type']).toContain("application/json"); + }); +}); \ No newline at end of file diff --git a/src/tests/selfservice/selfservice_register.spec.ts b/src/tests/selfservice/selfservice_register.spec.ts index 36dc7fa..576445c 100644 --- a/src/tests/selfservice/selfservice_register.spec.ts +++ b/src/tests/selfservice/selfservice_register.spec.ts @@ -14,236 +14,52 @@ beforeAll(async () => { validateStatus: undefined }; }); - -describe('register invalid citizen', () => { - it('registering as citizen without mail should return 406', async () => { - const res = await axios.post(base + '/api/runners/register', { - "firstname": "string", - "middlename": "string", - "lastname": "string", - }, axios_config); - expect(res.status).toEqual(406); - expect(res.headers['content-type']).toContain("application/json"); - }); - it('registering as citizen with invalid mail should return 400', async () => { - const res = await axios.post(base + '/api/runners/register', { - "firstname": "string", - "middlename": "string", - "lastname": "string", - "email": "user" - }, axios_config); - expect(res.status).toEqual(400); - expect(res.headers['content-type']).toContain("application/json"); - }); - it('registering as citizen without fist name should return 400', async () => { - const res = await axios.post(base + '/api/runners/register', { - "middlename": "string", - "lastname": "string", - "email": "user@example.com" - }, axios_config); - expect(res.status).toEqual(400); - expect(res.headers['content-type']).toContain("application/json"); - }); - it('registering as citizen without last name should return 400', async () => { - const res = await axios.post(base + '/api/runners/register', { - "firstname": "string", - "middlename": "string", - "email": "user@example.com" - }, axios_config); - expect(res.status).toEqual(400); - expect(res.headers['content-type']).toContain("application/json"); - }); - it('registering as citizen with invalid mail should return 400', async () => { - const res = await axios.post(base + '/api/runners/register', { - "firstname": "string", - "middlename": "string", - "lastname": "string", - "phone": "peter", - "email": "user@example.com" - }, axios_config); - expect(res.status).toEqual(400); - expect(res.headers['content-type']).toContain("application/json"); - }); -}); // --------------- -describe('register citizen valid', () => { +describe('delete selfservice runner invalid', () => { + let added_runner; it('registering as citizen with minimal params should return 200', async () => { const res = await axios.post(base + '/api/runners/register', { "firstname": "string", "lastname": "string", "email": "user@example.com" }, axios_config); + added_runner = res.data; expect(res.status).toEqual(200); expect(res.headers['content-type']).toContain("application/json"); }); - it('registering as citizen with all params should return 200', async () => { + it('delete with valid jwt should return 200', async () => { + const res = await axios.delete(base + '/api/runners/me/' + added_runner.token, axios_config); + expect(res.status).toEqual(200); + expect(res.headers['content-type']).toContain("application/json"); + }); + it('delete with valid jwt but non-existant runner should return 200', async () => { + const res = await axios.delete(base + '/api/runners/me/' + added_runner.token, axios_config); + expect(res.status).toEqual(404); + expect(res.headers['content-type']).toContain("application/json"); + }); + it('delete with invalid jwt should return 401', async () => { + const res = await axios.delete(base + '/api/runners/me/123.123', axios_config); + expect(res.status).toEqual(401); + expect(res.headers['content-type']).toContain("application/json"); + }); +}); +// --------------- +describe('delete selfservice runner valid', () => { + let added_runner; + it('registering as citizen with minimal params should return 200', async () => { const res = await axios.post(base + '/api/runners/register', { "firstname": "string", - "middlename": "string", "lastname": "string", - "email": "user@example.com", - "phone": "+4909132123456", - "address": { - address1: "Teststreet 1", - address2: "Testapartement", - postalcode: "91074", - city: "Herzo", - country: "Germany" - } + "email": "user@example.com" }, axios_config); + added_runner = res.data; expect(res.status).toEqual(200); expect(res.headers['content-type']).toContain("application/json"); }); -}); -// --------------- -describe('register invalid company', () => { - let added_org; - it('creating a new org with just a name and registration enabled should return 200', async () => { - const res = await axios.post(base + '/api/organizations', { - "name": "test123", - "registrationEnabled": true - }, axios_config); - added_org = res.data; - expect(res.status).toEqual(200); - expect(res.headers['content-type']).toContain("application/json") - }); - it('registering with bs token should return 404', async () => { - const res = await axios.post(base + '/api/runners/register/4040404', { - "firstname": "string", - "middlename": "string", - "lastname": "string", - }, axios_config); - expect(res.status).toEqual(404); - expect(res.headers['content-type']).toContain("application/json"); - }); - it('registering without firstname should return 400', async () => { - const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { - "middlename": "string", - "lastname": "string", - }, axios_config); - expect(res.status).toEqual(400); - expect(res.headers['content-type']).toContain("application/json"); - }); - it('registering without lastname should return 400', async () => { - const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { - "middlename": "string", - "firstname": "string", - }, axios_config); - expect(res.status).toEqual(400); - expect(res.headers['content-type']).toContain("application/json"); - }); - it('registering with bs mail should return 400', async () => { - const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { - "firstname": "string", - "middlename": "string", - "lastname": "string", - "email": "true" - }, axios_config); - expect(res.status).toEqual(400); - expect(res.headers['content-type']).toContain("application/json"); - }); - it('registering with invalid team should return 404', async () => { - const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { - "firstname": "string", - "lastname": "string", - "team": 9999999999999999999999 - }, axios_config); - expect(res.status).toEqual(404); - expect(res.headers['content-type']).toContain("application/json"); - }); -}); -// --------------- -describe('register valid company', () => { - let added_org; - let added_team; - it('creating a new org with just a name and registration enabled should return 200', async () => { - const res = await axios.post(base + '/api/organizations', { - "name": "test123", - "registrationEnabled": true - }, axios_config); - added_org = res.data; - expect(res.status).toEqual(200); - expect(res.headers['content-type']).toContain("application/json") - }); - it('creating a new team with a parent org should return 200', async () => { - const res = await axios.post(base + '/api/teams', { - "name": "test_team", - "parentGroup": added_org.id - }, axios_config); - added_team = res.data; - expect(res.status).toEqual(200); - expect(res.headers['content-type']).toContain("application/json") - }); - it('registering with minimal params should return 200', async () => { - const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { - "firstname": "string", - "lastname": "string", - }, axios_config); - expect(res.status).toEqual(200); - expect(res.headers['content-type']).toContain("application/json"); - }); - it('registering with all params except team should return 200', async () => { - const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { - "firstname": "string", - "middlename": "string", - "lastname": "string", - "email": "user@example.com", - "phone": "+4909132123456", - "address": { - address1: "Teststreet 1", - address2: "Testapartement", - postalcode: "91074", - city: "Herzo", - country: "Germany" - } - }, axios_config); - expect(res.status).toEqual(200); - expect(res.headers['content-type']).toContain("application/json"); - }); - it('registering with minimal params and team should return 200', async () => { - const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { - "firstname": "string", - "lastname": "string", - "team": added_team.id - }, axios_config); - expect(res.status).toEqual(200); - expect(res.headers['content-type']).toContain("application/json"); - }); - it('registering with all params except team should return 200', async () => { - const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { - "firstname": "string", - "middlename": "string", - "lastname": "string", - "email": "user@example.com", - "phone": "+4909132123456", - "address": { - address1: "Teststreet 1", - address2: "Testapartement", - postalcode: "91074", - city: "Herzo", - country: "Germany" - } - }, axios_config); - expect(res.status).toEqual(200); - expect(res.headers['content-type']).toContain("application/json"); - }); - it('registering with all params and team should return 200', async () => { - const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { - "firstname": "string", - "middlename": "string", - "lastname": "string", - "email": "user@example.com", - "phone": "+4909132123456", - "address": { - address1: "Teststreet 1", - address2: "Testapartement", - postalcode: "91074", - city: "Herzo", - country: "Germany" - }, - "team": added_team.id - }, axios_config); + it('delete with valid jwt should return 200', async () => { + const res = await axios.delete(base + '/api/runners/me/' + added_runner.token, axios_config); expect(res.status).toEqual(200); expect(res.headers['content-type']).toContain("application/json"); + expect(res.data).toEqual(added_runner); }); }); \ No newline at end of file From 88844e1a44d87a7dc253bf9aedf2fb3f6cdd1cfe Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Fri, 26 Mar 2021 15:53:45 +0000 Subject: [PATCH 5/7] =?UTF-8?q?=F0=9F=A7=BENew=20changelog=20file=20versio?= =?UTF-8?q?n=20[CI=20SKIP]=20[skip=20ci]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 68fab58..9776c0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,14 +4,16 @@ All notable changes to this project will be documented in this file. Dates are d #### [v0.7.1](https://git.odit.services/lfk/backend/compare/v0.7.0...v0.7.1) +- Merge pull request 'Release 0.7.1' (#173) from dev into main [`e76a9ce`](https://git.odit.services/lfk/backend/commit/e76a9cef956b00de7bbb11b6d863d4f33e3d5a34) - Revert "Set timeout even higher b/c sqlite just kills itself during these tests" [`f159252`](https://git.odit.services/lfk/backend/commit/f159252651942e442026dbcaae09b242e05d8204) - Set timeout even higher b/c sqlite just kills itself during these tests [`6ab6099`](https://git.odit.services/lfk/backend/commit/6ab60998d4f716aded93bb3b5d15594fc5e0434a) - Adjusted jest timeout to mitigate sqlite from invalidateing all tests⏱ [`30d220b`](https://git.odit.services/lfk/backend/commit/30d220bc36a28f224406e49ed27ff3f6b4f409e9) - 🧾New changelog file version [CI SKIP] [skip ci] [`963253c`](https://git.odit.services/lfk/backend/commit/963253cbc84ed07af13ed0925952ec1b7dcc53ad) -- Now resolveing runnercards [`24aff3b`](https://git.odit.services/lfk/backend/commit/24aff3bac458a9886ca40163484bc72733dc766a) -- Tests now keep the group [`f3d73d5`](https://git.odit.services/lfk/backend/commit/f3d73d53467a4d00011d280c24e1e12fbb8e443d) +- 🧾New changelog file version [CI SKIP] [skip ci] [`3ef3a94`](https://git.odit.services/lfk/backend/commit/3ef3a94b20c1abf6fd2f19472e5f448b4c72bd7f) - 🚀Bumped version to v0.7.1 [`135852e`](https://git.odit.services/lfk/backend/commit/135852eb9a91010a4ab972ba9efc7b71dfe4d68f) - Merge pull request 'RESPONSERUNNERCARD fix bugfix/171-responserunnercards' (#172) from bugfix/171-responserunnercards into dev [`539a650`](https://git.odit.services/lfk/backend/commit/539a6509b17cfd373eef8e443eaa7d41168ac7a9) +- Now resolveing runnercards [`24aff3b`](https://git.odit.services/lfk/backend/commit/24aff3bac458a9886ca40163484bc72733dc766a) +- Tests now keep the group [`f3d73d5`](https://git.odit.services/lfk/backend/commit/f3d73d53467a4d00011d280c24e1e12fbb8e443d) - 🧾New changelog file version [CI SKIP] [skip ci] [`ce63043`](https://git.odit.services/lfk/backend/commit/ce63043887769e1f92a8c064d6647e0deb81b7fa) #### [v0.7.0](https://git.odit.services/lfk/backend/compare/v0.6.4...v0.7.0) From 97159dd9f81aed080c174a3eb8da9e66dfea9b10 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Fri, 26 Mar 2021 16:56:45 +0100 Subject: [PATCH 6/7] Removed param from test ref #174 --- .../selfservice/selfservice_delete.spec.ts | 241 +++--------------- .../selfservice/selfservice_register.spec.ts | 230 +++++++++++++++-- 2 files changed, 236 insertions(+), 235 deletions(-) diff --git a/src/tests/selfservice/selfservice_delete.spec.ts b/src/tests/selfservice/selfservice_delete.spec.ts index 36dc7fa..9add148 100644 --- a/src/tests/selfservice/selfservice_delete.spec.ts +++ b/src/tests/selfservice/selfservice_delete.spec.ts @@ -14,236 +14,53 @@ beforeAll(async () => { validateStatus: undefined }; }); - -describe('register invalid citizen', () => { - it('registering as citizen without mail should return 406', async () => { - const res = await axios.post(base + '/api/runners/register', { - "firstname": "string", - "middlename": "string", - "lastname": "string", - }, axios_config); - expect(res.status).toEqual(406); - expect(res.headers['content-type']).toContain("application/json"); - }); - it('registering as citizen with invalid mail should return 400', async () => { - const res = await axios.post(base + '/api/runners/register', { - "firstname": "string", - "middlename": "string", - "lastname": "string", - "email": "user" - }, axios_config); - expect(res.status).toEqual(400); - expect(res.headers['content-type']).toContain("application/json"); - }); - it('registering as citizen without fist name should return 400', async () => { - const res = await axios.post(base + '/api/runners/register', { - "middlename": "string", - "lastname": "string", - "email": "user@example.com" - }, axios_config); - expect(res.status).toEqual(400); - expect(res.headers['content-type']).toContain("application/json"); - }); - it('registering as citizen without last name should return 400', async () => { - const res = await axios.post(base + '/api/runners/register', { - "firstname": "string", - "middlename": "string", - "email": "user@example.com" - }, axios_config); - expect(res.status).toEqual(400); - expect(res.headers['content-type']).toContain("application/json"); - }); - it('registering as citizen with invalid mail should return 400', async () => { - const res = await axios.post(base + '/api/runners/register', { - "firstname": "string", - "middlename": "string", - "lastname": "string", - "phone": "peter", - "email": "user@example.com" - }, axios_config); - expect(res.status).toEqual(400); - expect(res.headers['content-type']).toContain("application/json"); - }); -}); // --------------- -describe('register citizen valid', () => { +describe('delete selfservice runner invalid', () => { + let added_runner; it('registering as citizen with minimal params should return 200', async () => { const res = await axios.post(base + '/api/runners/register', { "firstname": "string", "lastname": "string", "email": "user@example.com" }, axios_config); + added_runner = res.data; expect(res.status).toEqual(200); expect(res.headers['content-type']).toContain("application/json"); }); - it('registering as citizen with all params should return 200', async () => { + it('delete with valid jwt should return 200', async () => { + const res = await axios.delete(base + '/api/runners/me/' + added_runner.token, axios_config); + expect(res.status).toEqual(200); + expect(res.headers['content-type']).toContain("application/json"); + }); + it('delete with valid jwt but non-existant runner should return 200', async () => { + const res = await axios.delete(base + '/api/runners/me/' + added_runner.token, axios_config); + expect(res.status).toEqual(404); + expect(res.headers['content-type']).toContain("application/json"); + }); + it('delete with invalid jwt should return 401', async () => { + const res = await axios.delete(base + '/api/runners/me/123.123', axios_config); + expect(res.status).toEqual(401); + expect(res.headers['content-type']).toContain("application/json"); + }); +}); +// --------------- +describe('delete selfservice runner valid', () => { + let added_runner; + it('registering as citizen with minimal params should return 200', async () => { const res = await axios.post(base + '/api/runners/register', { "firstname": "string", - "middlename": "string", "lastname": "string", - "email": "user@example.com", - "phone": "+4909132123456", - "address": { - address1: "Teststreet 1", - address2: "Testapartement", - postalcode: "91074", - city: "Herzo", - country: "Germany" - } + "email": "user@example.com" }, axios_config); + added_runner = res.data; expect(res.status).toEqual(200); expect(res.headers['content-type']).toContain("application/json"); }); -}); -// --------------- -describe('register invalid company', () => { - let added_org; - it('creating a new org with just a name and registration enabled should return 200', async () => { - const res = await axios.post(base + '/api/organizations', { - "name": "test123", - "registrationEnabled": true - }, axios_config); - added_org = res.data; - expect(res.status).toEqual(200); - expect(res.headers['content-type']).toContain("application/json") - }); - it('registering with bs token should return 404', async () => { - const res = await axios.post(base + '/api/runners/register/4040404', { - "firstname": "string", - "middlename": "string", - "lastname": "string", - }, axios_config); - expect(res.status).toEqual(404); - expect(res.headers['content-type']).toContain("application/json"); - }); - it('registering without firstname should return 400', async () => { - const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { - "middlename": "string", - "lastname": "string", - }, axios_config); - expect(res.status).toEqual(400); - expect(res.headers['content-type']).toContain("application/json"); - }); - it('registering without lastname should return 400', async () => { - const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { - "middlename": "string", - "firstname": "string", - }, axios_config); - expect(res.status).toEqual(400); - expect(res.headers['content-type']).toContain("application/json"); - }); - it('registering with bs mail should return 400', async () => { - const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { - "firstname": "string", - "middlename": "string", - "lastname": "string", - "email": "true" - }, axios_config); - expect(res.status).toEqual(400); - expect(res.headers['content-type']).toContain("application/json"); - }); - it('registering with invalid team should return 404', async () => { - const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { - "firstname": "string", - "lastname": "string", - "team": 9999999999999999999999 - }, axios_config); - expect(res.status).toEqual(404); - expect(res.headers['content-type']).toContain("application/json"); - }); -}); -// --------------- -describe('register valid company', () => { - let added_org; - let added_team; - it('creating a new org with just a name and registration enabled should return 200', async () => { - const res = await axios.post(base + '/api/organizations', { - "name": "test123", - "registrationEnabled": true - }, axios_config); - added_org = res.data; - expect(res.status).toEqual(200); - expect(res.headers['content-type']).toContain("application/json") - }); - it('creating a new team with a parent org should return 200', async () => { - const res = await axios.post(base + '/api/teams', { - "name": "test_team", - "parentGroup": added_org.id - }, axios_config); - added_team = res.data; - expect(res.status).toEqual(200); - expect(res.headers['content-type']).toContain("application/json") - }); - it('registering with minimal params should return 200', async () => { - const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { - "firstname": "string", - "lastname": "string", - }, axios_config); - expect(res.status).toEqual(200); - expect(res.headers['content-type']).toContain("application/json"); - }); - it('registering with all params except team should return 200', async () => { - const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { - "firstname": "string", - "middlename": "string", - "lastname": "string", - "email": "user@example.com", - "phone": "+4909132123456", - "address": { - address1: "Teststreet 1", - address2: "Testapartement", - postalcode: "91074", - city: "Herzo", - country: "Germany" - } - }, axios_config); - expect(res.status).toEqual(200); - expect(res.headers['content-type']).toContain("application/json"); - }); - it('registering with minimal params and team should return 200', async () => { - const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { - "firstname": "string", - "lastname": "string", - "team": added_team.id - }, axios_config); - expect(res.status).toEqual(200); - expect(res.headers['content-type']).toContain("application/json"); - }); - it('registering with all params except team should return 200', async () => { - const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { - "firstname": "string", - "middlename": "string", - "lastname": "string", - "email": "user@example.com", - "phone": "+4909132123456", - "address": { - address1: "Teststreet 1", - address2: "Testapartement", - postalcode: "91074", - city: "Herzo", - country: "Germany" - } - }, axios_config); - expect(res.status).toEqual(200); - expect(res.headers['content-type']).toContain("application/json"); - }); - it('registering with all params and team should return 200', async () => { - const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { - "firstname": "string", - "middlename": "string", - "lastname": "string", - "email": "user@example.com", - "phone": "+4909132123456", - "address": { - address1: "Teststreet 1", - address2: "Testapartement", - postalcode: "91074", - city: "Herzo", - country: "Germany" - }, - "team": added_team.id - }, axios_config); + it('delete with valid jwt should return 200', async () => { + const res = await axios.delete(base + '/api/runners/me/' + added_runner.token, axios_config); expect(res.status).toEqual(200); expect(res.headers['content-type']).toContain("application/json"); + delete added_runner.token; + expect(res.data).toEqual(added_runner); }); }); \ No newline at end of file diff --git a/src/tests/selfservice/selfservice_register.spec.ts b/src/tests/selfservice/selfservice_register.spec.ts index 576445c..36dc7fa 100644 --- a/src/tests/selfservice/selfservice_register.spec.ts +++ b/src/tests/selfservice/selfservice_register.spec.ts @@ -14,52 +14,236 @@ beforeAll(async () => { validateStatus: undefined }; }); -// --------------- -describe('delete selfservice runner invalid', () => { - let added_runner; - it('registering as citizen with minimal params should return 200', async () => { + +describe('register invalid citizen', () => { + it('registering as citizen without mail should return 406', async () => { const res = await axios.post(base + '/api/runners/register', { "firstname": "string", + "middlename": "string", + "lastname": "string", + }, axios_config); + expect(res.status).toEqual(406); + expect(res.headers['content-type']).toContain("application/json"); + }); + it('registering as citizen with invalid mail should return 400', async () => { + const res = await axios.post(base + '/api/runners/register', { + "firstname": "string", + "middlename": "string", + "lastname": "string", + "email": "user" + }, axios_config); + expect(res.status).toEqual(400); + expect(res.headers['content-type']).toContain("application/json"); + }); + it('registering as citizen without fist name should return 400', async () => { + const res = await axios.post(base + '/api/runners/register', { + "middlename": "string", "lastname": "string", "email": "user@example.com" }, axios_config); - added_runner = res.data; - expect(res.status).toEqual(200); + expect(res.status).toEqual(400); expect(res.headers['content-type']).toContain("application/json"); }); - it('delete with valid jwt should return 200', async () => { - const res = await axios.delete(base + '/api/runners/me/' + added_runner.token, axios_config); - expect(res.status).toEqual(200); + it('registering as citizen without last name should return 400', async () => { + const res = await axios.post(base + '/api/runners/register', { + "firstname": "string", + "middlename": "string", + "email": "user@example.com" + }, axios_config); + expect(res.status).toEqual(400); expect(res.headers['content-type']).toContain("application/json"); }); - it('delete with valid jwt but non-existant runner should return 200', async () => { - const res = await axios.delete(base + '/api/runners/me/' + added_runner.token, axios_config); - expect(res.status).toEqual(404); - expect(res.headers['content-type']).toContain("application/json"); - }); - it('delete with invalid jwt should return 401', async () => { - const res = await axios.delete(base + '/api/runners/me/123.123', axios_config); - expect(res.status).toEqual(401); + it('registering as citizen with invalid mail should return 400', async () => { + const res = await axios.post(base + '/api/runners/register', { + "firstname": "string", + "middlename": "string", + "lastname": "string", + "phone": "peter", + "email": "user@example.com" + }, axios_config); + expect(res.status).toEqual(400); expect(res.headers['content-type']).toContain("application/json"); }); }); // --------------- -describe('delete selfservice runner valid', () => { - let added_runner; +describe('register citizen valid', () => { it('registering as citizen with minimal params should return 200', async () => { const res = await axios.post(base + '/api/runners/register', { "firstname": "string", "lastname": "string", "email": "user@example.com" }, axios_config); - added_runner = res.data; expect(res.status).toEqual(200); expect(res.headers['content-type']).toContain("application/json"); }); - it('delete with valid jwt should return 200', async () => { - const res = await axios.delete(base + '/api/runners/me/' + added_runner.token, axios_config); + it('registering as citizen with all params should return 200', async () => { + const res = await axios.post(base + '/api/runners/register', { + "firstname": "string", + "middlename": "string", + "lastname": "string", + "email": "user@example.com", + "phone": "+4909132123456", + "address": { + address1: "Teststreet 1", + address2: "Testapartement", + postalcode: "91074", + city: "Herzo", + country: "Germany" + } + }, axios_config); + expect(res.status).toEqual(200); + expect(res.headers['content-type']).toContain("application/json"); + }); +}); +// --------------- +describe('register invalid company', () => { + let added_org; + it('creating a new org with just a name and registration enabled should return 200', async () => { + const res = await axios.post(base + '/api/organizations', { + "name": "test123", + "registrationEnabled": true + }, axios_config); + added_org = res.data; + expect(res.status).toEqual(200); + expect(res.headers['content-type']).toContain("application/json") + }); + it('registering with bs token should return 404', async () => { + const res = await axios.post(base + '/api/runners/register/4040404', { + "firstname": "string", + "middlename": "string", + "lastname": "string", + }, axios_config); + expect(res.status).toEqual(404); + expect(res.headers['content-type']).toContain("application/json"); + }); + it('registering without firstname should return 400', async () => { + const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { + "middlename": "string", + "lastname": "string", + }, axios_config); + expect(res.status).toEqual(400); + expect(res.headers['content-type']).toContain("application/json"); + }); + it('registering without lastname should return 400', async () => { + const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { + "middlename": "string", + "firstname": "string", + }, axios_config); + expect(res.status).toEqual(400); + expect(res.headers['content-type']).toContain("application/json"); + }); + it('registering with bs mail should return 400', async () => { + const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { + "firstname": "string", + "middlename": "string", + "lastname": "string", + "email": "true" + }, axios_config); + expect(res.status).toEqual(400); + expect(res.headers['content-type']).toContain("application/json"); + }); + it('registering with invalid team should return 404', async () => { + const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { + "firstname": "string", + "lastname": "string", + "team": 9999999999999999999999 + }, axios_config); + expect(res.status).toEqual(404); + expect(res.headers['content-type']).toContain("application/json"); + }); +}); +// --------------- +describe('register valid company', () => { + let added_org; + let added_team; + it('creating a new org with just a name and registration enabled should return 200', async () => { + const res = await axios.post(base + '/api/organizations', { + "name": "test123", + "registrationEnabled": true + }, axios_config); + added_org = res.data; + expect(res.status).toEqual(200); + expect(res.headers['content-type']).toContain("application/json") + }); + it('creating a new team with a parent org should return 200', async () => { + const res = await axios.post(base + '/api/teams', { + "name": "test_team", + "parentGroup": added_org.id + }, axios_config); + added_team = res.data; + expect(res.status).toEqual(200); + expect(res.headers['content-type']).toContain("application/json") + }); + it('registering with minimal params should return 200', async () => { + const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { + "firstname": "string", + "lastname": "string", + }, axios_config); + expect(res.status).toEqual(200); + expect(res.headers['content-type']).toContain("application/json"); + }); + it('registering with all params except team should return 200', async () => { + const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { + "firstname": "string", + "middlename": "string", + "lastname": "string", + "email": "user@example.com", + "phone": "+4909132123456", + "address": { + address1: "Teststreet 1", + address2: "Testapartement", + postalcode: "91074", + city: "Herzo", + country: "Germany" + } + }, axios_config); + expect(res.status).toEqual(200); + expect(res.headers['content-type']).toContain("application/json"); + }); + it('registering with minimal params and team should return 200', async () => { + const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { + "firstname": "string", + "lastname": "string", + "team": added_team.id + }, axios_config); + expect(res.status).toEqual(200); + expect(res.headers['content-type']).toContain("application/json"); + }); + it('registering with all params except team should return 200', async () => { + const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { + "firstname": "string", + "middlename": "string", + "lastname": "string", + "email": "user@example.com", + "phone": "+4909132123456", + "address": { + address1: "Teststreet 1", + address2: "Testapartement", + postalcode: "91074", + city: "Herzo", + country: "Germany" + } + }, axios_config); + expect(res.status).toEqual(200); + expect(res.headers['content-type']).toContain("application/json"); + }); + it('registering with all params and team should return 200', async () => { + const res = await axios.post(base + '/api/runners/register/' + added_org.registrationKey, { + "firstname": "string", + "middlename": "string", + "lastname": "string", + "email": "user@example.com", + "phone": "+4909132123456", + "address": { + address1: "Teststreet 1", + address2: "Testapartement", + postalcode: "91074", + city: "Herzo", + country: "Germany" + }, + "team": added_team.id + }, axios_config); expect(res.status).toEqual(200); expect(res.headers['content-type']).toContain("application/json"); - expect(res.data).toEqual(added_runner); }); }); \ No newline at end of file From c9bd6de4762fec04e1e02cd3b667838d05ef39a7 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Fri, 26 Mar 2021 16:19:28 +0000 Subject: [PATCH 7/7] =?UTF-8?q?=F0=9F=A7=BENew=20changelog=20file=20versio?= =?UTF-8?q?n=20[CI=20SKIP]=20[skip=20ci]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9776c0f..32df7de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,20 @@ All notable changes to this project will be documented in this file. Dates are displayed in UTC. +#### [v0.7.1](https://git.odit.services/lfk/backend/compare/v0.7.1...v0.7.1) + +- Merge pull request 'Selfservice deletion feature/174-selfservice_deletion' (#175) from feature/174-selfservice_deletion into dev [`e702118`](https://git.odit.services/lfk/backend/commit/e702118d4d80e362e41bb88c74343d50530d1338) +- Added tests for the new endpoint [`20aeed8`](https://git.odit.services/lfk/backend/commit/20aeed87780247dc6401bba725801fc1874e50b5) +- Removed param from test [`97159dd`](https://git.odit.services/lfk/backend/commit/97159dd9f81aed080c174a3eb8da9e66dfea9b10) +- Added selfservice deletion endpoint [`dcb12b0`](https://git.odit.services/lfk/backend/commit/dcb12b0ac289f8df148ba10ae6389727c16f53fd) +- 🧾New changelog file version [CI SKIP] [skip ci] [`88844e1`](https://git.odit.services/lfk/backend/commit/88844e1a44d87a7dc253bf9aedf2fb3f6cdd1cfe) +- Fixed response bug [`ccb7ae2`](https://git.odit.services/lfk/backend/commit/ccb7ae29a39387c0f2762861565dc22996a2493a) +- Updated old hint [`dd12583`](https://git.odit.services/lfk/backend/commit/dd1258333ef67243f8a8df97c176ec5a054a5e3b) + #### [v0.7.1](https://git.odit.services/lfk/backend/compare/v0.7.0...v0.7.1) +> 26 March 2021 + - Merge pull request 'Release 0.7.1' (#173) from dev into main [`e76a9ce`](https://git.odit.services/lfk/backend/commit/e76a9cef956b00de7bbb11b6d863d4f33e3d5a34) - Revert "Set timeout even higher b/c sqlite just kills itself during these tests" [`f159252`](https://git.odit.services/lfk/backend/commit/f159252651942e442026dbcaae09b242e05d8204) - Set timeout even higher b/c sqlite just kills itself during these tests [`6ab6099`](https://git.odit.services/lfk/backend/commit/6ab60998d4f716aded93bb3b5d15594fc5e0434a)