Compare commits
4 Commits
v0.7.1
...
20aeed8778
| Author | SHA1 | Date | |
|---|---|---|---|
| 20aeed8778 | |||
| ccb7ae29a3 | |||
| dcb12b0ac2 | |||
| dd1258333e |
@@ -1,12 +1,12 @@
|
|||||||
import { Request } from "express";
|
import { Request } from "express";
|
||||||
import * as jwt from "jsonwebtoken";
|
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 { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||||
import { getConnectionManager, Repository } from 'typeorm';
|
import { getConnectionManager, Repository } from 'typeorm';
|
||||||
import { config } from '../config';
|
import { config } from '../config';
|
||||||
import { InvalidCredentialsError, JwtNotProvidedError } from '../errors/AuthError';
|
import { InvalidCredentialsError, JwtNotProvidedError } from '../errors/AuthError';
|
||||||
import { MailSendingError } from '../errors/MailErrors';
|
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 { RunnerOrganizationNotFoundError } from '../errors/RunnerOrganizationErrors';
|
||||||
import { ScanStationNotFoundError } from '../errors/ScanStationErrors';
|
import { ScanStationNotFoundError } from '../errors/ScanStationErrors';
|
||||||
import { JwtCreator } from '../jwtcreator';
|
import { JwtCreator } from '../jwtcreator';
|
||||||
@@ -23,6 +23,9 @@ import { ResponseScanStation } from '../models/responses/ResponseScanStation';
|
|||||||
import { ResponseSelfServiceOrganisation } from '../models/responses/ResponseSelfServiceOrganisation';
|
import { ResponseSelfServiceOrganisation } from '../models/responses/ResponseSelfServiceOrganisation';
|
||||||
import { ResponseSelfServiceRunner } from '../models/responses/ResponseSelfServiceRunner';
|
import { ResponseSelfServiceRunner } from '../models/responses/ResponseSelfServiceRunner';
|
||||||
import { ResponseSelfServiceScan } from '../models/responses/ResponseSelfServiceScan';
|
import { ResponseSelfServiceScan } from '../models/responses/ResponseSelfServiceScan';
|
||||||
|
import { DonationController } from './DonationController';
|
||||||
|
import { RunnerCardController } from './RunnerCardController';
|
||||||
|
import { ScanController } from './ScanController';
|
||||||
|
|
||||||
@JsonController()
|
@JsonController()
|
||||||
export class RunnerSelfServiceController {
|
export class RunnerSelfServiceController {
|
||||||
@@ -43,11 +46,50 @@ export class RunnerSelfServiceController {
|
|||||||
@ResponseSchema(ResponseSelfServiceRunner)
|
@ResponseSchema(ResponseSelfServiceRunner)
|
||||||
@ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
|
@ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
|
||||||
@OnUndefined(RunnerNotFoundError)
|
@OnUndefined(RunnerNotFoundError)
|
||||||
@OpenAPI({ description: 'Lists all information about yourself. <br> Please provide your runner jwt(that code we gave you during registration) for auth. <br> If you lost your jwt/personalized link please contact support.' })
|
@OpenAPI({ description: 'Lists all information about yourself. <br> Please provide your runner jwt(that code we gave you during registration) for auth. <br> If you lost your jwt/personalized link please use the forgot endpoint.' })
|
||||||
async get(@Param('jwt') token: string) {
|
async get(@Param('jwt') token: string) {
|
||||||
return (new ResponseSelfServiceRunner(await this.getRunner(token)));
|
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. <br> Please provide your runner jwt(that code we gave you during registration) for auth. <br> If you lost your jwt/personalized link please use the forgot endpoint.' })
|
||||||
|
async remove(@Param('jwt') token: string, @QueryParam("force") force: boolean) {
|
||||||
|
const responseRunner = await this.getRunner(token);
|
||||||
|
let runner = await this.runnerRepository.findOne({ id: responseRunner.id });
|
||||||
|
|
||||||
|
if (!runner) { return null; }
|
||||||
|
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')
|
@Get('/runners/me/:jwt/scans')
|
||||||
@ResponseSchema(ResponseSelfServiceScan, { isArray: true })
|
@ResponseSchema(ResponseSelfServiceScan, { isArray: true })
|
||||||
@ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
|
@ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
|
||||||
|
|||||||
249
src/tests/selfservice/selfservice_delete.spec.ts
Normal file
249
src/tests/selfservice/selfservice_delete.spec.ts
Normal file
@@ -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");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -14,236 +14,52 @@ beforeAll(async () => {
|
|||||||
validateStatus: undefined
|
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 () => {
|
it('registering as citizen with minimal params should return 200', async () => {
|
||||||
const res = await axios.post(base + '/api/runners/register', {
|
const res = await axios.post(base + '/api/runners/register', {
|
||||||
"firstname": "string",
|
"firstname": "string",
|
||||||
"lastname": "string",
|
"lastname": "string",
|
||||||
"email": "user@example.com"
|
"email": "user@example.com"
|
||||||
}, axios_config);
|
}, axios_config);
|
||||||
|
added_runner = res.data;
|
||||||
expect(res.status).toEqual(200);
|
expect(res.status).toEqual(200);
|
||||||
expect(res.headers['content-type']).toContain("application/json");
|
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', {
|
const res = await axios.post(base + '/api/runners/register', {
|
||||||
"firstname": "string",
|
"firstname": "string",
|
||||||
"middlename": "string",
|
|
||||||
"lastname": "string",
|
"lastname": "string",
|
||||||
"email": "user@example.com",
|
"email": "user@example.com"
|
||||||
"phone": "+4909132123456",
|
|
||||||
"address": {
|
|
||||||
address1: "Teststreet 1",
|
|
||||||
address2: "Testapartement",
|
|
||||||
postalcode: "91074",
|
|
||||||
city: "Herzo",
|
|
||||||
country: "Germany"
|
|
||||||
}
|
|
||||||
}, axios_config);
|
}, axios_config);
|
||||||
|
added_runner = res.data;
|
||||||
expect(res.status).toEqual(200);
|
expect(res.status).toEqual(200);
|
||||||
expect(res.headers['content-type']).toContain("application/json");
|
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);
|
||||||
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.status).toEqual(200);
|
||||||
expect(res.headers['content-type']).toContain("application/json");
|
expect(res.headers['content-type']).toContain("application/json");
|
||||||
|
expect(res.data).toEqual(added_runner);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user