🧪tracks.spec.ts - move to baseurl

ref #17
This commit is contained in:
Philipp Dormann 2020-12-05 20:45:06 +01:00
parent 29acabfca3
commit def7ca3eb2

View File

@ -1,13 +1,14 @@
import axios from 'axios'; import axios from 'axios';
const base = "http://localhost:4010"
describe('GET /api/tracks', () => { describe('GET /api/tracks', () => {
it('basic get should return 200', async () => { it('basic get should return 200', async () => {
const res = await axios.get('http://localhost:4010/api/tracks'); const res = await axios.get(base + '/api/tracks');
expect(res.status).toEqual(200); expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json") expect(res.headers['content-type']).toContain("application/json")
}); });
it('correct distance input should return 200', async () => { it('correct distance input should return 200', async () => {
const res = await axios.post('http://localhost:4010/api/tracks', { const res = await axios.post(base + '/api/tracks', {
"name": "string", "name": "string",
"distance": 400 "distance": 400
}); });
@ -18,7 +19,7 @@ describe('GET /api/tracks', () => {
// --------------- // ---------------
describe('POST /api/tracks', () => { describe('POST /api/tracks', () => {
it('illegal distance input should return 400', async () => { it('illegal distance input should return 400', async () => {
const res = await axios.post('http://localhost:4010/api/tracks', { const res = await axios.post(base + '/api/tracks', {
"name": "string", "name": "string",
"distance": -1 "distance": -1
}, { validateStatus: undefined }); }, { validateStatus: undefined });
@ -26,7 +27,7 @@ describe('POST /api/tracks', () => {
expect(res.headers['content-type']).toContain("application/json") expect(res.headers['content-type']).toContain("application/json")
}); });
it('correct distance input should return 200', async () => { it('correct distance input should return 200', async () => {
const res = await axios.post('http://localhost:4010/api/tracks', { const res = await axios.post(base + '/api/tracks', {
"name": "string", "name": "string",
"distance": 400 "distance": 400
}); });
@ -37,7 +38,7 @@ describe('POST /api/tracks', () => {
// --------------- // ---------------
describe('adding + getting tracks', () => { describe('adding + getting tracks', () => {
it('correct distance input should return 200', async () => { it('correct distance input should return 200', async () => {
const res = await axios.post('http://localhost:4010/api/tracks', { const res = await axios.post(base + '/api/tracks', {
"name": "string", "name": "string",
"distance": 1000 "distance": 1000
}); });
@ -45,7 +46,7 @@ describe('adding + getting tracks', () => {
expect(res.headers['content-type']).toContain("application/json") expect(res.headers['content-type']).toContain("application/json")
}); });
it('check if track was added', async () => { it('check if track was added', async () => {
const res = await axios.get('http://localhost:4010/api/tracks'); const res = await axios.get(base + '/api/tracks');
expect(res.status).toEqual(200); expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json") expect(res.headers['content-type']).toContain("application/json")
let added_track = res.data[res.data.length - 1] let added_track = res.data[res.data.length - 1]
@ -60,7 +61,7 @@ describe('adding + getting tracks', () => {
describe('adding + getting + updating', () => { describe('adding + getting + updating', () => {
let added_track_id let added_track_id
it('correct distance input should return 200', async () => { it('correct distance input should return 200', async () => {
const res = await axios.post('http://localhost:4010/api/tracks', { const res = await axios.post(base + '/api/tracks', {
"name": "string", "name": "string",
"distance": 1500 "distance": 1500
}); });
@ -68,7 +69,7 @@ describe('adding + getting + updating', () => {
expect(res.headers['content-type']).toContain("application/json") expect(res.headers['content-type']).toContain("application/json")
}); });
it('get should return 200', async () => { it('get should return 200', async () => {
const res1 = await axios.get('http://localhost:4010/api/tracks'); const res1 = await axios.get(base + '/api/tracks');
expect(res1.status).toEqual(200); expect(res1.status).toEqual(200);
expect(res1.headers['content-type']).toContain("application/json") expect(res1.headers['content-type']).toContain("application/json")
let added_track = res1.data[res1.data.length - 1] let added_track = res1.data[res1.data.length - 1]
@ -80,7 +81,7 @@ describe('adding + getting + updating', () => {
}) })
}) })
it('get should return 200', async () => { it('get should return 200', async () => {
const res2 = await axios.put('http://localhost:4010/api/tracks/' + added_track_id, { const res2 = await axios.put(base + '/api/tracks/' + added_track_id, {
"id": added_track_id, "id": added_track_id,
"name": "apitrack", "name": "apitrack",
"distance": 5100 "distance": 5100
@ -89,7 +90,7 @@ describe('adding + getting + updating', () => {
expect(res2.headers['content-type']).toContain("application/json") expect(res2.headers['content-type']).toContain("application/json")
}) })
it('get should return 200', async () => { it('get should return 200', async () => {
const res3 = await axios.get('http://localhost:4010/api/tracks'); const res3 = await axios.get(base + '/api/tracks');
expect(res3.status).toEqual(200); expect(res3.status).toEqual(200);
expect(res3.headers['content-type']).toContain("application/json") expect(res3.headers['content-type']).toContain("application/json")
let added_track2 = res3.data[res3.data.length - 1] let added_track2 = res3.data[res3.data.length - 1]