Added track add tests

ref #71
This commit is contained in:
Nicolai Ort 2021-01-03 17:52:16 +01:00
parent 9f103d8df1
commit 1a0573e0d0
1 changed files with 90 additions and 0 deletions

View File

@ -0,0 +1,90 @@
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('POST /api/tracks illegally', () => {
it('no distance input should return 400', async () => {
const res = await axios.post(base + '/api/tracks', {
"name": "string",
}, axios_config);
expect(res.status).toEqual(400);
expect(res.headers['content-type']).toContain("application/json")
});
it('illegal distance input should return 400', async () => {
const res = await axios.post(base + '/api/tracks', {
"name": "string",
"distance": -1
}, axios_config);
expect(res.status).toEqual(400);
expect(res.headers['content-type']).toContain("application/json")
});
it('negative minimum lap time input should return 406', async () => {
const res = await axios.post(base + '/api/tracks', {
"name": "string",
"distance": 200,
"minimumLapTime": -1
}, axios_config);
expect(res.status).toEqual(406);
expect(res.headers['content-type']).toContain("application/json")
});
});
// ---------------
describe('POST /api/tracks successfully', () => {
it('creating a track with the minimum amount of parameters should return 200', async () => {
const res = await axios.post(base + '/api/tracks', {
"name": "testtrack",
"distance": 200,
}, axios_config);
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json");
delete res.data.id;
expect(res.data).toEqual({
"name": "string",
"distance": 200,
"minimumLapTime": null
})
});
it('creating a track with all parameters (optional set to null) should return 200', async () => {
const res = await axios.post(base + '/api/tracks', {
"name": "testtrack",
"distance": 200,
"minimumLapTime": null
}, axios_config);
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json");
delete res.data.id;
expect(res.data).toEqual({
"name": "string",
"distance": 200,
"minimumLapTime": null
})
});
it('creating a track with all parameters should return 200', async () => {
const res = await axios.post(base + '/api/tracks', {
"name": "testtrack",
"distance": 200,
"minimumLapTime": 123
}, axios_config);
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json");
delete res.data.id;
expect(res.data).toEqual({
"name": "string",
"distance": 200,
"minimumLapTime": 123
})
});
});