Compare commits

..

No commits in common. "4824547dde4d7f90e9e2377a26df34cabf082fdb" and "ae7c5ff0c387e9337d01a9dd819a4dddc208f6dd" have entirely different histories.

10 changed files with 27 additions and 44 deletions

View File

@ -1,6 +1,5 @@
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';
@ -30,7 +29,7 @@ export class CreateDonor extends CreateParticipant {
newDonor.receiptNeeded = this.receiptNeeded;
newDonor.address = this.address;
if (this.receiptNeeded == true && Address.isValidAddress(newDonor.address) == false) {
if (this.receiptNeeded == true && this.address.isValidAddress == false) {
throw new DonorReceiptAddressNeededError()
}

View File

@ -1,6 +1,5 @@
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';
@ -35,7 +34,8 @@ export class UpdateDonor extends CreateParticipant {
donor.email = this.email;
donor.receiptNeeded = this.receiptNeeded;
donor.address = this.address;
if (this.receiptNeeded == true && Address.isValidAddress(donor.address) == false) {
if (this.receiptNeeded == true && this.address == null) {
throw new DonorReceiptAddressNeededError()
}

View File

@ -59,9 +59,8 @@ export class Address {
/**
* 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; }
public get isValidAddress(): Boolean {
if (!this.address1 || !this.city || !this.country || !this.postalcode) { return false; }
return true;
}
}

View File

@ -29,6 +29,16 @@ describe('POST /api/donors with errors', () => {
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",

View File

@ -60,7 +60,7 @@ describe('Update donor without address but receiptNeeded=true should fail', () =
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",
"lastname": "last",
}, axios_config);
added_donor = res2.data;
expect(res2.status).toEqual(200);

View File

@ -56,13 +56,7 @@ describe('adding + getting from all orgs', () => {
expect(added_org).toEqual({
"name": "test123",
"contact": null,
"address": {
"address1": null,
"address2": null,
"city": null,
"country": null,
"postalcode": null,
},
"address": null,
"teams": []
})
});
@ -89,13 +83,7 @@ describe('adding + getting explicitly', () => {
expect(added_org2).toEqual({
"name": "test123",
"contact": null,
"address": {
"address1": null,
"address2": null,
"city": null,
"country": null,
"postalcode": null,
},
"address": null,
"teams": []
})
});

View File

@ -44,13 +44,7 @@ describe('adding + deletion (successfull)', () => {
expect(added_org2).toEqual({
"name": "test123",
"contact": null,
"address": {
"address1": null,
"address2": null,
"city": null,
"country": null,
"postalcode": null,
},
"address": null,
"teams": []
});
});
@ -127,13 +121,7 @@ describe('adding + deletion with teams still existing (with force)', () => {
expect(added_org2).toEqual({
"name": "test123",
"contact": null,
"address": {
"address1": null,
"address2": null,
"city": null,
"country": null,
"postalcode": null,
},
"address": null
});
});
it('check if org really was deleted', async () => {

View File

@ -42,13 +42,7 @@ describe('adding + updating name', () => {
expect(added_org2).toEqual({
"name": "testlelele",
"contact": null,
"address": {
"address1": null,
"address2": null,
"city": null,
"country": null,
"postalcode": null,
},
"address": null,
"teams": []
})
});

View File

@ -123,6 +123,7 @@ describe('add+update parent org (valid)', () => {
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)

View File

@ -44,6 +44,7 @@ describe('Update runner name after adding', () => {
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;
@ -55,6 +56,7 @@ 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"
@ -79,6 +81,7 @@ describe('Update runner group after adding', () => {
"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);
@ -89,7 +92,8 @@ describe('Update runner group after adding', () => {
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);
updated_runner = res3.data
expect(updated_runner.group).toEqual(added_org_2);
});
});
// ---------------