Added track update tests
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				continuous-integration/drone/pr Build is passing
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	continuous-integration/drone/pr Build is passing
				
			ref #71
This commit is contained in:
		
							
								
								
									
										98
									
								
								src/tests/tracks/track_update.spec.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										98
									
								
								src/tests/tracks/track_update.spec.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,98 @@ | ||||
| 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 illegally', () => { | ||||
| 	let added_track; | ||||
| 	it('correct distance input should return 200', async () => { | ||||
| 		const res = await axios.post(base + '/api/tracks', { | ||||
| 			"name": "apitrack", | ||||
| 			"distance": 1500 | ||||
| 		}, axios_config); | ||||
| 		expect(res.status).toEqual(200); | ||||
| 		expect(res.headers['content-type']).toContain("application/json"); | ||||
| 		added_track = res.data; | ||||
| 	}); | ||||
| 	it('update with negative distance should return 400', async () => { | ||||
| 		const res2 = await axios.put(base + '/api/tracks/' + added_track.id, { | ||||
| 			"id": added_track.id, | ||||
| 			"name": "apitrack", | ||||
| 			"distance": -1 | ||||
| 		}, axios_config); | ||||
| 		expect(res2.status).toEqual(400); | ||||
| 		expect(res2.headers['content-type']).toContain("application/json") | ||||
| 	}); | ||||
| 	it('update with negative laptime should return 406', async () => { | ||||
| 		const res2 = await axios.put(base + '/api/tracks/' + added_track.id, { | ||||
| 			"id": added_track.id, | ||||
| 			"name": "apitrack", | ||||
| 			"distance": 2, | ||||
| 			"minimumLapTime": -1 | ||||
| 		}, axios_config); | ||||
| 		expect(res2.status).toEqual(406); | ||||
| 		expect(res2.headers['content-type']).toContain("application/json") | ||||
| 	}); | ||||
| }); | ||||
| // --------------- | ||||
| describe('adding + updating successfilly', () => { | ||||
| 	let added_track; | ||||
| 	it('correct distance input should return 200', async () => { | ||||
| 		const res = await axios.post(base + '/api/tracks', { | ||||
| 			"name": "apitrack2", | ||||
| 			"distance": 1500 | ||||
| 		}, axios_config); | ||||
| 		expect(res.status).toEqual(200); | ||||
| 		expect(res.headers['content-type']).toContain("application/json"); | ||||
| 		added_track = res.data; | ||||
| 	}); | ||||
| 	it('valid name change should return 200', async () => { | ||||
| 		const res2 = await axios.put(base + '/api/tracks/' + added_track.id, { | ||||
| 			"id": added_track.id, | ||||
| 			"name": "apitrackk", | ||||
| 			"distance": 1500 | ||||
| 		}, axios_config); | ||||
| 		expect(res2.status).toEqual(200); | ||||
| 		expect(res2.headers['content-type']).toContain("application/json") | ||||
| 	}); | ||||
| 	it('valid distance change should return 200', async () => { | ||||
| 		const res2 = await axios.put(base + '/api/tracks/' + added_track.id, { | ||||
| 			"id": added_track.id, | ||||
| 			"name": "apitrack2", | ||||
| 			"distance": 5100 | ||||
| 		}, axios_config); | ||||
| 		expect(res2.status).toEqual(200); | ||||
| 		expect(res2.headers['content-type']).toContain("application/json") | ||||
| 	}); | ||||
| 	it('valid laptime change (to a set number) should return 200', async () => { | ||||
| 		const res2 = await axios.put(base + '/api/tracks/' + added_track.id, { | ||||
| 			"id": added_track.id, | ||||
| 			"name": "apitrack2", | ||||
| 			"distance": 5100, | ||||
| 			"minimumLapTime": 3 | ||||
| 		}, axios_config); | ||||
| 		expect(res2.status).toEqual(200); | ||||
| 		expect(res2.headers['content-type']).toContain("application/json") | ||||
| 	}); | ||||
| 	it('valid laptime change (to a set null) should return 200', async () => { | ||||
| 		const res2 = await axios.put(base + '/api/tracks/' + added_track.id, { | ||||
| 			"id": added_track.id, | ||||
| 			"name": "apitrack2", | ||||
| 			"distance": 5100, | ||||
| 			"minimumLapTime": null | ||||
| 		}, axios_config); | ||||
| 		expect(res2.status).toEqual(200); | ||||
| 		expect(res2.headers['content-type']).toContain("application/json") | ||||
| 	}); | ||||
| }); | ||||
		Reference in New Issue
	
	Block a user