@@ -36,36 +36,36 @@ describe('adding + updating fixed donation illegally', () => {
 | 
				
			|||||||
		expect(res.headers['content-type']).toContain("application/json")
 | 
							expect(res.headers['content-type']).toContain("application/json")
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
	it('updating empty should return 400', async () => {
 | 
						it('updating empty should return 400', async () => {
 | 
				
			||||||
		const res2 = await axios.put(base + '/api/donations/fixed/' + added_donation.id, null, axios_config);
 | 
							const res = await axios.put(base + '/api/donations/fixed/' + added_donation.id, null, axios_config);
 | 
				
			||||||
		expect(res2.status).toEqual(400);
 | 
							expect(res.status).toEqual(400);
 | 
				
			||||||
		expect(res2.headers['content-type']).toContain("application/json")
 | 
							expect(res.headers['content-type']).toContain("application/json")
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
	it('updating with wrong id should return 406', async () => {
 | 
						it('updating with wrong id should return 406', async () => {
 | 
				
			||||||
		const res2 = await axios.put(base + '/api/donations/fixed/' + added_donation.id, {
 | 
							const res = await axios.put(base + '/api/donations/fixed/' + added_donation.id, {
 | 
				
			||||||
			"id": added_donation.id + 1,
 | 
								"id": added_donation.id + 1,
 | 
				
			||||||
			"donor": added_donor.id,
 | 
								"donor": added_donor.id,
 | 
				
			||||||
			"amount": 100
 | 
								"amount": 100
 | 
				
			||||||
		}, axios_config);
 | 
							}, axios_config);
 | 
				
			||||||
		expect(res2.status).toEqual(406);
 | 
							expect(res.status).toEqual(406);
 | 
				
			||||||
		expect(res2.headers['content-type']).toContain("application/json")
 | 
							expect(res.headers['content-type']).toContain("application/json")
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
	it('updating with negative amount should return 400', async () => {
 | 
						it('updating with negative amount should return 400', async () => {
 | 
				
			||||||
		const res2 = await axios.put(base + '/api/donations/fixed/' + added_donation.id, {
 | 
							const res = await axios.put(base + '/api/donations/fixed/' + added_donation.id, {
 | 
				
			||||||
			"id": added_donation.id,
 | 
								"id": added_donation.id,
 | 
				
			||||||
			"donor": added_donor.id,
 | 
								"donor": added_donor.id,
 | 
				
			||||||
			"amount": -1
 | 
								"amount": -1
 | 
				
			||||||
		}, axios_config);
 | 
							}, axios_config);
 | 
				
			||||||
		expect(res2.status).toEqual(400);
 | 
							expect(res.status).toEqual(400);
 | 
				
			||||||
		expect(res2.headers['content-type']).toContain("application/json")
 | 
							expect(res.headers['content-type']).toContain("application/json")
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
	it('updating with invalid donor should return 404', async () => {
 | 
						it('updating with invalid donor should return 404', async () => {
 | 
				
			||||||
		const res2 = await axios.put(base + '/api/donations/fixed/' + added_donation.id, {
 | 
							const res = await axios.put(base + '/api/donations/fixed/' + added_donation.id, {
 | 
				
			||||||
			"id": added_donation.id,
 | 
								"id": added_donation.id,
 | 
				
			||||||
			"donor": 9999999999999999999,
 | 
								"donor": 9999999999999999999,
 | 
				
			||||||
			"amount": 100
 | 
								"amount": 100
 | 
				
			||||||
		}, axios_config);
 | 
							}, axios_config);
 | 
				
			||||||
		expect(res2.status).toEqual(404);
 | 
							expect(res.status).toEqual(404);
 | 
				
			||||||
		expect(res2.headers['content-type']).toContain("application/json")
 | 
							expect(res.headers['content-type']).toContain("application/json")
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
// ---------------
 | 
					// ---------------
 | 
				
			||||||
@@ -112,48 +112,229 @@ describe('adding + updating distance donation illegally', () => {
 | 
				
			|||||||
		expect(res.headers['content-type']).toContain("application/json")
 | 
							expect(res.headers['content-type']).toContain("application/json")
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
	it('updating empty should return 400', async () => {
 | 
						it('updating empty should return 400', async () => {
 | 
				
			||||||
		const res2 = await axios.put(base + '/api/donations/distance/' + added_donation.id, null, axios_config);
 | 
							const res = await axios.put(base + '/api/donations/distance/' + added_donation.id, null, axios_config);
 | 
				
			||||||
		expect(res2.status).toEqual(400);
 | 
							expect(res.status).toEqual(400);
 | 
				
			||||||
		expect(res2.headers['content-type']).toContain("application/json")
 | 
							expect(res.headers['content-type']).toContain("application/json")
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
	it('updating with wrong id should return 406', async () => {
 | 
						it('updating with wrong id should return 406', async () => {
 | 
				
			||||||
		const res2 = await axios.put(base + '/api/donations/distance/' + added_donation.id, {
 | 
							const res = await axios.put(base + '/api/donations/distance/' + added_donation.id, {
 | 
				
			||||||
			"id": added_donation.id + 1,
 | 
								"id": added_donation.id + 1,
 | 
				
			||||||
			"runner": added_runner.id,
 | 
								"runner": added_runner.id,
 | 
				
			||||||
			"amountPerDistance": 100,
 | 
								"amountPerDistance": 100,
 | 
				
			||||||
			"donor": added_donor.id
 | 
								"donor": added_donor.id
 | 
				
			||||||
		}, axios_config);
 | 
							}, axios_config);
 | 
				
			||||||
		expect(res2.status).toEqual(406);
 | 
							expect(res.status).toEqual(406);
 | 
				
			||||||
		expect(res2.headers['content-type']).toContain("application/json")
 | 
							expect(res.headers['content-type']).toContain("application/json")
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
	it('updating with negative amountPerDistance should return 400', async () => {
 | 
						it('updating with negative amountPerDistance should return 400', async () => {
 | 
				
			||||||
		const res2 = await axios.put(base + '/api/donations/distance/' + added_donation.id, {
 | 
							const res = await axios.put(base + '/api/donations/distance/' + added_donation.id, {
 | 
				
			||||||
			"id": added_donation.id,
 | 
								"id": added_donation.id,
 | 
				
			||||||
			"runner": added_runner.id,
 | 
								"runner": added_runner.id,
 | 
				
			||||||
			"amountPerDistance": -1,
 | 
								"amountPerDistance": -1,
 | 
				
			||||||
			"donor": added_donor.id
 | 
								"donor": added_donor.id
 | 
				
			||||||
		}, axios_config);
 | 
							}, axios_config);
 | 
				
			||||||
		expect(res2.status).toEqual(400);
 | 
							expect(res.status).toEqual(400);
 | 
				
			||||||
		expect(res2.headers['content-type']).toContain("application/json")
 | 
							expect(res.headers['content-type']).toContain("application/json")
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
	it('updating with invalid donor should return 404', async () => {
 | 
						it('updating with invalid donor should return 404', async () => {
 | 
				
			||||||
		const res2 = await axios.put(base + '/api/donations/distance/' + added_donation.id, {
 | 
							const res = await axios.put(base + '/api/donations/distance/' + added_donation.id, {
 | 
				
			||||||
			"id": added_donation.id,
 | 
								"id": added_donation.id,
 | 
				
			||||||
			"runner": added_runner.id,
 | 
								"runner": added_runner.id,
 | 
				
			||||||
			"amountPerDistance": 100,
 | 
								"amountPerDistance": 100,
 | 
				
			||||||
			"donor": 9999999999999999999
 | 
								"donor": 9999999999999999999
 | 
				
			||||||
		}, axios_config);
 | 
							}, axios_config);
 | 
				
			||||||
		expect(res2.status).toEqual(404);
 | 
							expect(res.status).toEqual(404);
 | 
				
			||||||
		expect(res2.headers['content-type']).toContain("application/json")
 | 
							expect(res.headers['content-type']).toContain("application/json")
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
	it('updating with invalid runner should return 404', async () => {
 | 
						it('updating with invalid runner should return 404', async () => {
 | 
				
			||||||
		const res2 = await axios.put(base + '/api/donations/distance/' + added_donation.id, {
 | 
							const res = await axios.put(base + '/api/donations/distance/' + added_donation.id, {
 | 
				
			||||||
			"id": added_donation.id,
 | 
								"id": added_donation.id,
 | 
				
			||||||
			"runner": 9999999999999999999,
 | 
								"runner": 9999999999999999999,
 | 
				
			||||||
			"amountPerDistance": 100,
 | 
								"amountPerDistance": 100,
 | 
				
			||||||
			"donor": added_donor.id
 | 
								"donor": added_donor.id
 | 
				
			||||||
		}, axios_config);
 | 
							}, axios_config);
 | 
				
			||||||
		expect(res2.status).toEqual(404);
 | 
							expect(res.status).toEqual(404);
 | 
				
			||||||
		expect(res2.headers['content-type']).toContain("application/json")
 | 
							expect(res.headers['content-type']).toContain("application/json")
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					// ---------------
 | 
				
			||||||
 | 
					describe('adding + updating fixed donation valid', () => {
 | 
				
			||||||
 | 
						let added_donor;
 | 
				
			||||||
 | 
						let added_donor2;
 | 
				
			||||||
 | 
						let added_donation;
 | 
				
			||||||
 | 
						it('creating a new donor with only needed params should return 200', async () => {
 | 
				
			||||||
 | 
							const res = await axios.post(base + '/api/donors', {
 | 
				
			||||||
 | 
								"firstname": "first",
 | 
				
			||||||
 | 
								"lastname": "last"
 | 
				
			||||||
 | 
							}, axios_config);
 | 
				
			||||||
 | 
							added_donor = res.data
 | 
				
			||||||
 | 
							expect(res.status).toEqual(200);
 | 
				
			||||||
 | 
							expect(res.headers['content-type']).toContain("application/json")
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
						it('creating a new donor with only needed params should return 200', async () => {
 | 
				
			||||||
 | 
							const res = await axios.post(base + '/api/donors', {
 | 
				
			||||||
 | 
								"firstname": "first",
 | 
				
			||||||
 | 
								"lastname": "last"
 | 
				
			||||||
 | 
							}, axios_config);
 | 
				
			||||||
 | 
							delete res.data.donationAmount;
 | 
				
			||||||
 | 
							added_donor2 = res.data
 | 
				
			||||||
 | 
							expect(res.status).toEqual(200);
 | 
				
			||||||
 | 
							expect(res.headers['content-type']).toContain("application/json")
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
						it('creating a new fixed donation should return 200', async () => {
 | 
				
			||||||
 | 
							const res = await axios.post(base + '/api/donations/fixed', {
 | 
				
			||||||
 | 
								"donor": added_donor.id,
 | 
				
			||||||
 | 
								"amount": 1000
 | 
				
			||||||
 | 
							}, axios_config);
 | 
				
			||||||
 | 
							added_donation = res.data;
 | 
				
			||||||
 | 
							expect(res.status).toEqual(200);
 | 
				
			||||||
 | 
							expect(res.headers['content-type']).toContain("application/json")
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
						it('updating nothing should return 200', async () => {
 | 
				
			||||||
 | 
							const res = await axios.put(base + '/api/donations/fixed/' + added_donation.id, {
 | 
				
			||||||
 | 
								"id": added_donation.id,
 | 
				
			||||||
 | 
								"donor": added_donor.id,
 | 
				
			||||||
 | 
								"amount": 1000
 | 
				
			||||||
 | 
							}, axios_config);
 | 
				
			||||||
 | 
							delete res.data.donor.donationAmount;
 | 
				
			||||||
 | 
							expect(res.status).toEqual(200);
 | 
				
			||||||
 | 
							expect(res.headers['content-type']).toContain("application/json");
 | 
				
			||||||
 | 
							expect(res.data).toEqual(added_donation);
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
						it('updating amount should return 200', async () => {
 | 
				
			||||||
 | 
							const res = await axios.put(base + '/api/donations/fixed/' + added_donation.id, {
 | 
				
			||||||
 | 
								"id": added_donation.id,
 | 
				
			||||||
 | 
								"donor": added_donor.id,
 | 
				
			||||||
 | 
								"amount": 42
 | 
				
			||||||
 | 
							}, axios_config);
 | 
				
			||||||
 | 
							expect(res.status).toEqual(200);
 | 
				
			||||||
 | 
							expect(res.headers['content-type']).toContain("application/json");
 | 
				
			||||||
 | 
							expect(res.data.amount).toEqual(42);
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
						it('updating donor should return 200', async () => {
 | 
				
			||||||
 | 
							const res = await axios.put(base + '/api/donations/fixed/' + added_donation.id, {
 | 
				
			||||||
 | 
								"id": added_donation.id,
 | 
				
			||||||
 | 
								"donor": added_donor2.id,
 | 
				
			||||||
 | 
								"amount": 42
 | 
				
			||||||
 | 
							}, axios_config);
 | 
				
			||||||
 | 
							delete res.data.donor.donationAmount;
 | 
				
			||||||
 | 
							expect(res.status).toEqual(200);
 | 
				
			||||||
 | 
							expect(res.headers['content-type']).toContain("application/json");
 | 
				
			||||||
 | 
							expect(res.data.donor).toEqual(added_donor2);
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					// ---------------
 | 
				
			||||||
 | 
					describe('adding + updating distance donation valid', () => {
 | 
				
			||||||
 | 
						let added_donor;
 | 
				
			||||||
 | 
						let added_donor2;
 | 
				
			||||||
 | 
						let added_org;
 | 
				
			||||||
 | 
						let added_runner;
 | 
				
			||||||
 | 
						let added_runner2;
 | 
				
			||||||
 | 
						let added_donation;
 | 
				
			||||||
 | 
						it('creating a new donor with only needed params should return 200', async () => {
 | 
				
			||||||
 | 
							const res = await axios.post(base + '/api/donors', {
 | 
				
			||||||
 | 
								"firstname": "first",
 | 
				
			||||||
 | 
								"lastname": "last"
 | 
				
			||||||
 | 
							}, axios_config);
 | 
				
			||||||
 | 
							added_donor = res.data
 | 
				
			||||||
 | 
							expect(res.status).toEqual(200);
 | 
				
			||||||
 | 
							expect(res.headers['content-type']).toContain("application/json")
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
						it('creating a new donor with only needed params should return 200', async () => {
 | 
				
			||||||
 | 
							const res = await axios.post(base + '/api/donors', {
 | 
				
			||||||
 | 
								"firstname": "first",
 | 
				
			||||||
 | 
								"lastname": "last"
 | 
				
			||||||
 | 
							}, axios_config);
 | 
				
			||||||
 | 
							added_donor2 = res.data
 | 
				
			||||||
 | 
							expect(res.status).toEqual(200);
 | 
				
			||||||
 | 
							expect(res.headers['content-type']).toContain("application/json")
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
						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
 | 
				
			||||||
 | 
							expect(res.status).toEqual(200);
 | 
				
			||||||
 | 
							expect(res.headers['content-type']).toContain("application/json")
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
						it('creating a new runner with only needed params should return 200', async () => {
 | 
				
			||||||
 | 
							const res = await axios.post(base + '/api/runners', {
 | 
				
			||||||
 | 
								"firstname": "first",
 | 
				
			||||||
 | 
								"lastname": "last",
 | 
				
			||||||
 | 
								"group": added_org.id
 | 
				
			||||||
 | 
							}, axios_config);
 | 
				
			||||||
 | 
							added_runner = res.data;
 | 
				
			||||||
 | 
							expect(res.status).toEqual(200);
 | 
				
			||||||
 | 
							expect(res.headers['content-type']).toContain("application/json")
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
						it('creating a new runner with only needed params should return 200', async () => {
 | 
				
			||||||
 | 
							const res = await axios.post(base + '/api/runners', {
 | 
				
			||||||
 | 
								"firstname": "first",
 | 
				
			||||||
 | 
								"lastname": "last",
 | 
				
			||||||
 | 
								"group": added_org.id
 | 
				
			||||||
 | 
							}, axios_config);
 | 
				
			||||||
 | 
							delete res.data.group;
 | 
				
			||||||
 | 
							added_runner2 = res.data;
 | 
				
			||||||
 | 
							expect(res.status).toEqual(200);
 | 
				
			||||||
 | 
							expect(res.headers['content-type']).toContain("application/json")
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
						it('creating a new distance donation should return 200', async () => {
 | 
				
			||||||
 | 
							const res = await axios.post(base + '/api/donations/distance', {
 | 
				
			||||||
 | 
								"runner": added_runner.id,
 | 
				
			||||||
 | 
								"amountPerDistance": 100,
 | 
				
			||||||
 | 
								"donor": added_donor.id
 | 
				
			||||||
 | 
							}, axios_config);
 | 
				
			||||||
 | 
							delete res.data.donor.donationAmount;
 | 
				
			||||||
 | 
							added_donation = res.data;
 | 
				
			||||||
 | 
							expect(res.status).toEqual(200);
 | 
				
			||||||
 | 
							expect(res.headers['content-type']).toContain("application/json")
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
						it('updating nothing should return 200', async () => {
 | 
				
			||||||
 | 
							const res = await axios.put(base + '/api/donations/distance/' + added_donation.id, {
 | 
				
			||||||
 | 
								"id": added_donation.id,
 | 
				
			||||||
 | 
								"runner": added_runner.id,
 | 
				
			||||||
 | 
								"amountPerDistance": 100,
 | 
				
			||||||
 | 
								"donor": added_donor.id
 | 
				
			||||||
 | 
							}, axios_config);
 | 
				
			||||||
 | 
							delete res.data.donor.donationAmount;
 | 
				
			||||||
 | 
							expect(res.status).toEqual(200);
 | 
				
			||||||
 | 
							expect(res.headers['content-type']).toContain("application/json");
 | 
				
			||||||
 | 
							expect(res.data).toEqual(added_donation);
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
						it('updating amount should return 200', async () => {
 | 
				
			||||||
 | 
							const res = await axios.put(base + '/api/donations/distance/' + added_donation.id, {
 | 
				
			||||||
 | 
								"id": added_donation.id,
 | 
				
			||||||
 | 
								"runner": added_runner.id,
 | 
				
			||||||
 | 
								"amountPerDistance": 69,
 | 
				
			||||||
 | 
								"donor": added_donor.id
 | 
				
			||||||
 | 
							}, axios_config);
 | 
				
			||||||
 | 
							delete res.data.donor.donationAmount;
 | 
				
			||||||
 | 
							expect(res.status).toEqual(200);
 | 
				
			||||||
 | 
							expect(res.headers['content-type']).toContain("application/json");
 | 
				
			||||||
 | 
							expect(res.data.amountPerDistance).toEqual(69);
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
						it('updating runner should return 200', async () => {
 | 
				
			||||||
 | 
							const res = await axios.put(base + '/api/donations/distance/' + added_donation.id, {
 | 
				
			||||||
 | 
								"id": added_donation.id,
 | 
				
			||||||
 | 
								"runner": added_runner2.id,
 | 
				
			||||||
 | 
								"amountPerDistance": 69,
 | 
				
			||||||
 | 
								"donor": added_donor.id
 | 
				
			||||||
 | 
							}, axios_config);
 | 
				
			||||||
 | 
							delete res.data.runner.group;
 | 
				
			||||||
 | 
							expect(res.status).toEqual(200);
 | 
				
			||||||
 | 
							expect(res.headers['content-type']).toContain("application/json");
 | 
				
			||||||
 | 
							expect(res.data.runner).toEqual(added_runner2);
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
						it('updating donor should return 200', async () => {
 | 
				
			||||||
 | 
							const res = await axios.put(base + '/api/donations/distance/' + added_donation.id, {
 | 
				
			||||||
 | 
								"id": added_donation.id,
 | 
				
			||||||
 | 
								"runner": added_runner2.id,
 | 
				
			||||||
 | 
								"amountPerDistance": 69,
 | 
				
			||||||
 | 
								"donor": added_donor2.id
 | 
				
			||||||
 | 
							}, axios_config);
 | 
				
			||||||
 | 
							delete res.data.donor.donationAmount;
 | 
				
			||||||
 | 
							expect(res.status).toEqual(200);
 | 
				
			||||||
 | 
							expect(res.headers['content-type']).toContain("application/json");
 | 
				
			||||||
 | 
							expect(res.data.donor).toEqual(added_donor2);
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
		Reference in New Issue
	
	Block a user