Added first selfservice test
continuous-integration/drone/pr Build is failing
Details
continuous-integration/drone/pr Build is failing
Details
ref #190
This commit is contained in:
parent
257f320ee3
commit
057ae0d797
|
@ -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");
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue