Added first selfservice test
continuous-integration/drone/pr Build is failing Details

ref #190
This commit is contained in:
Nicolai Ort 2021-04-06 09:09:01 +02:00
parent 257f320ee3
commit 057ae0d797
1 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,46 @@
import axios from 'axios';
import { config } from '../../config';
const base = "http://localhost:" + config.internal_port
let axios_config_full;
let axios_config_stats;
beforeAll(async () => {
jest.setTimeout(20000);
const res = await axios.post(base + '/api/auth/login', { username: "demo", password: "demo" });
let access_token = res.data["access_token"];
axios_config_full = {
headers: { "authorization": "Bearer " + access_token },
validateStatus: undefined
};
const res2 = await axios.post(base + '/api/statsclients', { username: "demo", password: "demo" }, axios_config_full);
access_token = res2.data["key"];
axios_config_stats = {
headers: { "authorization": "Bearer " + access_token },
validateStatus: undefined
};
});
describe('GET /api/stats/distance w/o auth should return 200', () => {
it('get with invalid token should return 401', async () => {
const res = await axios.get(base + '/api/stats/distance', {
headers: { "authorization": "Bearer 123123123123123123" },
validateStatus: undefined
});
expect(res.status).toEqual(401);
expect(res.headers['content-type']).toContain("application/json");
});
});
// ---------------
describe('GET /api/stats should return 200', () => {
it('get w/o auth should return 200', async () => {
const res = await axios.get(base + '/api/stats', { validateStatus: undefined });
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json");
});
it('get w/ auth should return 200', async () => {
const res = await axios.get(base + '/api/stats', axios_config_stats);
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json");
});
});