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'); 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 }); 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 }); expect(res.status).toEqual(200); expect(res.headers['content-type']).toContain("application/json") }); it('check if track was added', async () => { const res = await axios.get('http://localhost:4010/api/tracks'); expect(res.status).toEqual(200); expect(res.headers['content-type']).toContain("application/json") let added_track = res.data[res.data.length - 1] delete added_track.id expect(added_track).toEqual({ "name": "string", "distance": 400 }) }); });