From 07e03ff04e6e51113f9dcdd9e0c2f6bde2c1b906 Mon Sep 17 00:00:00 2001 From: Philipp Dormann Date: Sat, 5 Dec 2020 20:11:52 +0100 Subject: [PATCH] basic track testing ref #17 --- src/tests/tracks.spec.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/tests/tracks.spec.ts diff --git a/src/tests/tracks.spec.ts b/src/tests/tracks.spec.ts new file mode 100644 index 0000000..e9ebad7 --- /dev/null +++ b/src/tests/tracks.spec.ts @@ -0,0 +1,36 @@ +import axios from 'axios'; + +describe('GET /api/tracks', () => { + it('basic get should return 200', async () => { + const res = await axios.get('http://localhost:4010/api/tracks', { validateStatus: undefined }); + expect(res.status).toEqual(200); + expect(res.headers['content-type']).toContain("application/json") + }); + it('correct distance input should return 200', async () => { + const res = await axios.post('http://localhost:4010/api/tracks', { + "name": "string", + "distance": 400 + }, { validateStatus: undefined }); + expect(res.status).toEqual(200); + expect(res.headers['content-type']).toContain("application/json") + }); +}); +// --------------- +describe('POST /api/tracks', () => { + it('illegal distance input should return 400', async () => { + const res = await axios.post('http://localhost:4010/api/tracks', { + "name": "string", + "distance": -1 + }, { validateStatus: undefined }); + expect(res.status).toEqual(400); + expect(res.headers['content-type']).toContain("application/json") + }); + it('correct distance input should return 200', async () => { + const res = await axios.post('http://localhost:4010/api/tracks', { + "name": "string", + "distance": 400 + }, { validateStatus: undefined }); + expect(res.status).toEqual(200); + expect(res.headers['content-type']).toContain("application/json") + }); +});