Added auth to all tests
Some checks failed
continuous-integration/drone/pr Build is failing

ref #6
This commit is contained in:
2020-12-18 22:11:41 +01:00
parent d742ccd581
commit b19f18ada1
14 changed files with 259 additions and 94 deletions

View File

@@ -1,10 +1,21 @@
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('GET /api/runners', () => {
it('basic get should return 200', async () => {
const res = await axios.get(base + '/api/runners');
const res = await axios.get(base + '/api/runners', axios_config);
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json")
});
@@ -12,7 +23,7 @@ describe('GET /api/runners', () => {
// ---------------
describe('GET /api/runners/0', () => {
it('basic get should return 404', async () => {
const res = await axios.get(base + '/api/runners/0', { validateStatus: undefined });
const res = await axios.get(base + '/api/runners/0', axios_config);
expect(res.status).toEqual(404);
expect(res.headers['content-type']).toContain("application/json")
});
@@ -24,7 +35,7 @@ describe('GET /api/runners after adding', () => {
it('creating a new org with just a name should return 200', async () => {
const res1 = await axios.post(base + '/api/organisations', {
"name": "test123"
});
}, axios_config);
let added_org = res1.data
added_org_id = added_org.id;
expect(res1.status).toEqual(200);
@@ -35,20 +46,20 @@ describe('GET /api/runners after adding', () => {
"firstname": "first",
"lastname": "last",
"group": added_org_id
}, { validateStatus: undefined });
}, axios_config);
added_runner = res2.data;
expect(res2.status).toEqual(200);
expect(res2.headers['content-type']).toContain("application/json")
});
it('explicit get should return 200', async () => {
const res3 = await axios.get(base + '/api/runners/' + added_runner.id, { validateStatus: undefined });
const res3 = await axios.get(base + '/api/runners/' + added_runner.id, axios_config);
expect(res3.status).toEqual(200);
expect(res3.headers['content-type']).toContain("application/json")
let gotten_runner = res3.data
expect(gotten_runner).toEqual(added_runner);
});
it('get from all runners should return 200', async () => {
const res4 = await axios.get(base + '/api/runners/', { validateStatus: undefined });
const res4 = await axios.get(base + '/api/runners/', axios_config);
expect(res4.status).toEqual(200);
expect(res4.headers['content-type']).toContain("application/json")
let gotten_runners = res4.data