Merge pull request 'Fully implemented addresses feature/105-addresses' (#107) from feature/105-addresses into dev
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Reviewed-on: #107
This commit is contained in:
commit
5e368552ea
2
.env.ci
2
.env.ci
|
@ -6,4 +6,4 @@ DB_USER=unused
|
|||
DB_PASSWORD=bla
|
||||
DB_NAME=./test.sqlite
|
||||
NODE_ENV=dev
|
||||
POSTALCODE_COUNTRYCODE=null
|
||||
POSTALCODE_COUNTRYCODE=DE
|
|
@ -29,7 +29,7 @@ export class RunnerOrganisationController {
|
|||
@OpenAPI({ description: 'Lists all organisations. <br> This includes their address, contact and teams (if existing/associated).' })
|
||||
async getAll() {
|
||||
let responseTeams: ResponseRunnerOrganisation[] = new Array<ResponseRunnerOrganisation>();
|
||||
const runners = await this.runnerOrganisationRepository.find({ relations: ['address', 'contact', 'teams'] });
|
||||
const runners = await this.runnerOrganisationRepository.find({ relations: ['contact', 'teams'] });
|
||||
runners.forEach(runner => {
|
||||
responseTeams.push(new ResponseRunnerOrganisation(runner));
|
||||
});
|
||||
|
@ -43,7 +43,7 @@ export class RunnerOrganisationController {
|
|||
@OnUndefined(RunnerOrganisationNotFoundError)
|
||||
@OpenAPI({ description: 'Lists all information about the organisation whose id got provided.' })
|
||||
async getOne(@Param('id') id: number) {
|
||||
let runnerOrg = await this.runnerOrganisationRepository.findOne({ id: id }, { relations: ['address', 'contact', 'teams'] });
|
||||
let runnerOrg = await this.runnerOrganisationRepository.findOne({ id: id }, { relations: ['contact', 'teams'] });
|
||||
if (!runnerOrg) { throw new RunnerOrganisationNotFoundError(); }
|
||||
return new ResponseRunnerOrganisation(runnerOrg);
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ export class RunnerOrganisationController {
|
|||
|
||||
runnerOrganisation = await this.runnerOrganisationRepository.save(runnerOrganisation);
|
||||
|
||||
return new ResponseRunnerOrganisation(await this.runnerOrganisationRepository.findOne(runnerOrganisation, { relations: ['address', 'contact', 'teams'] }));
|
||||
return new ResponseRunnerOrganisation(await this.runnerOrganisationRepository.findOne(runnerOrganisation, { relations: ['contact', 'teams'] }));
|
||||
}
|
||||
|
||||
@Put('/:id')
|
||||
|
@ -84,7 +84,7 @@ export class RunnerOrganisationController {
|
|||
|
||||
await this.runnerOrganisationRepository.save(await updateOrganisation.update(oldRunnerOrganisation));
|
||||
|
||||
return new ResponseRunnerOrganisation(await this.runnerOrganisationRepository.findOne(id, { relations: ['address', 'contact', 'teams'] }));
|
||||
return new ResponseRunnerOrganisation(await this.runnerOrganisationRepository.findOne(id, { relations: ['contact', 'teams'] }));
|
||||
}
|
||||
|
||||
@Delete('/:id')
|
||||
|
@ -98,7 +98,7 @@ export class RunnerOrganisationController {
|
|||
async remove(@Param("id") id: number, @QueryParam("force") force: boolean) {
|
||||
let organisation = await this.runnerOrganisationRepository.findOne({ id: id });
|
||||
if (!organisation) { return null; }
|
||||
let runnerOrganisation = await this.runnerOrganisationRepository.findOne(organisation, { relations: ['address', 'contact', 'runners', 'teams'] });
|
||||
let runnerOrganisation = await this.runnerOrganisationRepository.findOne(organisation, { relations: ['contact', 'runners', 'teams'] });
|
||||
|
||||
if (!force) {
|
||||
if (runnerOrganisation.teams.length != 0) {
|
||||
|
|
|
@ -1,24 +1,57 @@
|
|||
import { IsString } from 'class-validator';
|
||||
import { NotAcceptableError, NotFoundError } from 'routing-controllers';
|
||||
|
||||
/**
|
||||
* Error to throw, when to provided address doesn't belong to the accepted types.
|
||||
*/
|
||||
export class AddressWrongTypeError extends NotAcceptableError {
|
||||
@IsString()
|
||||
name = "AddressWrongTypeError"
|
||||
|
||||
@IsString()
|
||||
message = "The address must be an existing address's id. \n You provided a object of another type."
|
||||
}
|
||||
|
||||
/**
|
||||
* Error to throw, when a non-existent address get's loaded.
|
||||
*/
|
||||
export class AddressNotFoundError extends NotFoundError {
|
||||
@IsString()
|
||||
name = "AddressNotFoundError"
|
||||
|
||||
@IsString()
|
||||
message = "The address you provided couldn't be located in the system. \n Please check your request."
|
||||
import { IsString } from 'class-validator';
|
||||
import { BadRequestError } from 'routing-controllers';
|
||||
|
||||
/**
|
||||
* Error to throw when an address's postal code fails validation.
|
||||
*/
|
||||
export class AddressPostalCodeInvalidError extends BadRequestError {
|
||||
@IsString()
|
||||
name = "AddressPostalCodeInvalidError"
|
||||
|
||||
@IsString()
|
||||
message = "The postal code you provided is invalid. \n Please check if your postal code follows the postal code validation guidelines."
|
||||
}
|
||||
|
||||
/**
|
||||
* Error to throw when an non-empty address's first line isn't set.
|
||||
*/
|
||||
export class AddressFirstLineEmptyError extends BadRequestError {
|
||||
@IsString()
|
||||
name = "AddressFirstLineEmptyError"
|
||||
|
||||
@IsString()
|
||||
message = "You provided a empty first address line. \n If you want an empty address please set all propertys to null. \n For non-empty addresses the following fields have to be set: address1, postalcode, city, country"
|
||||
}
|
||||
|
||||
/**
|
||||
* Error to throw when an non-empty address's postal code isn't set.
|
||||
*/
|
||||
export class AddressPostalCodeEmptyError extends BadRequestError {
|
||||
@IsString()
|
||||
name = "AddressPostalCodeEmptyError"
|
||||
|
||||
@IsString()
|
||||
message = "You provided a empty postal code. \n If you want an empty address please set all propertys to null. \n For non-empty addresses the following fields have to be set: address1, postalcode, city, country"
|
||||
}
|
||||
|
||||
/**
|
||||
* Error to throw when an non-empty address's city isn't set.
|
||||
*/
|
||||
export class AddressCityEmptyError extends BadRequestError {
|
||||
@IsString()
|
||||
name = "AddressCityEmptyError"
|
||||
|
||||
@IsString()
|
||||
message = "You provided a empty city. \n If you want an empty address please set all propertys to null. \n For non-empty addresses the following fields have to be set: address1, postalcode, city, country"
|
||||
}
|
||||
|
||||
/**
|
||||
* Error to throw when an non-empty address's country isn't set.
|
||||
*/
|
||||
export class AddressCountryEmptyError extends BadRequestError {
|
||||
@IsString()
|
||||
name = "AddressCountryEmptyError"
|
||||
|
||||
@IsString()
|
||||
message = "You provided a empty country. \n If you want an empty address please set all propertys to null. \n For non-empty addresses the following fields have to be set: address1, postalcode, city, country"
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
import { IsNotEmpty, IsOptional, IsPostalCode, IsString } from 'class-validator';
|
||||
import { config } from '../../../config';
|
||||
import { Address } from '../../entities/Address';
|
||||
|
||||
/**
|
||||
* This classed is used to create a new Address entity from a json body (post request).
|
||||
*/
|
||||
export class CreateAddress {
|
||||
/**
|
||||
* The newaddress's description.
|
||||
*/
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
description?: string;
|
||||
|
||||
/**
|
||||
* The new address's first line.
|
||||
* Containing the street and house number.
|
||||
*/
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
address1: string;
|
||||
|
||||
/**
|
||||
* The new address's second line.
|
||||
* Containing optional information.
|
||||
*/
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
address2?: string;
|
||||
|
||||
/**
|
||||
* The new address's postal code.
|
||||
* This will get checked against the postal code syntax for the configured country.
|
||||
*/
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@IsPostalCode(config.postalcode_validation_countrycode)
|
||||
postalcode: string;
|
||||
|
||||
/**
|
||||
* The new address's city.
|
||||
*/
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
city: string;
|
||||
|
||||
/**
|
||||
* The new address's country.
|
||||
*/
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
country: string;
|
||||
|
||||
/**
|
||||
* Creates a new Address entity from this.
|
||||
*/
|
||||
public async toEntity(): Promise<Address> {
|
||||
let newAddress: Address = new Address();
|
||||
|
||||
newAddress.address1 = this.address1;
|
||||
newAddress.address2 = this.address2;
|
||||
newAddress.postalcode = this.postalcode;
|
||||
newAddress.city = this.city;
|
||||
newAddress.country = this.country;
|
||||
|
||||
return newAddress;
|
||||
}
|
||||
}
|
|
@ -1,38 +1,39 @@
|
|||
import { IsBoolean, IsOptional } from 'class-validator';
|
||||
import { DonorReceiptAddressNeededError } from '../../../errors/DonorErrors';
|
||||
import { Donor } from '../../entities/Donor';
|
||||
import { CreateParticipant } from './CreateParticipant';
|
||||
|
||||
/**
|
||||
* This classed is used to create a new Donor entity from a json body (post request).
|
||||
*/
|
||||
export class CreateDonor extends CreateParticipant {
|
||||
|
||||
/**
|
||||
* Does this donor need a receipt?
|
||||
*/
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
receiptNeeded?: boolean = false;
|
||||
|
||||
/**
|
||||
* Creates a new Donor entity from this.
|
||||
*/
|
||||
public async toEntity(): Promise<Donor> {
|
||||
let newDonor: Donor = new Donor();
|
||||
|
||||
newDonor.firstname = this.firstname;
|
||||
newDonor.middlename = this.middlename;
|
||||
newDonor.lastname = this.lastname;
|
||||
newDonor.phone = this.phone;
|
||||
newDonor.email = this.email;
|
||||
newDonor.address = await this.getAddress();
|
||||
newDonor.receiptNeeded = this.receiptNeeded;
|
||||
|
||||
if (this.receiptNeeded == true && this.address == null) {
|
||||
throw new DonorReceiptAddressNeededError()
|
||||
}
|
||||
|
||||
return newDonor;
|
||||
}
|
||||
import { IsBoolean, IsOptional } from 'class-validator';
|
||||
import { DonorReceiptAddressNeededError } from '../../../errors/DonorErrors';
|
||||
import { Address } from '../../entities/Address';
|
||||
import { Donor } from '../../entities/Donor';
|
||||
import { CreateParticipant } from './CreateParticipant';
|
||||
|
||||
/**
|
||||
* This classed is used to create a new Donor entity from a json body (post request).
|
||||
*/
|
||||
export class CreateDonor extends CreateParticipant {
|
||||
|
||||
/**
|
||||
* Does this donor need a receipt?
|
||||
*/
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
receiptNeeded?: boolean = false;
|
||||
|
||||
/**
|
||||
* Creates a new Donor entity from this.
|
||||
*/
|
||||
public async toEntity(): Promise<Donor> {
|
||||
let newDonor: Donor = new Donor();
|
||||
|
||||
newDonor.firstname = this.firstname;
|
||||
newDonor.middlename = this.middlename;
|
||||
newDonor.lastname = this.lastname;
|
||||
newDonor.phone = this.phone;
|
||||
newDonor.email = this.email;
|
||||
newDonor.receiptNeeded = this.receiptNeeded;
|
||||
newDonor.address = this.address;
|
||||
Address.validate(newDonor.address);
|
||||
if (this.receiptNeeded == true && Address.isValidAddress(newDonor.address) == false) {
|
||||
throw new DonorReceiptAddressNeededError()
|
||||
}
|
||||
|
||||
return newDonor;
|
||||
}
|
||||
}
|
|
@ -1,78 +1,68 @@
|
|||
import { IsEmail, IsInt, IsNotEmpty, IsOptional, IsPhoneNumber, IsString } from 'class-validator';
|
||||
import { getConnectionManager } from 'typeorm';
|
||||
import { config } from '../../../config';
|
||||
import { AddressNotFoundError } from '../../../errors/AddressErrors';
|
||||
import { Address } from '../../entities/Address';
|
||||
import { GroupContact } from '../../entities/GroupContact';
|
||||
|
||||
/**
|
||||
* This classed is used to create a new Group entity from a json body (post request).
|
||||
*/
|
||||
export class CreateGroupContact {
|
||||
/**
|
||||
* The new contact's first name.
|
||||
*/
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
firstname: string;
|
||||
|
||||
/**
|
||||
* The new contact's middle name.
|
||||
*/
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
middlename?: string;
|
||||
|
||||
/**
|
||||
* The new contact's last name.
|
||||
*/
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
lastname: string;
|
||||
|
||||
/**
|
||||
* The new contact's address's id.
|
||||
*/
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
address?: number;
|
||||
|
||||
/**
|
||||
* The contact's phone number.
|
||||
* This will be validated against the configured country phone numer syntax (default: international).
|
||||
*/
|
||||
@IsOptional()
|
||||
@IsPhoneNumber(config.phone_validation_countrycode)
|
||||
phone?: string;
|
||||
|
||||
/**
|
||||
* The contact's email address.
|
||||
*/
|
||||
@IsOptional()
|
||||
@IsEmail()
|
||||
email?: string;
|
||||
|
||||
/**
|
||||
* Gets the new contact's address by it's id.
|
||||
*/
|
||||
public async getAddress(): Promise<Address> {
|
||||
if (!this.address) { return null; }
|
||||
let address = await getConnectionManager().get().getRepository(Address).findOne({ id: this.address });
|
||||
if (!address) { throw new AddressNotFoundError; }
|
||||
return address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Address entity from this.
|
||||
*/
|
||||
public async toEntity(): Promise<GroupContact> {
|
||||
let contact: GroupContact = new GroupContact();
|
||||
contact.firstname = this.firstname;
|
||||
contact.middlename = this.middlename;
|
||||
contact.lastname = this.lastname;
|
||||
contact.email = this.email;
|
||||
contact.phone = this.phone;
|
||||
contact.address = await this.getAddress();
|
||||
return null;
|
||||
}
|
||||
import { IsEmail, IsNotEmpty, IsObject, IsOptional, IsPhoneNumber, IsString } from 'class-validator';
|
||||
import { config } from '../../../config';
|
||||
import { Address } from '../../entities/Address';
|
||||
import { GroupContact } from '../../entities/GroupContact';
|
||||
|
||||
/**
|
||||
* This classed is used to create a new Group entity from a json body (post request).
|
||||
*/
|
||||
export class CreateGroupContact {
|
||||
/**
|
||||
* The new contact's first name.
|
||||
*/
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
firstname: string;
|
||||
|
||||
/**
|
||||
* The new contact's middle name.
|
||||
*/
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
middlename?: string;
|
||||
|
||||
/**
|
||||
* The new contact's last name.
|
||||
*/
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
lastname: string;
|
||||
|
||||
/**
|
||||
* The new contact's address.
|
||||
*/
|
||||
@IsOptional()
|
||||
@IsObject()
|
||||
address?: Address;
|
||||
|
||||
/**
|
||||
* The contact's phone number.
|
||||
* This will be validated against the configured country phone numer syntax (default: international).
|
||||
*/
|
||||
@IsOptional()
|
||||
@IsPhoneNumber(config.phone_validation_countrycode)
|
||||
phone?: string;
|
||||
|
||||
/**
|
||||
* The contact's email address.
|
||||
*/
|
||||
@IsOptional()
|
||||
@IsEmail()
|
||||
email?: string;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new Address entity from this.
|
||||
*/
|
||||
public async toEntity(): Promise<GroupContact> {
|
||||
let contact: GroupContact = new GroupContact();
|
||||
contact.firstname = this.firstname;
|
||||
contact.middlename = this.middlename;
|
||||
contact.lastname = this.lastname;
|
||||
contact.email = this.email;
|
||||
contact.phone = this.phone;
|
||||
contact.address = this.address;
|
||||
Address.validate(contact.address);
|
||||
return contact;
|
||||
}
|
||||
}
|
|
@ -1,65 +1,53 @@
|
|||
import { IsEmail, IsInt, IsNotEmpty, IsOptional, IsPhoneNumber, IsString } from 'class-validator';
|
||||
import { getConnectionManager } from 'typeorm';
|
||||
import { config } from '../../../config';
|
||||
import { AddressNotFoundError } from '../../../errors/AddressErrors';
|
||||
import { Address } from '../../entities/Address';
|
||||
|
||||
/**
|
||||
* This classed is used to create a new Participant entity from a json body (post request).
|
||||
*/
|
||||
export abstract class CreateParticipant {
|
||||
/**
|
||||
* The new participant's first name.
|
||||
*/
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
firstname: string;
|
||||
|
||||
/**
|
||||
* The new participant's middle name.
|
||||
*/
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
middlename?: string;
|
||||
|
||||
/**
|
||||
* The new participant's last name.
|
||||
*/
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
lastname: string;
|
||||
|
||||
/**
|
||||
* The new participant's phone number.
|
||||
* This will be validated against the configured country phone numer syntax (default: international).
|
||||
*/
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@IsPhoneNumber(config.phone_validation_countrycode)
|
||||
phone?: string;
|
||||
|
||||
/**
|
||||
* The new participant's e-mail address.
|
||||
*/
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@IsEmail()
|
||||
email?: string;
|
||||
|
||||
/**
|
||||
* The new participant's address's id.
|
||||
*/
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
address?: number;
|
||||
|
||||
/**
|
||||
* Gets the new participant's address by it's id.
|
||||
*/
|
||||
public async getAddress(): Promise<Address> {
|
||||
if (!this.address) { return null; }
|
||||
let address = await getConnectionManager().get().getRepository(Address).findOne({ id: this.address });
|
||||
if (!address) { throw new AddressNotFoundError; }
|
||||
return address;
|
||||
}
|
||||
import { IsEmail, IsNotEmpty, IsObject, IsOptional, IsPhoneNumber, IsString } from 'class-validator';
|
||||
import { config } from '../../../config';
|
||||
import { Address } from '../../entities/Address';
|
||||
|
||||
/**
|
||||
* This classed is used to create a new Participant entity from a json body (post request).
|
||||
*/
|
||||
export abstract class CreateParticipant {
|
||||
/**
|
||||
* The new participant's first name.
|
||||
*/
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
firstname: string;
|
||||
|
||||
/**
|
||||
* The new participant's middle name.
|
||||
*/
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
middlename?: string;
|
||||
|
||||
/**
|
||||
* The new participant's last name.
|
||||
*/
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
lastname: string;
|
||||
|
||||
/**
|
||||
* The new participant's phone number.
|
||||
* This will be validated against the configured country phone numer syntax (default: international).
|
||||
*/
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@IsPhoneNumber(config.phone_validation_countrycode)
|
||||
phone?: string;
|
||||
|
||||
/**
|
||||
* The new participant's e-mail address.
|
||||
*/
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@IsEmail()
|
||||
email?: string;
|
||||
|
||||
/**
|
||||
* The new participant's address.
|
||||
*/
|
||||
@IsOptional()
|
||||
@IsObject()
|
||||
address?: Address;
|
||||
}
|
|
@ -1,53 +1,55 @@
|
|||
import { IsInt } from 'class-validator';
|
||||
import { getConnectionManager } from 'typeorm';
|
||||
import { RunnerGroupNotFoundError } from '../../../errors/RunnerGroupErrors';
|
||||
import { RunnerOrganisationWrongTypeError } from '../../../errors/RunnerOrganisationErrors';
|
||||
import { RunnerTeamNeedsParentError } from '../../../errors/RunnerTeamErrors';
|
||||
import { Runner } from '../../entities/Runner';
|
||||
import { RunnerGroup } from '../../entities/RunnerGroup';
|
||||
import { CreateParticipant } from './CreateParticipant';
|
||||
|
||||
/**
|
||||
* This classed is used to create a new Runner entity from a json body (post request).
|
||||
*/
|
||||
export class CreateRunner extends CreateParticipant {
|
||||
|
||||
/**
|
||||
* The new runner's group's id.
|
||||
*/
|
||||
@IsInt()
|
||||
group: number;
|
||||
|
||||
/**
|
||||
* Creates a new Runner entity from this.
|
||||
*/
|
||||
public async toEntity(): Promise<Runner> {
|
||||
let newRunner: Runner = new Runner();
|
||||
|
||||
newRunner.firstname = this.firstname;
|
||||
newRunner.middlename = this.middlename;
|
||||
newRunner.lastname = this.lastname;
|
||||
newRunner.phone = this.phone;
|
||||
newRunner.email = this.email;
|
||||
newRunner.group = await this.getGroup();
|
||||
newRunner.address = await this.getAddress();
|
||||
|
||||
return newRunner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the new runner's group by it's id.
|
||||
*/
|
||||
public async getGroup(): Promise<RunnerGroup> {
|
||||
if (this.group === undefined || this.group === null) {
|
||||
throw new RunnerTeamNeedsParentError();
|
||||
}
|
||||
if (!isNaN(this.group)) {
|
||||
let group = await getConnectionManager().get().getRepository(RunnerGroup).findOne({ id: this.group });
|
||||
if (!group) { throw new RunnerGroupNotFoundError; }
|
||||
return group;
|
||||
}
|
||||
|
||||
throw new RunnerOrganisationWrongTypeError;
|
||||
}
|
||||
import { IsInt } from 'class-validator';
|
||||
import { getConnectionManager } from 'typeorm';
|
||||
import { RunnerGroupNotFoundError } from '../../../errors/RunnerGroupErrors';
|
||||
import { RunnerOrganisationWrongTypeError } from '../../../errors/RunnerOrganisationErrors';
|
||||
import { RunnerTeamNeedsParentError } from '../../../errors/RunnerTeamErrors';
|
||||
import { Address } from '../../entities/Address';
|
||||
import { Runner } from '../../entities/Runner';
|
||||
import { RunnerGroup } from '../../entities/RunnerGroup';
|
||||
import { CreateParticipant } from './CreateParticipant';
|
||||
|
||||
/**
|
||||
* This classed is used to create a new Runner entity from a json body (post request).
|
||||
*/
|
||||
export class CreateRunner extends CreateParticipant {
|
||||
|
||||
/**
|
||||
* The new runner's group's id.
|
||||
*/
|
||||
@IsInt()
|
||||
group: number;
|
||||
|
||||
/**
|
||||
* Creates a new Runner entity from this.
|
||||
*/
|
||||
public async toEntity(): Promise<Runner> {
|
||||
let newRunner: Runner = new Runner();
|
||||
|
||||
newRunner.firstname = this.firstname;
|
||||
newRunner.middlename = this.middlename;
|
||||
newRunner.lastname = this.lastname;
|
||||
newRunner.phone = this.phone;
|
||||
newRunner.email = this.email;
|
||||
newRunner.group = await this.getGroup();
|
||||
newRunner.address = this.address;
|
||||
Address.validate(newRunner.address);
|
||||
|
||||
return newRunner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the new runner's group by it's id.
|
||||
*/
|
||||
public async getGroup(): Promise<RunnerGroup> {
|
||||
if (this.group === undefined || this.group === null) {
|
||||
throw new RunnerTeamNeedsParentError();
|
||||
}
|
||||
if (!isNaN(this.group)) {
|
||||
let group = await getConnectionManager().get().getRepository(RunnerGroup).findOne({ id: this.group });
|
||||
if (!group) { throw new RunnerGroupNotFoundError; }
|
||||
return group;
|
||||
}
|
||||
|
||||
throw new RunnerOrganisationWrongTypeError;
|
||||
}
|
||||
}
|
|
@ -1,41 +1,30 @@
|
|||
import { IsInt, IsOptional } from 'class-validator';
|
||||
import { getConnectionManager } from 'typeorm';
|
||||
import { AddressNotFoundError } from '../../../errors/AddressErrors';
|
||||
import { Address } from '../../entities/Address';
|
||||
import { RunnerOrganisation } from '../../entities/RunnerOrganisation';
|
||||
import { CreateRunnerGroup } from './CreateRunnerGroup';
|
||||
|
||||
/**
|
||||
* This classed is used to create a new RunnerOrganisation entity from a json body (post request).
|
||||
*/
|
||||
export class CreateRunnerOrganisation extends CreateRunnerGroup {
|
||||
/**
|
||||
* The new organisation's address's id.
|
||||
*/
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
address?: number;
|
||||
|
||||
/**
|
||||
* Gets the org's address by it's id.
|
||||
*/
|
||||
public async getAddress(): Promise<Address> {
|
||||
if (!this.address) { return null; }
|
||||
let address = await getConnectionManager().get().getRepository(Address).findOne({ id: this.address });
|
||||
if (!address) { throw new AddressNotFoundError; }
|
||||
return address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new RunnerOrganisation entity from this.
|
||||
*/
|
||||
public async toEntity(): Promise<RunnerOrganisation> {
|
||||
let newRunnerOrganisation: RunnerOrganisation = new RunnerOrganisation();
|
||||
|
||||
newRunnerOrganisation.name = this.name;
|
||||
newRunnerOrganisation.contact = await this.getContact();
|
||||
newRunnerOrganisation.address = await this.getAddress();
|
||||
|
||||
return newRunnerOrganisation;
|
||||
}
|
||||
import { IsObject, IsOptional } from 'class-validator';
|
||||
import { Address } from '../../entities/Address';
|
||||
import { RunnerOrganisation } from '../../entities/RunnerOrganisation';
|
||||
import { CreateRunnerGroup } from './CreateRunnerGroup';
|
||||
|
||||
/**
|
||||
* This classed is used to create a new RunnerOrganisation entity from a json body (post request).
|
||||
*/
|
||||
export class CreateRunnerOrganisation extends CreateRunnerGroup {
|
||||
/**
|
||||
* The new organisation's address.
|
||||
*/
|
||||
@IsOptional()
|
||||
@IsObject()
|
||||
address?: Address;
|
||||
|
||||
/**
|
||||
* Creates a new RunnerOrganisation entity from this.
|
||||
*/
|
||||
public async toEntity(): Promise<RunnerOrganisation> {
|
||||
let newRunnerOrganisation: RunnerOrganisation = new RunnerOrganisation();
|
||||
|
||||
newRunnerOrganisation.name = this.name;
|
||||
newRunnerOrganisation.contact = await this.getContact();
|
||||
newRunnerOrganisation.address = this.address;
|
||||
Address.validate(newRunnerOrganisation.address);
|
||||
|
||||
return newRunnerOrganisation;
|
||||
}
|
||||
}
|
|
@ -1,44 +1,46 @@
|
|||
import { IsBoolean, IsInt, IsOptional } from 'class-validator';
|
||||
import { DonorReceiptAddressNeededError } from '../../../errors/DonorErrors';
|
||||
import { Donor } from '../../entities/Donor';
|
||||
import { CreateParticipant } from '../create/CreateParticipant';
|
||||
|
||||
/**
|
||||
* This class is used to update a Donor entity (via put request).
|
||||
*/
|
||||
export class UpdateDonor extends CreateParticipant {
|
||||
|
||||
/**
|
||||
* The updated donor's id.
|
||||
* This shouldn't have changed but it is here in case anyone ever wants to enable id changes (whyever they would want to).
|
||||
*/
|
||||
@IsInt()
|
||||
id: number;
|
||||
|
||||
/**
|
||||
* Does the updated donor need a receipt?
|
||||
*/
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
receiptNeeded?: boolean;
|
||||
|
||||
|
||||
/**
|
||||
* Updates a provided Donor entity based on this.
|
||||
*/
|
||||
public async update(donor: Donor): Promise<Donor> {
|
||||
donor.firstname = this.firstname;
|
||||
donor.middlename = this.middlename;
|
||||
donor.lastname = this.lastname;
|
||||
donor.phone = this.phone;
|
||||
donor.email = this.email;
|
||||
donor.receiptNeeded = this.receiptNeeded;
|
||||
donor.address = await this.getAddress();
|
||||
|
||||
if (this.receiptNeeded == true && this.address == null) {
|
||||
throw new DonorReceiptAddressNeededError()
|
||||
}
|
||||
|
||||
return donor;
|
||||
}
|
||||
import { IsBoolean, IsInt, IsOptional } from 'class-validator';
|
||||
import { DonorReceiptAddressNeededError } from '../../../errors/DonorErrors';
|
||||
import { Address } from '../../entities/Address';
|
||||
import { Donor } from '../../entities/Donor';
|
||||
import { CreateParticipant } from '../create/CreateParticipant';
|
||||
|
||||
/**
|
||||
* This class is used to update a Donor entity (via put request).
|
||||
*/
|
||||
export class UpdateDonor extends CreateParticipant {
|
||||
|
||||
/**
|
||||
* The updated donor's id.
|
||||
* This shouldn't have changed but it is here in case anyone ever wants to enable id changes (whyever they would want to).
|
||||
*/
|
||||
@IsInt()
|
||||
id: number;
|
||||
|
||||
/**
|
||||
* Does the updated donor need a receipt?
|
||||
*/
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
receiptNeeded?: boolean;
|
||||
|
||||
|
||||
/**
|
||||
* Updates a provided Donor entity based on this.
|
||||
*/
|
||||
public async update(donor: Donor): Promise<Donor> {
|
||||
donor.firstname = this.firstname;
|
||||
donor.middlename = this.middlename;
|
||||
donor.lastname = this.lastname;
|
||||
donor.phone = this.phone;
|
||||
donor.email = this.email;
|
||||
donor.receiptNeeded = this.receiptNeeded;
|
||||
if (!this.address) { donor.address.reset(); }
|
||||
else { donor.address = this.address; }
|
||||
Address.validate(donor.address);
|
||||
if (this.receiptNeeded == true && Address.isValidAddress(donor.address) == false) {
|
||||
throw new DonorReceiptAddressNeededError()
|
||||
}
|
||||
|
||||
return donor;
|
||||
}
|
||||
}
|
|
@ -1,54 +1,57 @@
|
|||
import { IsInt, IsPositive } from 'class-validator';
|
||||
import { getConnectionManager } from 'typeorm';
|
||||
import { RunnerGroupNotFoundError } from '../../../errors/RunnerGroupErrors';
|
||||
import { RunnerTeamNeedsParentError } from '../../../errors/RunnerTeamErrors';
|
||||
import { Runner } from '../../entities/Runner';
|
||||
import { RunnerGroup } from '../../entities/RunnerGroup';
|
||||
import { CreateParticipant } from '../create/CreateParticipant';
|
||||
|
||||
/**
|
||||
* This class is used to update a Runner entity (via put request).
|
||||
*/
|
||||
export class UpdateRunner extends CreateParticipant {
|
||||
|
||||
/**
|
||||
* The updated runner's id.
|
||||
* This shouldn't have changed but it is here in case anyone ever wants to enable id changes (whyever they would want to).
|
||||
*/
|
||||
@IsInt()
|
||||
id: number;
|
||||
|
||||
/**
|
||||
* The updated runner's group's id.
|
||||
*/
|
||||
@IsInt()
|
||||
@IsPositive()
|
||||
group: number;
|
||||
|
||||
/**
|
||||
* Updates a provided Runner entity based on this.
|
||||
*/
|
||||
public async update(runner: Runner): Promise<Runner> {
|
||||
runner.firstname = this.firstname;
|
||||
runner.middlename = this.middlename;
|
||||
runner.lastname = this.lastname;
|
||||
runner.phone = this.phone;
|
||||
runner.email = this.email;
|
||||
runner.group = await this.getGroup();
|
||||
runner.address = await this.getAddress();
|
||||
|
||||
return runner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the updated runner's group based on it's id.
|
||||
*/
|
||||
public async getGroup(): Promise<RunnerGroup> {
|
||||
if (this.group === undefined || this.group === null) {
|
||||
throw new RunnerTeamNeedsParentError();
|
||||
}
|
||||
let group = await getConnectionManager().get().getRepository(RunnerGroup).findOne({ id: this.group });
|
||||
if (!group) { throw new RunnerGroupNotFoundError; }
|
||||
return group;
|
||||
}
|
||||
import { IsInt, IsPositive } from 'class-validator';
|
||||
import { getConnectionManager } from 'typeorm';
|
||||
import { RunnerGroupNotFoundError } from '../../../errors/RunnerGroupErrors';
|
||||
import { RunnerTeamNeedsParentError } from '../../../errors/RunnerTeamErrors';
|
||||
import { Address } from '../../entities/Address';
|
||||
import { Runner } from '../../entities/Runner';
|
||||
import { RunnerGroup } from '../../entities/RunnerGroup';
|
||||
import { CreateParticipant } from '../create/CreateParticipant';
|
||||
|
||||
/**
|
||||
* This class is used to update a Runner entity (via put request).
|
||||
*/
|
||||
export class UpdateRunner extends CreateParticipant {
|
||||
|
||||
/**
|
||||
* The updated runner's id.
|
||||
* This shouldn't have changed but it is here in case anyone ever wants to enable id changes (whyever they would want to).
|
||||
*/
|
||||
@IsInt()
|
||||
id: number;
|
||||
|
||||
/**
|
||||
* The updated runner's group's id.
|
||||
*/
|
||||
@IsInt()
|
||||
@IsPositive()
|
||||
group: number;
|
||||
|
||||
/**
|
||||
* Updates a provided Runner entity based on this.
|
||||
*/
|
||||
public async update(runner: Runner): Promise<Runner> {
|
||||
runner.firstname = this.firstname;
|
||||
runner.middlename = this.middlename;
|
||||
runner.lastname = this.lastname;
|
||||
runner.phone = this.phone;
|
||||
runner.email = this.email;
|
||||
runner.group = await this.getGroup();
|
||||
if (!this.address) { runner.address.reset(); }
|
||||
else { runner.address = this.address; }
|
||||
Address.validate(runner.address);
|
||||
|
||||
return runner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the updated runner's group based on it's id.
|
||||
*/
|
||||
public async getGroup(): Promise<RunnerGroup> {
|
||||
if (this.group === undefined || this.group === null) {
|
||||
throw new RunnerTeamNeedsParentError();
|
||||
}
|
||||
let group = await getConnectionManager().get().getRepository(RunnerGroup).findOne({ id: this.group });
|
||||
if (!group) { throw new RunnerGroupNotFoundError; }
|
||||
return group;
|
||||
}
|
||||
}
|
|
@ -1,48 +1,38 @@
|
|||
import { IsInt, IsOptional } from 'class-validator';
|
||||
import { getConnectionManager } from 'typeorm';
|
||||
import { AddressNotFoundError } from '../../../errors/AddressErrors';
|
||||
import { Address } from '../../entities/Address';
|
||||
import { RunnerOrganisation } from '../../entities/RunnerOrganisation';
|
||||
import { CreateRunnerGroup } from '../create/CreateRunnerGroup';
|
||||
|
||||
/**
|
||||
* This class is used to update a RunnerOrganisation entity (via put request).
|
||||
*/
|
||||
export class UpdateRunnerOrganisation extends CreateRunnerGroup {
|
||||
|
||||
/**
|
||||
* The updated orgs's id.
|
||||
* This shouldn't have changed but it is here in case anyone ever wants to enable id changes (whyever they would want to).
|
||||
*/
|
||||
@IsInt()
|
||||
id: number;
|
||||
|
||||
/**
|
||||
* The updated organisation's address's id.
|
||||
*/
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
address?: number;
|
||||
|
||||
/**
|
||||
* Loads the organisation's address based on it's id.
|
||||
*/
|
||||
public async getAddress(): Promise<Address> {
|
||||
if (!this.address) { return null; }
|
||||
let address = await getConnectionManager().get().getRepository(Address).findOne({ id: this.address });
|
||||
if (!address) { throw new AddressNotFoundError; }
|
||||
return address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a provided RunnerOrganisation entity based on this.
|
||||
*/
|
||||
public async update(organisation: RunnerOrganisation): Promise<RunnerOrganisation> {
|
||||
|
||||
organisation.name = this.name;
|
||||
organisation.contact = await this.getContact();
|
||||
organisation.address = await this.getAddress();
|
||||
|
||||
return organisation;
|
||||
}
|
||||
import { IsInt, IsObject, IsOptional } from 'class-validator';
|
||||
import { Address } from '../../entities/Address';
|
||||
import { RunnerOrganisation } from '../../entities/RunnerOrganisation';
|
||||
import { CreateRunnerGroup } from '../create/CreateRunnerGroup';
|
||||
|
||||
/**
|
||||
* This class is used to update a RunnerOrganisation entity (via put request).
|
||||
*/
|
||||
export class UpdateRunnerOrganisation extends CreateRunnerGroup {
|
||||
|
||||
/**
|
||||
* The updated orgs's id.
|
||||
* This shouldn't have changed but it is here in case anyone ever wants to enable id changes (whyever they would want to).
|
||||
*/
|
||||
@IsInt()
|
||||
id: number;
|
||||
|
||||
/**
|
||||
* The updated organisation's address.
|
||||
*/
|
||||
@IsOptional()
|
||||
@IsObject()
|
||||
address?: Address;
|
||||
|
||||
/**
|
||||
* Updates a provided RunnerOrganisation entity based on this.
|
||||
*/
|
||||
public async update(organisation: RunnerOrganisation): Promise<RunnerOrganisation> {
|
||||
|
||||
organisation.name = this.name;
|
||||
organisation.contact = await this.getContact();
|
||||
if (!this.address) { organisation.address.reset(); }
|
||||
else { organisation.address = this.address; }
|
||||
Address.validate(organisation.address);
|
||||
|
||||
return organisation;
|
||||
}
|
||||
}
|
|
@ -1,90 +1,93 @@
|
|||
import {
|
||||
IsInt,
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
IsPostalCode,
|
||||
IsString
|
||||
} from "class-validator";
|
||||
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm";
|
||||
import { config } from '../../config';
|
||||
import { IAddressUser } from './IAddressUser';
|
||||
|
||||
/**
|
||||
* Defines the Address entity.
|
||||
* Implemented this way to prevent any formatting differences.
|
||||
*/
|
||||
@Entity()
|
||||
export class Address {
|
||||
/**
|
||||
* Autogenerated unique id (primary key).
|
||||
*/
|
||||
@PrimaryGeneratedColumn()
|
||||
@IsInt()
|
||||
id: number;
|
||||
|
||||
/**
|
||||
* The address's description.
|
||||
* Optional and mostly for UX.
|
||||
*/
|
||||
@Column({ nullable: true })
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
description?: string;
|
||||
|
||||
/**
|
||||
* The address's first line.
|
||||
* Containing the street and house number.
|
||||
*/
|
||||
@Column()
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
address1: string;
|
||||
|
||||
/**
|
||||
* The address's second line.
|
||||
* Containing optional information.
|
||||
*/
|
||||
@Column({ nullable: true })
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
address2?: string;
|
||||
|
||||
/**
|
||||
* The address's postal code.
|
||||
* This will get checked against the postal code syntax for the configured country.
|
||||
*/
|
||||
@Column()
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@IsPostalCode(config.postalcode_validation_countrycode)
|
||||
postalcode: string;
|
||||
|
||||
/**
|
||||
* The address's city.
|
||||
*/
|
||||
@Column()
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
city: string;
|
||||
|
||||
/**
|
||||
* The address's country.
|
||||
*/
|
||||
@Column()
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
country: string;
|
||||
|
||||
/**
|
||||
* Used to link the address to participants.
|
||||
*/
|
||||
@OneToMany(() => IAddressUser, addressUser => addressUser.address, { nullable: true })
|
||||
addressUsers: IAddressUser[];
|
||||
|
||||
/**
|
||||
* Turns this entity into it's response class.
|
||||
*/
|
||||
public toResponse() {
|
||||
return new Error("NotImplemented");
|
||||
}
|
||||
}
|
||||
import {
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
IsPostalCode,
|
||||
IsString
|
||||
} from "class-validator";
|
||||
import { Column } from "typeorm";
|
||||
import ValidatorJS from 'validator';
|
||||
import { config } from '../../config';
|
||||
import { AddressCityEmptyError, AddressCountryEmptyError, AddressFirstLineEmptyError, AddressPostalCodeEmptyError, AddressPostalCodeInvalidError } from '../../errors/AddressErrors';
|
||||
|
||||
/**
|
||||
* Defines the Address class.
|
||||
* Implemented this way to prevent any formatting differences.
|
||||
*/
|
||||
export class Address {
|
||||
/**
|
||||
* The address's first line.
|
||||
* Containing the street and house number.
|
||||
*/
|
||||
@Column()
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
address1: string;
|
||||
|
||||
/**
|
||||
* The address's second line.
|
||||
* Containing optional information.
|
||||
*/
|
||||
@Column({ nullable: true })
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
address2?: string;
|
||||
|
||||
/**
|
||||
* The address's postal code.
|
||||
* This will get checked against the postal code syntax for the configured country.
|
||||
*/
|
||||
@Column()
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@IsPostalCode(config.postalcode_validation_countrycode)
|
||||
postalcode: string;
|
||||
|
||||
/**
|
||||
* The address's city.
|
||||
*/
|
||||
@Column()
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
city: string;
|
||||
|
||||
/**
|
||||
* The address's country.
|
||||
*/
|
||||
@Column()
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
country: string;
|
||||
|
||||
public reset() {
|
||||
this.address1 = null;
|
||||
this.address2 = null;
|
||||
this.city = null;
|
||||
this.country = null;
|
||||
this.postalcode = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this is a valid address
|
||||
*/
|
||||
public static isValidAddress(address: Address): Boolean {
|
||||
if (address == null) { return false; }
|
||||
if (address.address1 == null || address.city == null || address.country == null || address.postalcode == null) { return false; }
|
||||
if (ValidatorJS.isPostalCode(address.postalcode, config.postalcode_validation_countrycode) == false) { return false; }
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function validates addresses.
|
||||
* This is a workaround for non-existant class validation for embedded entities.
|
||||
* @param address The address that shall get validated.
|
||||
*/
|
||||
public static validate(address: Address) {
|
||||
if (address == null) { return; }
|
||||
if (address.address1 == null && address.city == null && address.country == null && address.postalcode == null) { return; }
|
||||
if (address.address1 == null) { throw new AddressFirstLineEmptyError(); }
|
||||
if (address.postalcode == null) { throw new AddressPostalCodeEmptyError(); }
|
||||
if (address.city == null) { throw new AddressCityEmptyError(); }
|
||||
if (address.country == null) { throw new AddressCountryEmptyError(); }
|
||||
if (ValidatorJS.isPostalCode(address.postalcode.toString(), config.postalcode_validation_countrycode) == false) { throw new AddressPostalCodeInvalidError(); }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,10 +7,9 @@ import {
|
|||
|
||||
IsString
|
||||
} from "class-validator";
|
||||
import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
|
||||
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm";
|
||||
import { config } from '../../config';
|
||||
import { Address } from "./Address";
|
||||
import { IAddressUser } from './IAddressUser';
|
||||
import { RunnerGroup } from "./RunnerGroup";
|
||||
|
||||
/**
|
||||
|
@ -18,7 +17,7 @@ import { RunnerGroup } from "./RunnerGroup";
|
|||
* Mainly it's own class to reduce duplicate code and enable contact's to be associated with multiple groups.
|
||||
*/
|
||||
@Entity()
|
||||
export class GroupContact implements IAddressUser {
|
||||
export class GroupContact {
|
||||
/**
|
||||
* Autogenerated unique id (primary key).
|
||||
*/
|
||||
|
@ -55,7 +54,7 @@ export class GroupContact implements IAddressUser {
|
|||
* This is a address object to prevent any formatting differences.
|
||||
*/
|
||||
@IsOptional()
|
||||
@ManyToOne(() => Address, address => address.addressUsers, { nullable: true })
|
||||
@Column(type => Address)
|
||||
address?: Address;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
import { Entity, ManyToOne, PrimaryColumn } from 'typeorm';
|
||||
import { Address } from './Address';
|
||||
|
||||
/**
|
||||
* The interface(tm) all entities using addresses have to implement.
|
||||
* This is a abstract class, because apparently typeorm can't really work with interfaces :/
|
||||
*/
|
||||
@Entity()
|
||||
export abstract class IAddressUser {
|
||||
@PrimaryColumn()
|
||||
id: number;
|
||||
|
||||
@ManyToOne(() => Address, address => address.addressUsers, { nullable: true })
|
||||
address?: Address
|
||||
|
||||
/**
|
||||
* Turns this entity into it's response class.
|
||||
*/
|
||||
public abstract toResponse();
|
||||
}
|
|
@ -7,11 +7,10 @@ import {
|
|||
|
||||
IsString
|
||||
} from "class-validator";
|
||||
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn, TableInheritance } from "typeorm";
|
||||
import { Column, Entity, PrimaryGeneratedColumn, TableInheritance } from "typeorm";
|
||||
import { config } from '../../config';
|
||||
import { ResponseParticipant } from '../responses/ResponseParticipant';
|
||||
import { Address } from "./Address";
|
||||
import { IAddressUser } from './IAddressUser';
|
||||
|
||||
/**
|
||||
* Defines the Participant entity.
|
||||
|
@ -19,7 +18,7 @@ import { IAddressUser } from './IAddressUser';
|
|||
*/
|
||||
@Entity()
|
||||
@TableInheritance({ column: { name: "type", type: "varchar" } })
|
||||
export abstract class Participant implements IAddressUser {
|
||||
export abstract class Participant {
|
||||
/**
|
||||
* Autogenerated unique id (primary key).
|
||||
*/
|
||||
|
@ -55,7 +54,7 @@ export abstract class Participant implements IAddressUser {
|
|||
* The participant's address.
|
||||
* This is a address object to prevent any formatting differences.
|
||||
*/
|
||||
@ManyToOne(() => Address, address => address.addressUsers, { nullable: true })
|
||||
@Column(type => Address)
|
||||
address?: Address;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,65 +1,64 @@
|
|||
import { IsInt, IsOptional } from "class-validator";
|
||||
import { ChildEntity, ManyToOne, OneToMany } from "typeorm";
|
||||
import { ResponseRunnerOrganisation } from '../responses/ResponseRunnerOrganisation';
|
||||
import { Address } from './Address';
|
||||
import { IAddressUser } from './IAddressUser';
|
||||
import { Runner } from './Runner';
|
||||
import { RunnerGroup } from "./RunnerGroup";
|
||||
import { RunnerTeam } from "./RunnerTeam";
|
||||
|
||||
/**
|
||||
* Defines the RunnerOrganisation entity.
|
||||
* This usually is a school, club or company.
|
||||
*/
|
||||
@ChildEntity()
|
||||
export class RunnerOrganisation extends RunnerGroup implements IAddressUser {
|
||||
|
||||
/**
|
||||
* The organisations's address.
|
||||
*/
|
||||
@IsOptional()
|
||||
@ManyToOne(() => Address, address => address.addressUsers, { nullable: true })
|
||||
address?: Address;
|
||||
|
||||
/**
|
||||
* The organisation's teams.
|
||||
* Used to link teams to a organisation.
|
||||
*/
|
||||
@OneToMany(() => RunnerTeam, team => team.parentGroup, { nullable: true })
|
||||
teams: RunnerTeam[];
|
||||
|
||||
/**
|
||||
* Returns all runners associated with this organisation (directly or indirectly via teams).
|
||||
*/
|
||||
public get allRunners(): Runner[] {
|
||||
let returnRunners: Runner[] = new Array<Runner>();
|
||||
returnRunners.push(...this.runners);
|
||||
for (let team of this.teams) {
|
||||
returnRunners.push(...team.runners)
|
||||
}
|
||||
return returnRunners;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total distance ran by this group's runners based on all their valid scans.
|
||||
*/
|
||||
@IsInt()
|
||||
public get distance(): number {
|
||||
return this.allRunners.reduce((sum, current) => sum + current.distance, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total donations a runner has collected based on his linked donations and distance ran.
|
||||
*/
|
||||
@IsInt()
|
||||
public get distanceDonationAmount(): number {
|
||||
return this.allRunners.reduce((sum, current) => sum + current.distanceDonationAmount, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns this entity into it's response class.
|
||||
*/
|
||||
public toResponse(): ResponseRunnerOrganisation {
|
||||
return new ResponseRunnerOrganisation(this);
|
||||
}
|
||||
import { IsInt, IsOptional } from "class-validator";
|
||||
import { ChildEntity, Column, OneToMany } from "typeorm";
|
||||
import { ResponseRunnerOrganisation } from '../responses/ResponseRunnerOrganisation';
|
||||
import { Address } from './Address';
|
||||
import { Runner } from './Runner';
|
||||
import { RunnerGroup } from "./RunnerGroup";
|
||||
import { RunnerTeam } from "./RunnerTeam";
|
||||
|
||||
/**
|
||||
* Defines the RunnerOrganisation entity.
|
||||
* This usually is a school, club or company.
|
||||
*/
|
||||
@ChildEntity()
|
||||
export class RunnerOrganisation extends RunnerGroup {
|
||||
|
||||
/**
|
||||
* The organisations's address.
|
||||
*/
|
||||
@IsOptional()
|
||||
@Column(type => Address)
|
||||
address?: Address;
|
||||
|
||||
/**
|
||||
* The organisation's teams.
|
||||
* Used to link teams to a organisation.
|
||||
*/
|
||||
@OneToMany(() => RunnerTeam, team => team.parentGroup, { nullable: true })
|
||||
teams: RunnerTeam[];
|
||||
|
||||
/**
|
||||
* Returns all runners associated with this organisation (directly or indirectly via teams).
|
||||
*/
|
||||
public get allRunners(): Runner[] {
|
||||
let returnRunners: Runner[] = new Array<Runner>();
|
||||
returnRunners.push(...this.runners);
|
||||
for (let team of this.teams) {
|
||||
returnRunners.push(...team.runners)
|
||||
}
|
||||
return returnRunners;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total distance ran by this group's runners based on all their valid scans.
|
||||
*/
|
||||
@IsInt()
|
||||
public get distance(): number {
|
||||
return this.allRunners.reduce((sum, current) => sum + current.distance, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total donations a runner has collected based on his linked donations and distance ran.
|
||||
*/
|
||||
@IsInt()
|
||||
public get distanceDonationAmount(): number {
|
||||
return this.allRunners.reduce((sum, current) => sum + current.distanceDonationAmount, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns this entity into it's response class.
|
||||
*/
|
||||
public toResponse(): ResponseRunnerOrganisation {
|
||||
return new ResponseRunnerOrganisation(this);
|
||||
}
|
||||
}
|
|
@ -1,56 +1,65 @@
|
|||
import { IsInt, IsString } from "class-validator";
|
||||
import { Participant } from '../entities/Participant';
|
||||
|
||||
/**
|
||||
* Defines the participant response.
|
||||
*/
|
||||
export abstract class ResponseParticipant {
|
||||
/**
|
||||
* The participant's id.
|
||||
*/
|
||||
@IsInt()
|
||||
id: number;
|
||||
|
||||
/**
|
||||
* The participant's first name.
|
||||
*/
|
||||
@IsString()
|
||||
firstname: string;
|
||||
|
||||
/**
|
||||
* The participant's middle name.
|
||||
*/
|
||||
@IsString()
|
||||
middlename?: string;
|
||||
|
||||
/**
|
||||
* The participant's last name.
|
||||
*/
|
||||
@IsString()
|
||||
lastname: string;
|
||||
|
||||
/**
|
||||
* The participant's phone number.
|
||||
*/
|
||||
@IsString()
|
||||
phone?: string;
|
||||
|
||||
/**
|
||||
* The participant's e-mail address.
|
||||
*/
|
||||
@IsString()
|
||||
email?: string;
|
||||
|
||||
/**
|
||||
* Creates a ResponseParticipant object from a participant.
|
||||
* @param participant The participant the response shall be build for.
|
||||
*/
|
||||
public constructor(participant: Participant) {
|
||||
this.id = participant.id;
|
||||
this.firstname = participant.firstname;
|
||||
this.middlename = participant.middlename;
|
||||
this.lastname = participant.lastname;
|
||||
this.phone = participant.phone;
|
||||
this.email = participant.email;
|
||||
}
|
||||
}
|
||||
import { IsInt, IsObject, IsOptional, IsString } from "class-validator";
|
||||
import { Address } from '../entities/Address';
|
||||
import { Participant } from '../entities/Participant';
|
||||
|
||||
/**
|
||||
* Defines the participant response.
|
||||
*/
|
||||
export abstract class ResponseParticipant {
|
||||
/**
|
||||
* The participant's id.
|
||||
*/
|
||||
@IsInt()
|
||||
id: number;
|
||||
|
||||
/**
|
||||
* The participant's first name.
|
||||
*/
|
||||
@IsString()
|
||||
firstname: string;
|
||||
|
||||
/**
|
||||
* The participant's middle name.
|
||||
*/
|
||||
@IsString()
|
||||
middlename?: string;
|
||||
|
||||
/**
|
||||
* The participant's last name.
|
||||
*/
|
||||
@IsString()
|
||||
lastname: string;
|
||||
|
||||
/**
|
||||
* The participant's phone number.
|
||||
*/
|
||||
@IsString()
|
||||
phone?: string;
|
||||
|
||||
/**
|
||||
* The participant's e-mail address.
|
||||
*/
|
||||
@IsString()
|
||||
email?: string;
|
||||
|
||||
/**
|
||||
* The participant's address.
|
||||
*/
|
||||
@IsOptional()
|
||||
@IsObject()
|
||||
address?: Address;
|
||||
|
||||
/**
|
||||
* Creates a ResponseParticipant object from a participant.
|
||||
* @param participant The participant the response shall be build for.
|
||||
*/
|
||||
public constructor(participant: Participant) {
|
||||
this.id = participant.id;
|
||||
this.firstname = participant.firstname;
|
||||
this.middlename = participant.middlename;
|
||||
this.lastname = participant.lastname;
|
||||
this.phone = participant.phone;
|
||||
this.email = participant.email;
|
||||
this.address = participant.address;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,94 +1,84 @@
|
|||
import axios from 'axios';
|
||||
import { config } from '../../config';
|
||||
const base = "http://localhost:" + config.internal_port
|
||||
|
||||
let access_token;
|
||||
let axios_config;
|
||||
|
||||
beforeAll(async () => {
|
||||
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('POST /api/donors with errors', () => {
|
||||
it('creating a new donor without any parameters should return 400', async () => {
|
||||
const res1 = await axios.post(base + '/api/donors', null, axios_config);
|
||||
expect(res1.status).toEqual(400);
|
||||
expect(res1.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new donor without a last name should return 400', async () => {
|
||||
const res2 = await axios.post(base + '/api/donors', {
|
||||
"firstname": "first",
|
||||
"middlename": "middle"
|
||||
}, axios_config);
|
||||
expect(res2.status).toEqual(400);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new donor with a invalid address should return 404', async () => {
|
||||
const res2 = await axios.post(base + '/api/donors', {
|
||||
"firstname": "first",
|
||||
"middlename": "middle",
|
||||
"lastname": "last",
|
||||
"address": 99999999999999999999999999
|
||||
}, axios_config);
|
||||
expect(res2.status).toEqual(404);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new donor with a invalid phone number should return 400', async () => {
|
||||
const res2 = await axios.post(base + '/api/donors', {
|
||||
"firstname": "first",
|
||||
"middlename": "middle",
|
||||
"lastname": "last",
|
||||
"phone": "123"
|
||||
}, axios_config);
|
||||
expect(res2.status).toEqual(400);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new donor with a invalid mail address should return 400', async () => {
|
||||
const res2 = await axios.post(base + '/api/donors', {
|
||||
"firstname": "string",
|
||||
"middlename": "string",
|
||||
"lastname": "string",
|
||||
"phone": null,
|
||||
"email": "123",
|
||||
}, axios_config);
|
||||
expect(res2.status).toEqual(400);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new donor without an address but with receiptNeeded=true 406', async () => {
|
||||
const res2 = await axios.post(base + '/api/donors', {
|
||||
"firstname": "string",
|
||||
"middlename": "string",
|
||||
"lastname": "string",
|
||||
"receiptNeeded": true
|
||||
}, axios_config);
|
||||
expect(res2.status).toEqual(406);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('POST /api/donors working', () => {
|
||||
it('creating a new donor with only needed params should return 200', async () => {
|
||||
const res2 = await axios.post(base + '/api/donors', {
|
||||
"firstname": "first",
|
||||
"lastname": "last"
|
||||
}, axios_config);
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new donor with all non-relationship optional params should return 200', async () => {
|
||||
const res3 = await axios.post(base + '/api/donors', {
|
||||
"firstname": "first",
|
||||
"middlename": "middle",
|
||||
"lastname": "last",
|
||||
"receiptNeeded": false
|
||||
}, axios_config);
|
||||
expect(res3.status).toEqual(200);
|
||||
expect(res3.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
import axios from 'axios';
|
||||
import { config } from '../../config';
|
||||
const base = "http://localhost:" + config.internal_port
|
||||
|
||||
let access_token;
|
||||
let axios_config;
|
||||
|
||||
beforeAll(async () => {
|
||||
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('POST /api/donors with errors', () => {
|
||||
it('creating a new donor without any parameters should return 400', async () => {
|
||||
const res1 = await axios.post(base + '/api/donors', null, axios_config);
|
||||
expect(res1.status).toEqual(400);
|
||||
expect(res1.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new donor without a last name should return 400', async () => {
|
||||
const res2 = await axios.post(base + '/api/donors', {
|
||||
"firstname": "first",
|
||||
"middlename": "middle"
|
||||
}, axios_config);
|
||||
expect(res2.status).toEqual(400);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new donor with a invalid phone number should return 400', async () => {
|
||||
const res2 = await axios.post(base + '/api/donors', {
|
||||
"firstname": "first",
|
||||
"middlename": "middle",
|
||||
"lastname": "last",
|
||||
"phone": "123"
|
||||
}, axios_config);
|
||||
expect(res2.status).toEqual(400);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new donor with a invalid mail address should return 400', async () => {
|
||||
const res2 = await axios.post(base + '/api/donors', {
|
||||
"firstname": "string",
|
||||
"middlename": "string",
|
||||
"lastname": "string",
|
||||
"phone": null,
|
||||
"email": "123",
|
||||
}, axios_config);
|
||||
expect(res2.status).toEqual(400);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new donor without an address but with receiptNeeded=true 406', async () => {
|
||||
const res2 = await axios.post(base + '/api/donors', {
|
||||
"firstname": "string",
|
||||
"middlename": "string",
|
||||
"lastname": "string",
|
||||
"receiptNeeded": true
|
||||
}, axios_config);
|
||||
expect(res2.status).toEqual(406);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('POST /api/donors working', () => {
|
||||
it('creating a new donor with only needed params should return 200', async () => {
|
||||
const res2 = await axios.post(base + '/api/donors', {
|
||||
"firstname": "first",
|
||||
"lastname": "last"
|
||||
}, axios_config);
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new donor with all non-relationship optional params should return 200', async () => {
|
||||
const res3 = await axios.post(base + '/api/donors', {
|
||||
"firstname": "first",
|
||||
"middlename": "middle",
|
||||
"lastname": "last",
|
||||
"receiptNeeded": false
|
||||
}, axios_config);
|
||||
expect(res3.status).toEqual(200);
|
||||
expect(res3.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
});
|
|
@ -1,75 +1,75 @@
|
|||
import axios from 'axios';
|
||||
import { config } from '../../config';
|
||||
const base = "http://localhost:" + config.internal_port
|
||||
|
||||
let access_token;
|
||||
let axios_config;
|
||||
|
||||
beforeAll(async () => {
|
||||
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('Update donor name after adding', () => {
|
||||
let added_donor;
|
||||
it('creating a new runner with only needed params should return 200', async () => {
|
||||
const res2 = await axios.post(base + '/api/donors', {
|
||||
"firstname": "first",
|
||||
"lastname": "last"
|
||||
}, axios_config);
|
||||
added_donor = res2.data;
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('valid update should return 200', async () => {
|
||||
let donor_copy = added_donor
|
||||
donor_copy.firstname = "second"
|
||||
const res3 = await axios.put(base + '/api/donors/' + added_donor.id, donor_copy, axios_config);
|
||||
expect(res3.status).toEqual(200);
|
||||
expect(res3.headers['content-type']).toContain("application/json")
|
||||
let updated_donor = res3.data
|
||||
expect(updated_donor).toEqual(donor_copy);
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('Update donor id after adding(should fail)', () => {
|
||||
let added_donor;
|
||||
it('creating a new donor with only needed params should return 200', async () => {
|
||||
const res2 = await axios.post(base + '/api/donors', {
|
||||
"firstname": "first",
|
||||
"lastname": "last"
|
||||
}, axios_config);
|
||||
added_donor = res2.data;
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('invalid update should return 406', async () => {
|
||||
added_donor.id++;
|
||||
const res3 = await axios.put(base + '/api/donors/' + (added_donor.id - 1), added_donor, axios_config);
|
||||
expect(res3.status).toEqual(406);
|
||||
expect(res3.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('Update donor without address but receiptNeeded=true should fail', () => {
|
||||
let added_donor;
|
||||
it('creating a new donor with only needed params should return 200', async () => {
|
||||
const res2 = await axios.post(base + '/api/donors', {
|
||||
"firstname": "first",
|
||||
"lastname": "last",
|
||||
}, axios_config);
|
||||
added_donor = res2.data;
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('invalid update should return 406', async () => {
|
||||
added_donor.receiptNeeded = true;
|
||||
const res3 = await axios.put(base + '/api/donors/' + added_donor.id, added_donor, axios_config);
|
||||
expect(res3.status).toEqual(406);
|
||||
expect(res3.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
import axios from 'axios';
|
||||
import { config } from '../../config';
|
||||
const base = "http://localhost:" + config.internal_port
|
||||
|
||||
let access_token;
|
||||
let axios_config;
|
||||
|
||||
beforeAll(async () => {
|
||||
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('Update donor name after adding', () => {
|
||||
let added_donor;
|
||||
it('creating a new runner with only needed params should return 200', async () => {
|
||||
const res2 = await axios.post(base + '/api/donors', {
|
||||
"firstname": "first",
|
||||
"lastname": "last"
|
||||
}, axios_config);
|
||||
added_donor = res2.data;
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('valid update should return 200', async () => {
|
||||
let donor_copy = added_donor
|
||||
donor_copy.firstname = "second"
|
||||
const res3 = await axios.put(base + '/api/donors/' + added_donor.id, donor_copy, axios_config);
|
||||
expect(res3.status).toEqual(200);
|
||||
expect(res3.headers['content-type']).toContain("application/json")
|
||||
let updated_donor = res3.data
|
||||
expect(updated_donor).toEqual(donor_copy);
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('Update donor id after adding(should fail)', () => {
|
||||
let added_donor;
|
||||
it('creating a new donor with only needed params should return 200', async () => {
|
||||
const res2 = await axios.post(base + '/api/donors', {
|
||||
"firstname": "first",
|
||||
"lastname": "last"
|
||||
}, axios_config);
|
||||
added_donor = res2.data;
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('invalid update should return 406', async () => {
|
||||
added_donor.id++;
|
||||
const res3 = await axios.put(base + '/api/donors/' + (added_donor.id - 1), added_donor, axios_config);
|
||||
expect(res3.status).toEqual(406);
|
||||
expect(res3.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('Update donor without address but receiptNeeded=true should fail', () => {
|
||||
let added_donor;
|
||||
it('creating a new donor with only needed params should return 200', async () => {
|
||||
const res2 = await axios.post(base + '/api/donors', {
|
||||
"firstname": "first",
|
||||
"lastname": "testtest",
|
||||
}, axios_config);
|
||||
added_donor = res2.data;
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('invalid update should return 406', async () => {
|
||||
added_donor.receiptNeeded = true;
|
||||
const res3 = await axios.put(base + '/api/donors/' + added_donor.id, added_donor, axios_config);
|
||||
expect(res3.status).toEqual(406);
|
||||
expect(res3.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
});
|
|
@ -1,90 +1,102 @@
|
|||
import axios from 'axios';
|
||||
import { config } from '../../config';
|
||||
const base = "http://localhost:" + config.internal_port
|
||||
|
||||
let access_token;
|
||||
let axios_config;
|
||||
|
||||
beforeAll(async () => {
|
||||
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('GET /api/organisations', () => {
|
||||
it('basic get should return 200', async () => {
|
||||
const res = await axios.get(base + '/api/organisations', axios_config);
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('POST /api/organisations', () => {
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new org with without a name should return 400', async () => {
|
||||
const res = await axios.post(base + '/api/organisations', {
|
||||
"name": null
|
||||
}, axios_config);
|
||||
expect(res.status).toEqual(400);
|
||||
expect(res.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('adding + getting from all orgs', () => {
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('check if org was added', async () => {
|
||||
const res = await axios.get(base + '/api/organisations', axios_config);
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json")
|
||||
let added_org = res.data[res.data.length - 1]
|
||||
delete added_org.id
|
||||
expect(added_org).toEqual({
|
||||
"name": "test123",
|
||||
"contact": null,
|
||||
"address": null,
|
||||
"teams": []
|
||||
})
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('adding + getting explicitly', () => {
|
||||
let added_org_id
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res1 = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
let added_org = res1.data
|
||||
added_org_id = added_org.id;
|
||||
expect(res1.status).toEqual(200);
|
||||
expect(res1.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('check if org was added', async () => {
|
||||
const res2 = await axios.get(base + '/api/organisations/' + added_org_id, axios_config);
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
let added_org2 = res2.data
|
||||
added_org_id = added_org2.id;
|
||||
delete added_org2.id
|
||||
expect(added_org2).toEqual({
|
||||
"name": "test123",
|
||||
"contact": null,
|
||||
"address": null,
|
||||
"teams": []
|
||||
})
|
||||
});
|
||||
import axios from 'axios';
|
||||
import { config } from '../../config';
|
||||
const base = "http://localhost:" + config.internal_port
|
||||
|
||||
let access_token;
|
||||
let axios_config;
|
||||
|
||||
beforeAll(async () => {
|
||||
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('GET /api/organisations', () => {
|
||||
it('basic get should return 200', async () => {
|
||||
const res = await axios.get(base + '/api/organisations', axios_config);
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('POST /api/organisations', () => {
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new org with without a name should return 400', async () => {
|
||||
const res = await axios.post(base + '/api/organisations', {
|
||||
"name": null
|
||||
}, axios_config);
|
||||
expect(res.status).toEqual(400);
|
||||
expect(res.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('adding + getting from all orgs', () => {
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('check if org was added', async () => {
|
||||
const res = await axios.get(base + '/api/organisations', axios_config);
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json")
|
||||
let added_org = res.data[res.data.length - 1]
|
||||
delete added_org.id
|
||||
expect(added_org).toEqual({
|
||||
"name": "test123",
|
||||
"contact": null,
|
||||
"address": {
|
||||
"address1": null,
|
||||
"address2": null,
|
||||
"city": null,
|
||||
"country": null,
|
||||
"postalcode": null,
|
||||
},
|
||||
"teams": []
|
||||
})
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('adding + getting explicitly', () => {
|
||||
let added_org_id
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res1 = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
let added_org = res1.data
|
||||
added_org_id = added_org.id;
|
||||
expect(res1.status).toEqual(200);
|
||||
expect(res1.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('check if org was added', async () => {
|
||||
const res2 = await axios.get(base + '/api/organisations/' + added_org_id, axios_config);
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
let added_org2 = res2.data
|
||||
added_org_id = added_org2.id;
|
||||
delete added_org2.id
|
||||
expect(added_org2).toEqual({
|
||||
"name": "test123",
|
||||
"contact": null,
|
||||
"address": {
|
||||
"address1": null,
|
||||
"address2": null,
|
||||
"city": null,
|
||||
"country": null,
|
||||
"postalcode": null,
|
||||
},
|
||||
"teams": []
|
||||
})
|
||||
});
|
||||
});
|
|
@ -1,132 +1,144 @@
|
|||
import axios from 'axios';
|
||||
import { config } from '../../config';
|
||||
const base = "http://localhost:" + config.internal_port
|
||||
|
||||
let access_token;
|
||||
let axios_config;
|
||||
|
||||
beforeAll(async () => {
|
||||
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('adding + deletion (non-existant)', () => {
|
||||
it('delete', async () => {
|
||||
const res2 = await axios.delete(base + '/api/organisations/0', axios_config);
|
||||
expect(res2.status).toEqual(204);
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('adding + deletion (successfull)', () => {
|
||||
let added_org_id
|
||||
let added_org
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res1 = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
added_org = res1.data
|
||||
added_org_id = added_org.id;
|
||||
expect(res1.status).toEqual(200);
|
||||
expect(res1.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('delete', async () => {
|
||||
const res2 = await axios.delete(base + '/api/organisations/' + added_org_id, axios_config);
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
let added_org2 = res2.data
|
||||
added_org_id = added_org2.id;
|
||||
delete added_org2.id
|
||||
expect(added_org2).toEqual({
|
||||
"name": "test123",
|
||||
"contact": null,
|
||||
"address": null,
|
||||
"teams": []
|
||||
});
|
||||
});
|
||||
it('check if org really was deleted', async () => {
|
||||
const res3 = await axios.get(base + '/api/organisations/' + added_org_id, axios_config);
|
||||
expect(res3.status).toEqual(404);
|
||||
expect(res3.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('adding + deletion with teams still existing (without force)', () => {
|
||||
let added_org;
|
||||
let added_org_id;
|
||||
let added_team;
|
||||
let added_team_id
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res1 = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
added_org = res1.data;
|
||||
added_org_id = added_org.id;
|
||||
expect(res1.status).toEqual(200);
|
||||
expect(res1.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new team with a valid org should return 200', async () => {
|
||||
const res2 = await axios.post(base + '/api/teams', {
|
||||
"name": "test123",
|
||||
"parentGroup": added_org_id
|
||||
}, axios_config);
|
||||
added_team = res2.data;
|
||||
added_team_id = added_team.id;
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('delete org - this should fail with a 406', async () => {
|
||||
const res2 = await axios.delete(base + '/api/organisations/' + added_org_id, axios_config);
|
||||
expect(res2.status).toEqual(406);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('adding + deletion with teams still existing (with force)', () => {
|
||||
let added_org;
|
||||
let added_org_id;
|
||||
let added_team;
|
||||
let added_team_id
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res1 = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
added_org = res1.data;
|
||||
added_org_id = added_org.id;
|
||||
expect(res1.status).toEqual(200);
|
||||
expect(res1.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new team with a valid org should return 200', async () => {
|
||||
const res2 = await axios.post(base + '/api/teams', {
|
||||
"name": "test123",
|
||||
"parentGroup": added_org_id
|
||||
}, axios_config);
|
||||
added_team = res2.data;
|
||||
added_team_id = added_team.id;
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('delete', async () => {
|
||||
const res2 = await axios.delete(base + '/api/organisations/' + added_org_id + '?force=true', axios_config);
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
let added_org2 = res2.data
|
||||
added_org_id = added_org2.id;
|
||||
delete added_org2.id;
|
||||
delete added_org2.teams;
|
||||
expect(added_org2).toEqual({
|
||||
"name": "test123",
|
||||
"contact": null,
|
||||
"address": null
|
||||
});
|
||||
});
|
||||
it('check if org really was deleted', async () => {
|
||||
const res3 = await axios.get(base + '/api/organisations/' + added_org_id, axios_config);
|
||||
expect(res3.status).toEqual(404);
|
||||
expect(res3.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
import axios from 'axios';
|
||||
import { config } from '../../config';
|
||||
const base = "http://localhost:" + config.internal_port
|
||||
|
||||
let access_token;
|
||||
let axios_config;
|
||||
|
||||
beforeAll(async () => {
|
||||
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('adding + deletion (non-existant)', () => {
|
||||
it('delete', async () => {
|
||||
const res2 = await axios.delete(base + '/api/organisations/0', axios_config);
|
||||
expect(res2.status).toEqual(204);
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('adding + deletion (successfull)', () => {
|
||||
let added_org_id
|
||||
let added_org
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res1 = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
added_org = res1.data
|
||||
added_org_id = added_org.id;
|
||||
expect(res1.status).toEqual(200);
|
||||
expect(res1.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('delete', async () => {
|
||||
const res2 = await axios.delete(base + '/api/organisations/' + added_org_id, axios_config);
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
let added_org2 = res2.data
|
||||
added_org_id = added_org2.id;
|
||||
delete added_org2.id
|
||||
expect(added_org2).toEqual({
|
||||
"name": "test123",
|
||||
"contact": null,
|
||||
"address": {
|
||||
"address1": null,
|
||||
"address2": null,
|
||||
"city": null,
|
||||
"country": null,
|
||||
"postalcode": null,
|
||||
},
|
||||
"teams": []
|
||||
});
|
||||
});
|
||||
it('check if org really was deleted', async () => {
|
||||
const res3 = await axios.get(base + '/api/organisations/' + added_org_id, axios_config);
|
||||
expect(res3.status).toEqual(404);
|
||||
expect(res3.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('adding + deletion with teams still existing (without force)', () => {
|
||||
let added_org;
|
||||
let added_org_id;
|
||||
let added_team;
|
||||
let added_team_id
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res1 = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
added_org = res1.data;
|
||||
added_org_id = added_org.id;
|
||||
expect(res1.status).toEqual(200);
|
||||
expect(res1.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new team with a valid org should return 200', async () => {
|
||||
const res2 = await axios.post(base + '/api/teams', {
|
||||
"name": "test123",
|
||||
"parentGroup": added_org_id
|
||||
}, axios_config);
|
||||
added_team = res2.data;
|
||||
added_team_id = added_team.id;
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('delete org - this should fail with a 406', async () => {
|
||||
const res2 = await axios.delete(base + '/api/organisations/' + added_org_id, axios_config);
|
||||
expect(res2.status).toEqual(406);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('adding + deletion with teams still existing (with force)', () => {
|
||||
let added_org;
|
||||
let added_org_id;
|
||||
let added_team;
|
||||
let added_team_id
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res1 = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
added_org = res1.data;
|
||||
added_org_id = added_org.id;
|
||||
expect(res1.status).toEqual(200);
|
||||
expect(res1.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new team with a valid org should return 200', async () => {
|
||||
const res2 = await axios.post(base + '/api/teams', {
|
||||
"name": "test123",
|
||||
"parentGroup": added_org_id
|
||||
}, axios_config);
|
||||
added_team = res2.data;
|
||||
added_team_id = added_team.id;
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('delete', async () => {
|
||||
const res2 = await axios.delete(base + '/api/organisations/' + added_org_id + '?force=true', axios_config);
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
let added_org2 = res2.data
|
||||
added_org_id = added_org2.id;
|
||||
delete added_org2.id;
|
||||
delete added_org2.teams;
|
||||
expect(added_org2).toEqual({
|
||||
"name": "test123",
|
||||
"contact": null,
|
||||
"address": {
|
||||
"address1": null,
|
||||
"address2": null,
|
||||
"city": null,
|
||||
"country": null,
|
||||
"postalcode": null,
|
||||
},
|
||||
});
|
||||
});
|
||||
it('check if org really was deleted', async () => {
|
||||
const res3 = await axios.get(base + '/api/organisations/' + added_org_id, axios_config);
|
||||
expect(res3.status).toEqual(404);
|
||||
expect(res3.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
});
|
|
@ -1,73 +1,383 @@
|
|||
import axios from 'axios';
|
||||
import { config } from '../../config';
|
||||
const base = "http://localhost:" + config.internal_port
|
||||
|
||||
let access_token;
|
||||
let axios_config;
|
||||
|
||||
beforeAll(async () => {
|
||||
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('adding + updating name', () => {
|
||||
let added_org_id
|
||||
let added_org
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res1 = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
added_org = res1.data
|
||||
added_org_id = added_org.id;
|
||||
expect(res1.status).toEqual(200);
|
||||
expect(res1.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('update org', async () => {
|
||||
const res2 = await axios.put(base + '/api/organisations/' + added_org_id, {
|
||||
"id": added_org_id,
|
||||
"name": "testlelele",
|
||||
"contact": null,
|
||||
"address": null,
|
||||
}, axios_config);
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
let added_org2 = res2.data
|
||||
added_org_id = added_org2.id;
|
||||
delete added_org2.id
|
||||
expect(added_org2).toEqual({
|
||||
"name": "testlelele",
|
||||
"contact": null,
|
||||
"address": null,
|
||||
"teams": []
|
||||
})
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('adding + try updating id (should return 406)', () => {
|
||||
let added_org_id
|
||||
let added_org
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res1 = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
added_org = res1.data
|
||||
added_org_id = added_org.id;
|
||||
expect(res1.status).toEqual(200);
|
||||
expect(res1.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('update org', async () => {
|
||||
const res2 = await axios.put(base + '/api/organisations/' + added_org_id, {
|
||||
"id": added_org_id + 1,
|
||||
"name": "testlelele",
|
||||
"contact": null,
|
||||
"address": null,
|
||||
}, axios_config);
|
||||
expect(res2.status).toEqual(406);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
import axios from 'axios';
|
||||
import { config } from '../../config';
|
||||
const base = "http://localhost:" + config.internal_port
|
||||
|
||||
let access_token;
|
||||
let axios_config;
|
||||
|
||||
beforeAll(async () => {
|
||||
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('adding + updating name', () => {
|
||||
let added_org_id
|
||||
let added_org
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
added_org = res.data
|
||||
added_org_id = added_org.id;
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('update org', async () => {
|
||||
const res = await axios.put(base + '/api/organisations/' + added_org_id, {
|
||||
"id": added_org_id,
|
||||
"name": "testlelele",
|
||||
"contact": null,
|
||||
"address": null,
|
||||
}, axios_config);
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json")
|
||||
let added_org2 = res.data
|
||||
added_org_id = added_org2.id;
|
||||
delete added_org2.id
|
||||
expect(added_org2).toEqual({
|
||||
"name": "testlelele",
|
||||
"contact": null,
|
||||
"address": {
|
||||
"address1": null,
|
||||
"address2": null,
|
||||
"city": null,
|
||||
"country": null,
|
||||
"postalcode": null,
|
||||
},
|
||||
"teams": []
|
||||
})
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('adding + try updating id (should return 406)', () => {
|
||||
let added_org_id
|
||||
let added_org
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
added_org = res.data
|
||||
added_org_id = added_org.id;
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('update org', async () => {
|
||||
const res = await axios.put(base + '/api/organisations/' + added_org_id, {
|
||||
"id": added_org_id + 1,
|
||||
"name": "testlelele",
|
||||
"contact": null,
|
||||
"address": null,
|
||||
}, axios_config);
|
||||
expect(res.status).toEqual(406);
|
||||
expect(res.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('adding + updateing address valid)', () => {
|
||||
let added_org_id
|
||||
let added_org
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
added_org = res.data
|
||||
added_org_id = added_org.id;
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('adding address to org should return 200', async () => {
|
||||
const res = await axios.put(base + '/api/organisations/' + added_org_id, {
|
||||
"id": added_org_id,
|
||||
"name": "testlelele",
|
||||
"contact": null,
|
||||
"address": {
|
||||
"address1": "Test1",
|
||||
"address2": null,
|
||||
"city": "Herzogenaurach",
|
||||
"country": "Burkina Faso",
|
||||
"postalcode": "90174"
|
||||
}
|
||||
}, axios_config);
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json");
|
||||
expect(res.data).toEqual({
|
||||
"id": added_org_id,
|
||||
"name": "testlelele",
|
||||
"contact": null,
|
||||
"address": {
|
||||
"address1": "Test1",
|
||||
"address2": null,
|
||||
"city": "Herzogenaurach",
|
||||
"country": "Burkina Faso",
|
||||
"postalcode": "90174"
|
||||
},
|
||||
"teams": []
|
||||
});
|
||||
});
|
||||
it('updateing address\'s first line should return 200', async () => {
|
||||
const res = await axios.put(base + '/api/organisations/' + added_org_id, {
|
||||
"id": added_org_id,
|
||||
"name": "testlelele",
|
||||
"contact": null,
|
||||
"address": {
|
||||
"address1": "Test2",
|
||||
"address2": null,
|
||||
"city": "TestCity",
|
||||
"country": "Burkina Faso",
|
||||
"postalcode": "90174"
|
||||
}
|
||||
}, axios_config);
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json");
|
||||
expect(res.data).toEqual({
|
||||
"id": added_org_id,
|
||||
"name": "testlelele",
|
||||
"contact": null,
|
||||
"address": {
|
||||
"address1": "Test2",
|
||||
"address2": null,
|
||||
"city": "TestCity",
|
||||
"country": "Burkina Faso",
|
||||
"postalcode": "90174"
|
||||
},
|
||||
"teams": []
|
||||
});
|
||||
});
|
||||
it('updateing address\'s second line should return 200', async () => {
|
||||
const res = await axios.put(base + '/api/organisations/' + added_org_id, {
|
||||
"id": added_org_id,
|
||||
"name": "testlelele",
|
||||
"contact": null,
|
||||
"address": {
|
||||
"address1": "Test2",
|
||||
"address2": "Test3",
|
||||
"city": "TestCity",
|
||||
"country": "Burkina Faso",
|
||||
"postalcode": "90174"
|
||||
}
|
||||
}, axios_config);
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json");
|
||||
expect(res.data).toEqual({
|
||||
"id": added_org_id,
|
||||
"name": "testlelele",
|
||||
"contact": null,
|
||||
"address": {
|
||||
"address1": "Test2",
|
||||
"address2": "Test3",
|
||||
"city": "TestCity",
|
||||
"country": "Burkina Faso",
|
||||
"postalcode": "90174"
|
||||
},
|
||||
"teams": []
|
||||
});
|
||||
});
|
||||
it('updateing address\'s city should return 200', async () => {
|
||||
const res = await axios.put(base + '/api/organisations/' + added_org_id, {
|
||||
"id": added_org_id,
|
||||
"name": "testlelele",
|
||||
"contact": null,
|
||||
"address": {
|
||||
"address1": "Test2",
|
||||
"address2": "Test3",
|
||||
"city": "Kaya",
|
||||
"country": "Burkina Faso",
|
||||
"postalcode": "90174"
|
||||
}
|
||||
}, axios_config);
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json");
|
||||
expect(res.data).toEqual({
|
||||
"id": added_org_id,
|
||||
"name": "testlelele",
|
||||
"contact": null,
|
||||
"address": {
|
||||
"address1": "Test2",
|
||||
"address2": "Test3",
|
||||
"city": "Kaya",
|
||||
"country": "Burkina Faso",
|
||||
"postalcode": "90174"
|
||||
},
|
||||
"teams": []
|
||||
});
|
||||
});
|
||||
it('updateing address\'s country should return 200', async () => {
|
||||
const res = await axios.put(base + '/api/organisations/' + added_org_id, {
|
||||
"id": added_org_id,
|
||||
"name": "testlelele",
|
||||
"contact": null,
|
||||
"address": {
|
||||
"address1": "Test2",
|
||||
"address2": "Test3",
|
||||
"city": "Kaya",
|
||||
"country": "Germany",
|
||||
"postalcode": "90174"
|
||||
}
|
||||
}, axios_config);
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json");
|
||||
expect(res.data).toEqual({
|
||||
"id": added_org_id,
|
||||
"name": "testlelele",
|
||||
"contact": null,
|
||||
"address": {
|
||||
"address1": "Test2",
|
||||
"address2": "Test3",
|
||||
"city": "Kaya",
|
||||
"country": "Germany",
|
||||
"postalcode": "90174"
|
||||
},
|
||||
"teams": []
|
||||
});
|
||||
});
|
||||
it('updateing address\'s postal code should return 200', async () => {
|
||||
const res = await axios.put(base + '/api/organisations/' + added_org_id, {
|
||||
"id": added_org_id,
|
||||
"name": "testlelele",
|
||||
"contact": null,
|
||||
"address": {
|
||||
"address1": "Test2",
|
||||
"address2": "Test3",
|
||||
"city": "Kaya",
|
||||
"country": "Germany",
|
||||
"postalcode": "91065"
|
||||
}
|
||||
}, axios_config);
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json");
|
||||
expect(res.data).toEqual({
|
||||
"id": added_org_id,
|
||||
"name": "testlelele",
|
||||
"contact": null,
|
||||
"address": {
|
||||
"address1": "Test2",
|
||||
"address2": "Test3",
|
||||
"city": "Kaya",
|
||||
"country": "Germany",
|
||||
"postalcode": "91065"
|
||||
},
|
||||
"teams": []
|
||||
});
|
||||
});
|
||||
it('removing org\'s should return 200', async () => {
|
||||
const res = await axios.put(base + '/api/organisations/' + added_org_id, {
|
||||
"id": added_org_id,
|
||||
"name": "testlelele",
|
||||
"contact": null
|
||||
}, axios_config);
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json");
|
||||
expect(res.data).toEqual({
|
||||
"id": added_org_id,
|
||||
"name": "testlelele",
|
||||
"contact": null,
|
||||
"address": {
|
||||
"address1": null,
|
||||
"address2": null,
|
||||
"city": null,
|
||||
"country": null,
|
||||
"postalcode": null
|
||||
},
|
||||
"teams": []
|
||||
});
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('adding + updateing address invalid)', () => {
|
||||
let added_org_id
|
||||
let added_org
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
added_org = res.data
|
||||
added_org_id = added_org.id;
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('adding address to org w/o address1 should return 400', async () => {
|
||||
const res = await axios.put(base + '/api/organisations/' + added_org_id, {
|
||||
"id": added_org_id,
|
||||
"name": "testlelele",
|
||||
"contact": null,
|
||||
"address": {
|
||||
"address1": null,
|
||||
"address2": null,
|
||||
"city": "TestCity",
|
||||
"country": "Burkina Faso",
|
||||
"postalcode": "90174"
|
||||
}
|
||||
}, axios_config);
|
||||
expect(res.status).toEqual(400);
|
||||
expect(res.headers['content-type']).toContain("application/json");
|
||||
});
|
||||
it('adding address to org w/o city should return 400', async () => {
|
||||
const res = await axios.put(base + '/api/organisations/' + added_org_id, {
|
||||
"id": added_org_id,
|
||||
"name": "testlelele",
|
||||
"contact": null,
|
||||
"address": {
|
||||
"address1": "Test1",
|
||||
"address2": null,
|
||||
"city": null,
|
||||
"country": "Burkina Faso",
|
||||
"postalcode": "90174"
|
||||
}
|
||||
}, axios_config);
|
||||
expect(res.status).toEqual(400);
|
||||
expect(res.headers['content-type']).toContain("application/json");
|
||||
});
|
||||
it('adding address to org w/o country should return 400', async () => {
|
||||
const res = await axios.put(base + '/api/organisations/' + added_org_id, {
|
||||
"id": added_org_id,
|
||||
"name": "testlelele",
|
||||
"contact": null,
|
||||
"address": {
|
||||
"address1": "Test1",
|
||||
"address2": null,
|
||||
"city": "TestCity",
|
||||
"country": null,
|
||||
"postalcode": "90174"
|
||||
}
|
||||
}, axios_config);
|
||||
expect(res.status).toEqual(400);
|
||||
expect(res.headers['content-type']).toContain("application/json");
|
||||
});
|
||||
it('adding address to org w/o postal code should return 400', async () => {
|
||||
const res = await axios.put(base + '/api/organisations/' + added_org_id, {
|
||||
"id": added_org_id,
|
||||
"name": "testlelele",
|
||||
"contact": null,
|
||||
"address": {
|
||||
"address1": "Test1",
|
||||
"address2": null,
|
||||
"city": "TestCity",
|
||||
"country": "Burkina Faso",
|
||||
"postalcode": null
|
||||
}
|
||||
}, axios_config);
|
||||
expect(res.status).toEqual(400);
|
||||
expect(res.headers['content-type']).toContain("application/json");
|
||||
});
|
||||
it('adding address to org w/ invalid postal code should return 400', async () => {
|
||||
const res = await axios.put(base + '/api/organisations/' + added_org_id, {
|
||||
"id": added_org_id,
|
||||
"name": "testlelele",
|
||||
"contact": null,
|
||||
"address": {
|
||||
"address1": "Test1",
|
||||
"address2": null,
|
||||
"city": "TestCity",
|
||||
"country": "Burkina Faso",
|
||||
"postalcode": "-1"
|
||||
}
|
||||
}, axios_config);
|
||||
expect(res.status).toEqual(400);
|
||||
expect(res.headers['content-type']).toContain("application/json");
|
||||
});
|
||||
});
|
|
@ -1,131 +1,130 @@
|
|||
import axios from 'axios';
|
||||
import { config } from '../../config';
|
||||
const base = "http://localhost:" + config.internal_port
|
||||
|
||||
let access_token;
|
||||
let axios_config;
|
||||
|
||||
beforeAll(async () => {
|
||||
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('adding + updating name', () => {
|
||||
let added_org;
|
||||
let added_org_id;
|
||||
let added_team;
|
||||
let added_team_id
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res1 = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
added_org = res1.data;
|
||||
added_org_id = added_org.id;
|
||||
expect(res1.status).toEqual(200);
|
||||
expect(res1.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new team with a valid org should return 200', async () => {
|
||||
const res2 = await axios.post(base + '/api/teams', {
|
||||
"name": "test123",
|
||||
"parentGroup": added_org_id
|
||||
}, axios_config);
|
||||
added_team = res2.data;
|
||||
added_team_id = added_team.id;
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('update name', async () => {
|
||||
const res3 = await axios.put(base + '/api/teams/' + added_team_id, {
|
||||
"id": added_team_id,
|
||||
"name": "testlelele",
|
||||
"contact": null,
|
||||
"parentGroup": added_org.id
|
||||
}, axios_config);
|
||||
expect(res3.status).toEqual(200);
|
||||
expect(res3.headers['content-type']).toContain("application/json")
|
||||
let updated_team = res3.data;
|
||||
added_team.name = "testlelele";
|
||||
expect(updated_team).toEqual(added_team)
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('adding + try updating id (should return 406)', () => {
|
||||
let added_org;
|
||||
let added_org_id;
|
||||
let added_team;
|
||||
let added_team_id
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res1 = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
added_org = res1.data;
|
||||
added_org_id = added_org.id;
|
||||
expect(res1.status).toEqual(200);
|
||||
expect(res1.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new team with a valid org should return 200', async () => {
|
||||
const res2 = await axios.post(base + '/api/teams', {
|
||||
"name": "test123",
|
||||
"parentGroup": added_org_id
|
||||
}, axios_config);
|
||||
added_team = res2.data;
|
||||
added_team_id = added_team.id;
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('update team', async () => {
|
||||
added_team.id = added_team.id + 1;
|
||||
added_team.parentGroup = added_team.parentGroup.id;
|
||||
const res3 = await axios.put(base + '/api/teams/' + added_team_id, added_team, axios_config);
|
||||
expect(res3.status).toEqual(406);
|
||||
expect(res3.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('add+update parent org (valid)', () => {
|
||||
let added_org;
|
||||
let added_org2;
|
||||
let added_team;
|
||||
let added_team_id
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res1 = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
added_org = res1.data;
|
||||
expect(res1.status).toEqual(200);
|
||||
expect(res1.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new team with a valid org should return 200', async () => {
|
||||
const res2 = await axios.post(base + '/api/teams', {
|
||||
"name": "test123",
|
||||
"parentGroup": added_org.id
|
||||
}, axios_config);
|
||||
added_team = res2.data;
|
||||
added_team_id = added_team.id;
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res3 = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
added_org2 = res3.data;
|
||||
expect(res3.status).toEqual(200);
|
||||
expect(res3.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('update team', async () => {
|
||||
added_team.parentGroup = added_org2.id;
|
||||
const res4 = await axios.put(base + '/api/teams/' + added_team_id, added_team, axios_config);
|
||||
let updated_team = res4.data;
|
||||
expect(res4.status).toEqual(200);
|
||||
expect(res4.headers['content-type']).toContain("application/json")
|
||||
delete added_org2.address;
|
||||
delete added_org2.contact;
|
||||
delete added_org2.teams;
|
||||
expect(updated_team.parentGroup).toEqual(added_org2)
|
||||
});
|
||||
import axios from 'axios';
|
||||
import { config } from '../../config';
|
||||
const base = "http://localhost:" + config.internal_port
|
||||
|
||||
let access_token;
|
||||
let axios_config;
|
||||
|
||||
beforeAll(async () => {
|
||||
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('adding + updating name', () => {
|
||||
let added_org;
|
||||
let added_org_id;
|
||||
let added_team;
|
||||
let added_team_id
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res1 = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
added_org = res1.data;
|
||||
added_org_id = added_org.id;
|
||||
expect(res1.status).toEqual(200);
|
||||
expect(res1.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new team with a valid org should return 200', async () => {
|
||||
const res2 = await axios.post(base + '/api/teams', {
|
||||
"name": "test123",
|
||||
"parentGroup": added_org_id
|
||||
}, axios_config);
|
||||
added_team = res2.data;
|
||||
added_team_id = added_team.id;
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('update name', async () => {
|
||||
const res3 = await axios.put(base + '/api/teams/' + added_team_id, {
|
||||
"id": added_team_id,
|
||||
"name": "testlelele",
|
||||
"contact": null,
|
||||
"parentGroup": added_org.id
|
||||
}, axios_config);
|
||||
expect(res3.status).toEqual(200);
|
||||
expect(res3.headers['content-type']).toContain("application/json")
|
||||
let updated_team = res3.data;
|
||||
added_team.name = "testlelele";
|
||||
expect(updated_team).toEqual(added_team)
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('adding + try updating id (should return 406)', () => {
|
||||
let added_org;
|
||||
let added_org_id;
|
||||
let added_team;
|
||||
let added_team_id
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res1 = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
added_org = res1.data;
|
||||
added_org_id = added_org.id;
|
||||
expect(res1.status).toEqual(200);
|
||||
expect(res1.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new team with a valid org should return 200', async () => {
|
||||
const res2 = await axios.post(base + '/api/teams', {
|
||||
"name": "test123",
|
||||
"parentGroup": added_org_id
|
||||
}, axios_config);
|
||||
added_team = res2.data;
|
||||
added_team_id = added_team.id;
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('update team', async () => {
|
||||
added_team.id = added_team.id + 1;
|
||||
added_team.parentGroup = added_team.parentGroup.id;
|
||||
const res3 = await axios.put(base + '/api/teams/' + added_team_id, added_team, axios_config);
|
||||
expect(res3.status).toEqual(406);
|
||||
expect(res3.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('add+update parent org (valid)', () => {
|
||||
let added_org;
|
||||
let added_org2;
|
||||
let added_team;
|
||||
let added_team_id
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res1 = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
added_org = res1.data;
|
||||
expect(res1.status).toEqual(200);
|
||||
expect(res1.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new team with a valid org should return 200', async () => {
|
||||
const res2 = await axios.post(base + '/api/teams', {
|
||||
"name": "test123",
|
||||
"parentGroup": added_org.id
|
||||
}, axios_config);
|
||||
added_team = res2.data;
|
||||
added_team_id = added_team.id;
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res3 = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
added_org2 = res3.data;
|
||||
expect(res3.status).toEqual(200);
|
||||
expect(res3.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('update team', async () => {
|
||||
added_team.parentGroup = added_org2.id;
|
||||
const res4 = await axios.put(base + '/api/teams/' + added_team_id, added_team, axios_config);
|
||||
let updated_team = res4.data;
|
||||
expect(res4.status).toEqual(200);
|
||||
expect(res4.headers['content-type']).toContain("application/json")
|
||||
delete added_org2.contact;
|
||||
delete added_org2.teams;
|
||||
expect(updated_team.parentGroup).toEqual(added_org2)
|
||||
});
|
||||
});
|
|
@ -1,160 +1,156 @@
|
|||
import axios from 'axios';
|
||||
import { config } from '../../config';
|
||||
const base = "http://localhost:" + config.internal_port
|
||||
|
||||
let access_token;
|
||||
let axios_config;
|
||||
|
||||
beforeAll(async () => {
|
||||
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('Update runner name after adding', () => {
|
||||
let added_org;
|
||||
let added_runner;
|
||||
let updated_runner;
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res1 = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
added_org = res1.data
|
||||
expect(res1.status).toEqual(200);
|
||||
expect(res1.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new runner with only needed params should return 200', async () => {
|
||||
const res2 = await axios.post(base + '/api/runners', {
|
||||
"firstname": "first",
|
||||
"lastname": "last",
|
||||
"group": added_org.id
|
||||
}, axios_config);
|
||||
added_runner = res2.data;
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('valid update should return 200', async () => {
|
||||
let runnercopy = added_runner
|
||||
runnercopy.firstname = "second"
|
||||
runnercopy.group = added_runner.group.id;
|
||||
const res3 = await axios.put(base + '/api/runners/' + added_runner.id, runnercopy, axios_config);
|
||||
expect(res3.status).toEqual(200);
|
||||
expect(res3.headers['content-type']).toContain("application/json")
|
||||
updated_runner = res3.data;
|
||||
delete added_org.address;
|
||||
delete added_org.contact;
|
||||
delete added_org.teams;
|
||||
runnercopy.group = added_org;
|
||||
expect(updated_runner).toEqual(runnercopy);
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('Update runner group after adding', () => {
|
||||
let added_org_id;
|
||||
let added_org_2;
|
||||
let added_runner;
|
||||
let updated_runner;
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res1 = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
let added_org = res1.data
|
||||
added_org_id = added_org.id;
|
||||
expect(res1.status).toEqual(200);
|
||||
expect(res1.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new runner with only needed params should return 200', async () => {
|
||||
const res2 = await axios.post(base + '/api/runners', {
|
||||
"firstname": "first",
|
||||
"lastname": "last",
|
||||
"group": added_org_id
|
||||
}, axios_config);
|
||||
added_runner = res2.data;
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res3 = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
added_org_2 = res3.data
|
||||
delete added_org_2.address;
|
||||
delete added_org_2.contact;
|
||||
delete added_org_2.teams;
|
||||
expect(res3.status).toEqual(200);
|
||||
expect(res3.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('valid group update should return 200', async () => {
|
||||
added_runner.group = added_org_2.id;
|
||||
const res3 = await axios.put(base + '/api/runners/' + added_runner.id, added_runner, axios_config);
|
||||
expect(res3.status).toEqual(200);
|
||||
expect(res3.headers['content-type']).toContain("application/json")
|
||||
updated_runner = res3.data
|
||||
expect(updated_runner.group).toEqual(added_org_2);
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('Update runner id after adding(should fail)', () => {
|
||||
let added_org_id;
|
||||
let added_runner;
|
||||
let added_runner_id;
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res1 = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
let added_org = res1.data
|
||||
added_org_id = added_org.id;
|
||||
expect(res1.status).toEqual(200);
|
||||
expect(res1.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new runner with only needed params should return 200', async () => {
|
||||
const res2 = await axios.post(base + '/api/runners', {
|
||||
"firstname": "first",
|
||||
"lastname": "last",
|
||||
"group": added_org_id
|
||||
}, axios_config);
|
||||
added_runner = res2.data;
|
||||
added_runner_id = added_runner.id;
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('invalid update should return 406', async () => {
|
||||
added_runner.id++;
|
||||
added_runner.group = added_runner.group.id;
|
||||
const res3 = await axios.put(base + '/api/runners/' + added_runner_id, added_runner, axios_config);
|
||||
expect(res3.status).toEqual(406);
|
||||
expect(res3.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('Update runner group with invalid group after adding', () => {
|
||||
let added_org;
|
||||
let added_runner;
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res1 = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
added_org = res1.data
|
||||
expect(res1.status).toEqual(200);
|
||||
expect(res1.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new runner with only needed params should return 200', async () => {
|
||||
const res2 = await axios.post(base + '/api/runners', {
|
||||
"firstname": "first",
|
||||
"lastname": "last",
|
||||
"group": added_org.id
|
||||
}, axios_config);
|
||||
added_runner = res2.data;
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('invalid group update should return 404', async () => {
|
||||
added_runner.group = 99999999999999999;
|
||||
const res3 = await axios.put(base + '/api/runners/' + added_runner.id, added_runner, axios_config);
|
||||
expect(res3.status).toEqual(404);
|
||||
expect(res3.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
import axios from 'axios';
|
||||
import { config } from '../../config';
|
||||
const base = "http://localhost:" + config.internal_port
|
||||
|
||||
let access_token;
|
||||
let axios_config;
|
||||
|
||||
beforeAll(async () => {
|
||||
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('Update runner name after adding', () => {
|
||||
let added_org;
|
||||
let added_runner;
|
||||
let updated_runner;
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res1 = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
added_org = res1.data
|
||||
expect(res1.status).toEqual(200);
|
||||
expect(res1.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new runner with only needed params should return 200', async () => {
|
||||
const res2 = await axios.post(base + '/api/runners', {
|
||||
"firstname": "first",
|
||||
"lastname": "last",
|
||||
"group": added_org.id
|
||||
}, axios_config);
|
||||
added_runner = res2.data;
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('valid update should return 200', async () => {
|
||||
let runnercopy = added_runner
|
||||
runnercopy.firstname = "second"
|
||||
runnercopy.group = added_runner.group.id;
|
||||
const res3 = await axios.put(base + '/api/runners/' + added_runner.id, runnercopy, axios_config);
|
||||
expect(res3.status).toEqual(200);
|
||||
expect(res3.headers['content-type']).toContain("application/json")
|
||||
updated_runner = res3.data;
|
||||
delete added_org.contact;
|
||||
delete added_org.teams;
|
||||
runnercopy.group = added_org;
|
||||
expect(updated_runner).toEqual(runnercopy);
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('Update runner group after adding', () => {
|
||||
let added_org_id;
|
||||
let added_org_2;
|
||||
let added_runner;
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res1 = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
let added_org = res1.data
|
||||
added_org_id = added_org.id;
|
||||
expect(res1.status).toEqual(200);
|
||||
expect(res1.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new runner with only needed params should return 200', async () => {
|
||||
const res2 = await axios.post(base + '/api/runners', {
|
||||
"firstname": "first",
|
||||
"lastname": "last",
|
||||
"group": added_org_id
|
||||
}, axios_config);
|
||||
added_runner = res2.data;
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res3 = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
added_org_2 = res3.data
|
||||
delete added_org_2.contact;
|
||||
delete added_org_2.teams;
|
||||
expect(res3.status).toEqual(200);
|
||||
expect(res3.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('valid group update should return 200', async () => {
|
||||
added_runner.group = added_org_2.id;
|
||||
const res3 = await axios.put(base + '/api/runners/' + added_runner.id, added_runner, axios_config);
|
||||
expect(res3.status).toEqual(200);
|
||||
expect(res3.headers['content-type']).toContain("application/json")
|
||||
expect(res3.data.group).toEqual(added_org_2);
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('Update runner id after adding(should fail)', () => {
|
||||
let added_org_id;
|
||||
let added_runner;
|
||||
let added_runner_id;
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res1 = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
let added_org = res1.data
|
||||
added_org_id = added_org.id;
|
||||
expect(res1.status).toEqual(200);
|
||||
expect(res1.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new runner with only needed params should return 200', async () => {
|
||||
const res2 = await axios.post(base + '/api/runners', {
|
||||
"firstname": "first",
|
||||
"lastname": "last",
|
||||
"group": added_org_id
|
||||
}, axios_config);
|
||||
added_runner = res2.data;
|
||||
added_runner_id = added_runner.id;
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('invalid update should return 406', async () => {
|
||||
added_runner.id++;
|
||||
added_runner.group = added_runner.group.id;
|
||||
const res3 = await axios.put(base + '/api/runners/' + added_runner_id, added_runner, axios_config);
|
||||
expect(res3.status).toEqual(406);
|
||||
expect(res3.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
describe('Update runner group with invalid group after adding', () => {
|
||||
let added_org;
|
||||
let added_runner;
|
||||
it('creating a new org with just a name should return 200', async () => {
|
||||
const res1 = await axios.post(base + '/api/organisations', {
|
||||
"name": "test123"
|
||||
}, axios_config);
|
||||
added_org = res1.data
|
||||
expect(res1.status).toEqual(200);
|
||||
expect(res1.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('creating a new runner with only needed params should return 200', async () => {
|
||||
const res2 = await axios.post(base + '/api/runners', {
|
||||
"firstname": "first",
|
||||
"lastname": "last",
|
||||
"group": added_org.id
|
||||
}, axios_config);
|
||||
added_runner = res2.data;
|
||||
expect(res2.status).toEqual(200);
|
||||
expect(res2.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
it('invalid group update should return 404', async () => {
|
||||
added_runner.group = 99999999999999999;
|
||||
const res3 = await axios.put(base + '/api/runners/' + added_runner.id, added_runner, axios_config);
|
||||
expect(res3.status).toEqual(404);
|
||||
expect(res3.headers['content-type']).toContain("application/json")
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue