Compare commits

..

2 Commits

Author SHA1 Message Date
4824547dde Fixed donor address check
ref #105
2021-01-16 18:52:57 +01:00
8dbee32eee Test's now accept the new address format
ref #105
2021-01-16 18:34:53 +01:00
10 changed files with 44 additions and 27 deletions

View File

@ -1,5 +1,6 @@
import { IsBoolean, IsOptional } from 'class-validator'; import { IsBoolean, IsOptional } from 'class-validator';
import { DonorReceiptAddressNeededError } from '../../../errors/DonorErrors'; import { DonorReceiptAddressNeededError } from '../../../errors/DonorErrors';
import { Address } from '../../entities/Address';
import { Donor } from '../../entities/Donor'; import { Donor } from '../../entities/Donor';
import { CreateParticipant } from './CreateParticipant'; import { CreateParticipant } from './CreateParticipant';
@ -29,7 +30,7 @@ export class CreateDonor extends CreateParticipant {
newDonor.receiptNeeded = this.receiptNeeded; newDonor.receiptNeeded = this.receiptNeeded;
newDonor.address = this.address; newDonor.address = this.address;
if (this.receiptNeeded == true && this.address.isValidAddress == false) { if (this.receiptNeeded == true && Address.isValidAddress(newDonor.address) == false) {
throw new DonorReceiptAddressNeededError() throw new DonorReceiptAddressNeededError()
} }

View File

@ -1,5 +1,6 @@
import { IsBoolean, IsInt, IsOptional } from 'class-validator'; import { IsBoolean, IsInt, IsOptional } from 'class-validator';
import { DonorReceiptAddressNeededError } from '../../../errors/DonorErrors'; import { DonorReceiptAddressNeededError } from '../../../errors/DonorErrors';
import { Address } from '../../entities/Address';
import { Donor } from '../../entities/Donor'; import { Donor } from '../../entities/Donor';
import { CreateParticipant } from '../create/CreateParticipant'; import { CreateParticipant } from '../create/CreateParticipant';
@ -34,8 +35,7 @@ export class UpdateDonor extends CreateParticipant {
donor.email = this.email; donor.email = this.email;
donor.receiptNeeded = this.receiptNeeded; donor.receiptNeeded = this.receiptNeeded;
donor.address = this.address; donor.address = this.address;
if (this.receiptNeeded == true && Address.isValidAddress(donor.address) == false) {
if (this.receiptNeeded == true && this.address == null) {
throw new DonorReceiptAddressNeededError() throw new DonorReceiptAddressNeededError()
} }

View File

@ -59,8 +59,9 @@ export class Address {
/** /**
* Checks if this is a valid address * Checks if this is a valid address
*/ */
public get isValidAddress(): Boolean { public static isValidAddress(address: Address): Boolean {
if (!this.address1 || !this.city || !this.country || !this.postalcode) { return false; } if (address == null) { return false; }
if (address.address1 == null || address.city == null || address.country == null || address.postalcode == null) { return false; }
return true; return true;
} }
} }

View File

@ -29,16 +29,6 @@ describe('POST /api/donors with errors', () => {
expect(res2.status).toEqual(400); expect(res2.status).toEqual(400);
expect(res2.headers['content-type']).toContain("application/json") 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 () => { it('creating a new donor with a invalid phone number should return 400', async () => {
const res2 = await axios.post(base + '/api/donors', { const res2 = await axios.post(base + '/api/donors', {
"firstname": "first", "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 () => { it('creating a new donor with only needed params should return 200', async () => {
const res2 = await axios.post(base + '/api/donors', { const res2 = await axios.post(base + '/api/donors', {
"firstname": "first", "firstname": "first",
"lastname": "last", "lastname": "testtest",
}, axios_config); }, axios_config);
added_donor = res2.data; added_donor = res2.data;
expect(res2.status).toEqual(200); expect(res2.status).toEqual(200);

View File

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

View File

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

View File

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

View File

@ -123,7 +123,6 @@ describe('add+update parent org (valid)', () => {
let updated_team = res4.data; let updated_team = res4.data;
expect(res4.status).toEqual(200); expect(res4.status).toEqual(200);
expect(res4.headers['content-type']).toContain("application/json") expect(res4.headers['content-type']).toContain("application/json")
delete added_org2.address;
delete added_org2.contact; delete added_org2.contact;
delete added_org2.teams; delete added_org2.teams;
expect(updated_team.parentGroup).toEqual(added_org2) expect(updated_team.parentGroup).toEqual(added_org2)

View File

@ -44,7 +44,6 @@ describe('Update runner name after adding', () => {
expect(res3.status).toEqual(200); expect(res3.status).toEqual(200);
expect(res3.headers['content-type']).toContain("application/json") expect(res3.headers['content-type']).toContain("application/json")
updated_runner = res3.data; updated_runner = res3.data;
delete added_org.address;
delete added_org.contact; delete added_org.contact;
delete added_org.teams; delete added_org.teams;
runnercopy.group = added_org; runnercopy.group = added_org;
@ -56,7 +55,6 @@ describe('Update runner group after adding', () => {
let added_org_id; let added_org_id;
let added_org_2; let added_org_2;
let added_runner; let added_runner;
let updated_runner;
it('creating a new org with just a name should return 200', async () => { it('creating a new org with just a name should return 200', async () => {
const res1 = await axios.post(base + '/api/organisations', { const res1 = await axios.post(base + '/api/organisations', {
"name": "test123" "name": "test123"
@ -81,7 +79,6 @@ describe('Update runner group after adding', () => {
"name": "test123" "name": "test123"
}, axios_config); }, axios_config);
added_org_2 = res3.data added_org_2 = res3.data
delete added_org_2.address;
delete added_org_2.contact; delete added_org_2.contact;
delete added_org_2.teams; delete added_org_2.teams;
expect(res3.status).toEqual(200); expect(res3.status).toEqual(200);
@ -92,8 +89,7 @@ describe('Update runner group after adding', () => {
const res3 = await axios.put(base + '/api/runners/' + added_runner.id, added_runner, axios_config); const res3 = await axios.put(base + '/api/runners/' + added_runner.id, added_runner, axios_config);
expect(res3.status).toEqual(200); expect(res3.status).toEqual(200);
expect(res3.headers['content-type']).toContain("application/json") expect(res3.headers['content-type']).toContain("application/json")
updated_runner = res3.data expect(res3.data.group).toEqual(added_org_2);
expect(updated_runner.group).toEqual(added_org_2);
}); });
}); });
// --------------- // ---------------