91 lines
4.1 KiB
TypeScript
91 lines
4.1 KiB
TypeScript
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/runners/distance w/o auth should return 200', () => {
|
|
it('get with invalid token should return 401', async () => {
|
|
const res = await axios.get(base + '/api/stats/runners/distance', {
|
|
headers: { "authorization": "Bearer 123123123123123123" },
|
|
validateStatus: undefined
|
|
});
|
|
expect(res.status).toEqual(401);
|
|
});
|
|
});
|
|
// ---------------
|
|
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");
|
|
});
|
|
});
|
|
// ---------------
|
|
describe('GET /api/stats/runners/* should return 200', () => {
|
|
it('get by distance w/ auth should return 200', async () => {
|
|
const res = await axios.get(base + '/api/stats/runners/distance', axios_config_stats);
|
|
expect(res.status).toEqual(200);
|
|
expect(res.headers['content-type']).toContain("application/json");
|
|
});
|
|
it('get by donations w/ auth should return 200', async () => {
|
|
const res = await axios.get(base + '/api/stats/runners/donations', axios_config_stats);
|
|
expect(res.status).toEqual(200);
|
|
expect(res.headers['content-type']).toContain("application/json");
|
|
});
|
|
it('get by laptime w/ auth should return 200', async () => {
|
|
const res = await axios.get(base + '/api/stats/runners/laptime', axios_config_stats);
|
|
expect(res.status).toEqual(200);
|
|
expect(res.headers['content-type']).toContain("application/json");
|
|
});
|
|
});
|
|
// ---------------
|
|
describe('GET /api/stats/teams/* should return 200', () => {
|
|
it('get by distance w/ auth should return 200', async () => {
|
|
const res = await axios.get(base + '/api/stats/teams/distance', axios_config_stats);
|
|
console.log("################# Teams by distance #################");
|
|
console.log(res.data);
|
|
expect(res.status).toEqual(200);
|
|
expect(res.headers['content-type']).toContain("application/json");
|
|
});
|
|
it('get by donations w/ auth should return 200', async () => {
|
|
const res = await axios.get(base + '/api/stats/teams/donations', axios_config_stats);
|
|
expect(res.status).toEqual(200);
|
|
expect(res.headers['content-type']).toContain("application/json");
|
|
});
|
|
});
|
|
// ---------------
|
|
describe('GET /api/stats/organizations/* should return 200', () => {
|
|
it('get by distance w/ auth should return 200', async () => {
|
|
const res = await axios.get(base + '/api/stats/organizations/distance', axios_config_stats);
|
|
expect(res.status).toEqual(200);
|
|
expect(res.headers['content-type']).toContain("application/json");
|
|
});
|
|
it('get by donations w/ auth should return 200', async () => {
|
|
const res = await axios.get(base + '/api/stats/organizations/donations', axios_config_stats);
|
|
expect(res.status).toEqual(200);
|
|
expect(res.headers['content-type']).toContain("application/json");
|
|
});
|
|
}); |