Compare commits
2 Commits
ae7c5ff0c3
...
4824547dde
Author | SHA1 | Date | |
---|---|---|---|
4824547dde | |||
8dbee32eee |
@ -1,5 +1,6 @@
|
||||
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';
|
||||
|
||||
@ -29,7 +30,7 @@ export class CreateDonor extends CreateParticipant {
|
||||
newDonor.receiptNeeded = this.receiptNeeded;
|
||||
newDonor.address = this.address;
|
||||
|
||||
if (this.receiptNeeded == true && this.address.isValidAddress == false) {
|
||||
if (this.receiptNeeded == true && Address.isValidAddress(newDonor.address) == false) {
|
||||
throw new DonorReceiptAddressNeededError()
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
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';
|
||||
|
||||
@ -34,8 +35,7 @@ export class UpdateDonor extends CreateParticipant {
|
||||
donor.email = this.email;
|
||||
donor.receiptNeeded = this.receiptNeeded;
|
||||
donor.address = this.address;
|
||||
|
||||
if (this.receiptNeeded == true && this.address == null) {
|
||||
if (this.receiptNeeded == true && Address.isValidAddress(donor.address) == false) {
|
||||
throw new DonorReceiptAddressNeededError()
|
||||
}
|
||||
|
||||
|
@ -59,8 +59,9 @@ export class Address {
|
||||
/**
|
||||
* Checks if this is a valid address
|
||||
*/
|
||||
public get isValidAddress(): Boolean {
|
||||
if (!this.address1 || !this.city || !this.country || !this.postalcode) { return false; }
|
||||
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; }
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -29,16 +29,6 @@ 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",
|
||||
|
@ -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": "last",
|
||||
"lastname": "testtest",
|
||||
}, axios_config);
|
||||
added_donor = res2.data;
|
||||
expect(res2.status).toEqual(200);
|
||||
|
@ -56,7 +56,13 @@ describe('adding + getting from all orgs', () => {
|
||||
expect(added_org).toEqual({
|
||||
"name": "test123",
|
||||
"contact": null,
|
||||
"address": null,
|
||||
"address": {
|
||||
"address1": null,
|
||||
"address2": null,
|
||||
"city": null,
|
||||
"country": null,
|
||||
"postalcode": null,
|
||||
},
|
||||
"teams": []
|
||||
})
|
||||
});
|
||||
@ -83,7 +89,13 @@ describe('adding + getting explicitly', () => {
|
||||
expect(added_org2).toEqual({
|
||||
"name": "test123",
|
||||
"contact": null,
|
||||
"address": null,
|
||||
"address": {
|
||||
"address1": null,
|
||||
"address2": null,
|
||||
"city": null,
|
||||
"country": null,
|
||||
"postalcode": null,
|
||||
},
|
||||
"teams": []
|
||||
})
|
||||
});
|
||||
|
@ -44,7 +44,13 @@ describe('adding + deletion (successfull)', () => {
|
||||
expect(added_org2).toEqual({
|
||||
"name": "test123",
|
||||
"contact": null,
|
||||
"address": null,
|
||||
"address": {
|
||||
"address1": null,
|
||||
"address2": null,
|
||||
"city": null,
|
||||
"country": null,
|
||||
"postalcode": null,
|
||||
},
|
||||
"teams": []
|
||||
});
|
||||
});
|
||||
@ -121,7 +127,13 @@ describe('adding + deletion with teams still existing (with force)', () => {
|
||||
expect(added_org2).toEqual({
|
||||
"name": "test123",
|
||||
"contact": null,
|
||||
"address": null
|
||||
"address": {
|
||||
"address1": null,
|
||||
"address2": null,
|
||||
"city": null,
|
||||
"country": null,
|
||||
"postalcode": null,
|
||||
},
|
||||
});
|
||||
});
|
||||
it('check if org really was deleted', async () => {
|
||||
|
@ -42,7 +42,13 @@ describe('adding + updating name', () => {
|
||||
expect(added_org2).toEqual({
|
||||
"name": "testlelele",
|
||||
"contact": null,
|
||||
"address": null,
|
||||
"address": {
|
||||
"address1": null,
|
||||
"address2": null,
|
||||
"city": null,
|
||||
"country": null,
|
||||
"postalcode": null,
|
||||
},
|
||||
"teams": []
|
||||
})
|
||||
});
|
||||
|
@ -123,7 +123,6 @@ 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)
|
||||
|
@ -44,7 +44,6 @@ 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;
|
||||
@ -56,7 +55,6 @@ 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"
|
||||
@ -81,7 +79,6 @@ 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);
|
||||
@ -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);
|
||||
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);
|
||||
expect(res3.data.group).toEqual(added_org_2);
|
||||
});
|
||||
});
|
||||
// ---------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user