Merge branch 'dev' into feature/19-user_seeding

# Conflicts:
#	ormconfig.ts
#	package.json
This commit is contained in:
Nicolai Ort 2020-12-11 19:32:53 +01:00
commit 5eabc1fe18
27 changed files with 1991 additions and 977 deletions

4
jest.config.js Normal file
View File

@ -0,0 +1,4 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};

View File

@ -0,0 +1,23 @@
import axios from 'axios';
import { config } from '../config';
const base = "http://localhost:" + config.internal_port
describe('GET /api/openapi.json', () => {
it('is http 200', async () => {
const res = await axios.get(base + '/api/openapi.json');
expect(res.status).toEqual(200);
});
});
describe('GET /', () => {
it('is http 404', async () => {
const res = await axios.get(base + '/', { validateStatus: undefined });
expect(res.status).toEqual(404);
});
});
describe('GET /api/teams', () => {
it('is http 200 && is json', async () => {
const res = await axios.get(base + '/api/teams', { validateStatus: undefined });
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json")
});
});

View File

@ -0,0 +1,78 @@
import axios from 'axios';
import { config } from '../../config';
const base = "http://localhost:" + config.internal_port
describe('GET /api/organisations', () => {
it('basic get should return 200', async () => {
const res = await axios.get(base + '/api/organisations');
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json")
});
});
// ---------------
describe('POST /api/organisations', () => {
it('creating a new org with just a name should return 200', async () => {
const res = await axios.post(base + '/api/organisations', {
"name": "test123"
});
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json")
});
it('creating a new org with without a name should return 400', async () => {
const res = await axios.post(base + '/api/organisations', {
"name": null
}, { validateStatus: undefined });
expect(res.status).toEqual(400);
expect(res.headers['content-type']).toContain("application/json")
});
});
// ---------------
describe('adding + getting from all orgs', () => {
it('creating a new org with just a name should return 200', async () => {
const res = await axios.post(base + '/api/organisations', {
"name": "test123"
});
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json")
});
it('check if org was added', async () => {
const res = await axios.get(base + '/api/organisations');
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json")
let added_org = res.data[res.data.length - 1]
delete added_org.id
expect(added_org).toEqual({
"name": "test123",
"contact": null,
"address": null,
"teams": []
})
});
});
// ---------------
describe('adding + getting explicitly', () => {
let added_org_id
it('creating a new org with just a name should return 200', async () => {
const res1 = await axios.post(base + '/api/organisations', {
"name": "test123"
});
let added_org = res1.data
added_org_id = added_org.id;
expect(res1.status).toEqual(200);
expect(res1.headers['content-type']).toContain("application/json")
});
it('check if org was added', async () => {
const res2 = await axios.get(base + '/api/organisations/' + added_org_id);
expect(res2.status).toEqual(200);
expect(res2.headers['content-type']).toContain("application/json")
let added_org2 = res2.data
added_org_id = added_org2.id;
delete added_org2.id
expect(added_org2).toEqual({
"name": "test123",
"contact": null,
"address": null,
"teams": []
})
});
});

View File

@ -0,0 +1,120 @@
import axios from 'axios';
import { config } from '../../config';
const base = "http://localhost:" + config.internal_port
// ---------------
describe('adding + deletion (non-existant)', () => {
it('delete', async () => {
const res2 = await axios.delete(base + '/api/organisations/0', { validateStatus: undefined });
expect(res2.status).toEqual(204);
});
});
// ---------------
describe('adding + deletion (successfull)', () => {
let added_org_id
let added_org
it('creating a new org with just a name should return 200', async () => {
const res1 = await axios.post(base + '/api/organisations', {
"name": "test123"
});
added_org = res1.data
added_org_id = added_org.id;
expect(res1.status).toEqual(200);
expect(res1.headers['content-type']).toContain("application/json")
});
it('delete', async () => {
const res2 = await axios.delete(base + '/api/organisations/' + added_org_id);
expect(res2.status).toEqual(200);
expect(res2.headers['content-type']).toContain("application/json")
let added_org2 = res2.data
added_org_id = added_org2.id;
delete added_org2.id
expect(added_org2).toEqual({
"name": "test123",
"contact": null,
"address": null,
"teams": []
});
});
it('check if org really was deleted', async () => {
const res3 = await axios.get(base + '/api/organisations/' + added_org_id, { validateStatus: undefined });
expect(res3.status).toEqual(404);
expect(res3.headers['content-type']).toContain("application/json")
});
});
// ---------------
describe('adding + deletion with teams still existing (without force)', () => {
let added_org;
let added_org_id;
let added_team;
let added_team_id
it('creating a new org with just a name should return 200', async () => {
const res1 = await axios.post(base + '/api/organisations', {
"name": "test123"
});
added_org = res1.data;
added_org_id = added_org.id;
expect(res1.status).toEqual(200);
expect(res1.headers['content-type']).toContain("application/json")
});
it('creating a new team with a valid org should return 200', async () => {
const res2 = await axios.post(base + '/api/teams', {
"name": "test123",
"parentGroup": added_org_id
});
added_team = res2.data;
added_team_id = added_team.id;
expect(res2.status).toEqual(200);
expect(res2.headers['content-type']).toContain("application/json")
});
it('delete org - this should fail with a 406', async () => {
const res2 = await axios.delete(base + '/api/organisations/' + added_org_id, { validateStatus: undefined });
expect(res2.status).toEqual(406);
expect(res2.headers['content-type']).toContain("application/json")
});
});
// ---------------
describe('adding + deletion with teams still existing (with force)', () => {
let added_org;
let added_org_id;
let added_team;
let added_team_id
it('creating a new org with just a name should return 200', async () => {
const res1 = await axios.post(base + '/api/organisations', {
"name": "test123"
});
added_org = res1.data;
added_org_id = added_org.id;
expect(res1.status).toEqual(200);
expect(res1.headers['content-type']).toContain("application/json")
});
it('creating a new team with a valid org should return 200', async () => {
const res2 = await axios.post(base + '/api/teams', {
"name": "test123",
"parentGroup": added_org_id
});
added_team = res2.data;
added_team_id = added_team.id;
expect(res2.status).toEqual(200);
expect(res2.headers['content-type']).toContain("application/json")
});
it('delete', async () => {
const res2 = await axios.delete(base + '/api/organisations/' + added_org_id + '?force=true');
expect(res2.status).toEqual(200);
expect(res2.headers['content-type']).toContain("application/json")
let added_org2 = res2.data
added_org_id = added_org2.id;
delete added_org2.id;
delete added_org2.teams;
expect(added_org2).toEqual({
"name": "test123",
"contact": null,
"address": null
});
});
it('check if org really was deleted', async () => {
const res3 = await axios.get(base + '/api/organisations/' + added_org_id, { validateStatus: undefined });
expect(res3.status).toEqual(404);
expect(res3.headers['content-type']).toContain("application/json")
});
});

View File

@ -0,0 +1,19 @@
import axios from 'axios';
import { config } from '../../config';
const base = "http://localhost:" + config.internal_port
describe('GET /api/organisations', () => {
it('basic get should return 200', async () => {
const res = await axios.get(base + '/api/organisations');
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json")
});
});
// ---------------
describe('GET /api/organisations/0', () => {
it('basic get should return 404', async () => {
const res = await axios.get(base + '/api/runners/0', { validateStatus: undefined });
expect(res.status).toEqual(404);
expect(res.headers['content-type']).toContain("application/json")
});
});

View File

@ -0,0 +1,61 @@
import axios from 'axios';
import { config } from '../../config';
const base = "http://localhost:" + config.internal_port
// ---------------
describe('adding + updating name', () => {
let added_org_id
let added_org
it('creating a new org with just a name should return 200', async () => {
const res1 = await axios.post(base + '/api/organisations', {
"name": "test123"
});
added_org = res1.data
added_org_id = added_org.id;
expect(res1.status).toEqual(200);
expect(res1.headers['content-type']).toContain("application/json")
});
it('update org', async () => {
const res2 = await axios.put(base + '/api/organisations/' + added_org_id, {
"id": added_org_id,
"name": "testlelele",
"contact": null,
"address": null,
});
expect(res2.status).toEqual(200);
expect(res2.headers['content-type']).toContain("application/json")
let added_org2 = res2.data
added_org_id = added_org2.id;
delete added_org2.id
expect(added_org2).toEqual({
"name": "testlelele",
"contact": null,
"address": null,
"teams": []
})
});
});
// ---------------
describe('adding + try updating id (should return 406)', () => {
let added_org_id
let added_org
it('creating a new org with just a name should return 200', async () => {
const res1 = await axios.post(base + '/api/organisations', {
"name": "test123"
});
added_org = res1.data
added_org_id = added_org.id;
expect(res1.status).toEqual(200);
expect(res1.headers['content-type']).toContain("application/json")
});
it('update org', async () => {
const res2 = await axios.put(base + '/api/organisations/' + added_org_id, {
"id": added_org_id + 1,
"name": "testlelele",
"contact": null,
"address": null,
}, { validateStatus: undefined });
expect(res2.status).toEqual(406);
expect(res2.headers['content-type']).toContain("application/json")
});
});

View File

@ -0,0 +1,65 @@
import axios from 'axios';
import { config } from '../../config';
const base = "http://localhost:" + config.internal_port
describe('GET /api/teams', () => {
it('basic get should return 200', async () => {
const res = await axios.get(base + '/api/teams');
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json")
});
});
// ---------------
describe('GET /api/teams/0', () => {
it('basic get should return 404', async () => {
const res = await axios.get(base + '/api/teams/0', { validateStatus: undefined });
expect(res.status).toEqual(404);
expect(res.headers['content-type']).toContain("application/json")
});
});
// ---------------
describe('POST /api/teams with errors', () => {
it('creating a new team without a name should return 400', async () => {
const res1 = await axios.post(base + '/api/teams', {
"name": null
}, { validateStatus: undefined });
expect(res1.status).toEqual(400);
expect(res1.headers['content-type']).toContain("application/json")
});
it('creating a new team without a org should return 400', async () => {
const res2 = await axios.post(base + '/api/teams', {
"name": "test_team"
}, { validateStatus: undefined });
expect(res2.status).toEqual(400);
expect(res2.headers['content-type']).toContain("application/json")
});
it('creating a new team without a valid org should return 404', async () => {
const res3 = await axios.post(base + '/api/teams', {
"name": "test_team",
"parentGroup": -1
}, { validateStatus: undefined });
expect(res3.status).toEqual(404);
expect(res3.headers['content-type']).toContain("application/json")
});
});
// ---------------
describe('POST /api/teams working', () => {
let added_org_id;
it('creating a new org with just a name should return 200', async () => {
const res1 = await axios.post(base + '/api/organisations', {
"name": "test123"
});
let added_org = res1.data
added_org_id = added_org.id;
expect(res1.status).toEqual(200);
expect(res1.headers['content-type']).toContain("application/json")
});
it('creating a new team with a parent org should return 200', async () => {
const res2 = await axios.post(base + '/api/teams', {
"name": "test_team",
"parentGroup": added_org_id
});
expect(res2.status).toEqual(200);
expect(res2.headers['content-type']).toContain("application/json")
});
});

View File

@ -0,0 +1,54 @@
import axios from 'axios';
import { config } from '../../config';
const base = "http://localhost:" + config.internal_port
// ---------------
describe('adding org', () => {
let added_org;
let added_org_id;
let added_team;
let added_team_id
it('creating a new org with just a name should return 200', async () => {
const res1 = await axios.post(base + '/api/organisations', {
"name": "test123"
});
added_org = res1.data;
added_org_id = added_org.id;
expect(res1.status).toEqual(200);
expect(res1.headers['content-type']).toContain("application/json")
});
it('creating a new team with a valid org should return 200', async () => {
const res2 = await axios.post(base + '/api/teams', {
"name": "test123",
"parentGroup": added_org_id
});
added_team = res2.data;
added_team_id = added_team.id;
expect(res2.status).toEqual(200);
expect(res2.headers['content-type']).toContain("application/json")
});
it('delete team', async () => {
const res2 = await axios.delete(base + '/api/teams/' + added_team_id);
expect(res2.status).toEqual(200);
expect(res2.headers['content-type']).toContain("application/json")
let deleted_team = res2.data
delete deleted_team.id;
delete deleted_team.parentGroup;
expect(deleted_team).toEqual({
"name": "test123",
"contact": null
});
});
it('check if team really was deleted', async () => {
const res3 = await axios.get(base + '/api/teams/' + added_team_id, { validateStatus: undefined });
expect(res3.status).toEqual(404);
expect(res3.headers['content-type']).toContain("application/json")
});
});
// ---------------
describe('adding + deletion (non-existant)', () => {
it('delete', async () => {
const res2 = await axios.delete(base + '/api/teams/0', { validateStatus: undefined });
expect(res2.status).toEqual(204);
});
});

View File

@ -0,0 +1,19 @@
import axios from 'axios';
import { config } from '../../config';
const base = "http://localhost:" + config.internal_port
describe('GET /api/teams', () => {
it('basic get should return 200', async () => {
const res = await axios.get(base + '/api/teams');
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json")
});
});
// ---------------
describe('GET /api/teams/0', () => {
it('basic get should return 404', async () => {
const res = await axios.get(base + '/api/teams/0', { validateStatus: undefined });
expect(res.status).toEqual(404);
expect(res.headers['content-type']).toContain("application/json")
});
});

View File

@ -0,0 +1,119 @@
import axios from 'axios';
import { config } from '../../config';
const base = "http://localhost:" + config.internal_port
// ---------------
describe('adding + updating name', () => {
let added_org;
let added_org_id;
let added_team;
let added_team_id
it('creating a new org with just a name should return 200', async () => {
const res1 = await axios.post(base + '/api/organisations', {
"name": "test123"
});
added_org = res1.data;
added_org_id = added_org.id;
expect(res1.status).toEqual(200);
expect(res1.headers['content-type']).toContain("application/json")
});
it('creating a new team with a valid org should return 200', async () => {
const res2 = await axios.post(base + '/api/teams', {
"name": "test123",
"parentGroup": added_org_id
});
added_team = res2.data;
added_team_id = added_team.id;
expect(res2.status).toEqual(200);
expect(res2.headers['content-type']).toContain("application/json")
});
it('update name', async () => {
const res3 = await axios.put(base + '/api/teams/' + added_team_id, {
"id": added_team_id,
"name": "testlelele",
"contact": null,
"parentGroup": added_org
});
expect(res3.status).toEqual(200);
expect(res3.headers['content-type']).toContain("application/json")
let updated_team = res3.data;
added_team.name = "testlelele";
expect(updated_team).toEqual(added_team)
});
});
// ---------------
describe('adding + try updating id (should return 406)', () => {
let added_org;
let added_org_id;
let added_team;
let added_team_id
it('creating a new org with just a name should return 200', async () => {
const res1 = await axios.post(base + '/api/organisations', {
"name": "test123"
});
added_org = res1.data;
added_org_id = added_org.id;
expect(res1.status).toEqual(200);
expect(res1.headers['content-type']).toContain("application/json")
});
it('creating a new team with a valid org should return 200', async () => {
const res2 = await axios.post(base + '/api/teams', {
"name": "test123",
"parentGroup": added_org_id
});
added_team = res2.data;
added_team_id = added_team.id;
expect(res2.status).toEqual(200);
expect(res2.headers['content-type']).toContain("application/json")
});
it('update team', async () => {
added_team.id = added_team.id + 1;
const res3 = await axios.put(base + '/api/teams/' + added_team_id, added_team, { validateStatus: undefined });
expect(res3.status).toEqual(406);
expect(res3.headers['content-type']).toContain("application/json")
});
});
// ---------------
describe('add+update parent org (valid)', () => {
let added_org;
let added_org2;
let added_team;
let added_team_id
it('creating a new org with just a name should return 200', async () => {
const res1 = await axios.post(base + '/api/organisations', {
"name": "test123"
});
added_org = res1.data;
expect(res1.status).toEqual(200);
expect(res1.headers['content-type']).toContain("application/json")
});
it('creating a new team with a valid org should return 200', async () => {
const res2 = await axios.post(base + '/api/teams', {
"name": "test123",
"parentGroup": added_org.id
});
added_team = res2.data;
added_team_id = added_team.id;
expect(res2.status).toEqual(200);
expect(res2.headers['content-type']).toContain("application/json")
});
it('creating a new org with just a name should return 200', async () => {
const res3 = await axios.post(base + '/api/organisations', {
"name": "test123"
});
added_org2 = res3.data;
expect(res3.status).toEqual(200);
expect(res3.headers['content-type']).toContain("application/json")
});
it('update team', async () => {
added_team.parentGroup = added_org2;
const res4 = await axios.put(base + '/api/teams/' + added_team_id, added_team, { validateStatus: undefined });
let updated_team = res4.data;
expect(res4.status).toEqual(200);
expect(res4.headers['content-type']).toContain("application/json")
delete added_org2.address;
delete added_org2.contact;
delete added_org2.teams;
expect(updated_team).toEqual(added_team)
});
});

View File

@ -0,0 +1,100 @@
import axios from 'axios';
import { config } from '../../config';
const base = "http://localhost:" + config.internal_port
describe('GET /api/runners', () => {
it('basic get should return 200', async () => {
const res = await axios.get(base + '/api/runners');
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json")
});
});
// ---------------
describe('GET /api/runners/0', () => {
it('basic get should return 404', async () => {
const res = await axios.get(base + '/api/runners/0', { validateStatus: undefined });
expect(res.status).toEqual(404);
expect(res.headers['content-type']).toContain("application/json")
});
});
// ---------------
describe('POST /api/runners with errors', () => {
it('creating a new runner without any parameters should return 400', async () => {
const res1 = await axios.post(base + '/api/runners', null, { validateStatus: undefined });
expect(res1.status).toEqual(400);
expect(res1.headers['content-type']).toContain("application/json")
});
it('creating a new runner without a group should return 400', async () => {
const res2 = await axios.post(base + '/api/runners', {
"firstname": "first",
"middlename": "middle",
"lastname": "last"
}, { validateStatus: undefined });
expect(res2.status).toEqual(400);
expect(res2.headers['content-type']).toContain("application/json")
});
it('creating a new runner with a invalid valid group should return 404', async () => {
const res2 = await axios.post(base + '/api/runners', {
"firstname": "first",
"middlename": "middle",
"lastname": "last",
"group": 0
}, { validateStatus: undefined });
expect(res2.status).toEqual(404);
expect(res2.headers['content-type']).toContain("application/json")
});
it('creating a new runner without a invalid phone number should return 400', async () => {
const res2 = await axios.post(base + '/api/runners', {
"firstname": "first",
"middlename": "middle",
"lastname": "last",
"phone": "123"
}, { validateStatus: undefined });
expect(res2.status).toEqual(400);
expect(res2.headers['content-type']).toContain("application/json")
});
it('creating a new runner without a invalid mail address should return 400', async () => {
const res2 = await axios.post(base + '/api/runners', {
"firstname": "first",
"middlename": "middle",
"lastname": "last",
"email ": "123"
}, { validateStatus: undefined });
expect(res2.status).toEqual(400);
expect(res2.headers['content-type']).toContain("application/json")
});
});
// ---------------
describe('POST /api/runners working', () => {
let added_org_id;
it('creating a new org with just a name should return 200', async () => {
const res1 = await axios.post(base + '/api/organisations', {
"name": "test123"
});
let added_org = res1.data
added_org_id = added_org.id;
expect(res1.status).toEqual(200);
expect(res1.headers['content-type']).toContain("application/json")
});
it('creating a new runner with only needed params should return 200', async () => {
const res2 = await axios.post(base + '/api/runners', {
"firstname": "first",
"lastname": "last",
"group": added_org_id
}, { validateStatus: undefined });
expect(res2.status).toEqual(200);
expect(res2.headers['content-type']).toContain("application/json")
});
it('creating a new runner with all non-relationship optional params should return 200', async () => {
const res3 = await axios.post(base + '/api/runners', {
"firstname": "first",
"middlename": "middle",
"lastname": "last",
"email": "test@example.com",
"phone": "+4909123123456789",
"group": added_org_id
}, { validateStatus: undefined });
expect(res3.status).toEqual(200);
expect(res3.headers['content-type']).toContain("application/json")
});
});

View File

@ -0,0 +1,46 @@
import axios from 'axios';
import { config } from '../../config';
const base = "http://localhost:" + config.internal_port
describe('adding + deletion (non-existant)', () => {
it('delete', async () => {
const res2 = await axios.delete(base + '/api/runners/0', { validateStatus: undefined });
expect(res2.status).toEqual(204);
});
});
// ---------------
describe('add+delete', () => {
let added_org_id;
let added_runner;
it('creating a new org with just a name should return 200', async () => {
const res1 = await axios.post(base + '/api/organisations', {
"name": "test123"
});
let added_org = res1.data
added_org_id = added_org.id;
expect(res1.status).toEqual(200);
expect(res1.headers['content-type']).toContain("application/json")
});
it('creating a new runner with only needed params should return 200', async () => {
const res2 = await axios.post(base + '/api/runners', {
"firstname": "first",
"lastname": "last",
"group": added_org_id
}, { validateStatus: undefined });
added_runner = res2.data;
expect(res2.status).toEqual(200);
expect(res2.headers['content-type']).toContain("application/json")
});
it('delete runner', async () => {
const res3 = await axios.delete(base + '/api/runners/' + added_runner.id);
expect(res3.status).toEqual(200);
expect(res3.headers['content-type']).toContain("application/json")
let deleted_runner = res3.data
expect(deleted_runner).toEqual(added_runner);
});
it('check if team really was deleted', async () => {
const res4 = await axios.get(base + '/api/runners/' + added_runner.id, { validateStatus: undefined });
expect(res4.status).toEqual(404);
expect(res4.headers['content-type']).toContain("application/json")
});
});

View File

@ -0,0 +1,57 @@
import axios from 'axios';
import { config } from '../../config';
const base = "http://localhost:" + config.internal_port
describe('GET /api/runners', () => {
it('basic get should return 200', async () => {
const res = await axios.get(base + '/api/runners');
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json")
});
});
// ---------------
describe('GET /api/runners/0', () => {
it('basic get should return 404', async () => {
const res = await axios.get(base + '/api/runners/0', { validateStatus: undefined });
expect(res.status).toEqual(404);
expect(res.headers['content-type']).toContain("application/json")
});
});
// ---------------
describe('GET /api/runners after adding', () => {
let added_org_id;
let added_runner;
it('creating a new org with just a name should return 200', async () => {
const res1 = await axios.post(base + '/api/organisations', {
"name": "test123"
});
let added_org = res1.data
added_org_id = added_org.id;
expect(res1.status).toEqual(200);
expect(res1.headers['content-type']).toContain("application/json")
});
it('creating a new runner with only needed params should return 200', async () => {
const res2 = await axios.post(base + '/api/runners', {
"firstname": "first",
"lastname": "last",
"group": added_org_id
}, { validateStatus: undefined });
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 });
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 });
expect(res4.status).toEqual(200);
expect(res4.headers['content-type']).toContain("application/json")
let gotten_runners = res4.data
expect(gotten_runners).toContainEqual(added_runner);
});
});

View File

@ -0,0 +1,145 @@
import axios from 'axios';
import { config } from '../../config';
const base = "http://localhost:" + config.internal_port
describe('Update runner name after adding', () => {
let added_org_id;
let added_runner;
let updated_runner;
it('creating a new org with just a name should return 200', async () => {
const res1 = await axios.post(base + '/api/organisations', {
"name": "test123"
});
let added_org = res1.data
added_org_id = added_org.id;
expect(res1.status).toEqual(200);
expect(res1.headers['content-type']).toContain("application/json")
});
it('creating a new runner with only needed params should return 200', async () => {
const res2 = await axios.post(base + '/api/runners', {
"firstname": "first",
"lastname": "last",
"group": added_org_id
}, { validateStatus: undefined });
added_runner = res2.data;
expect(res2.status).toEqual(200);
expect(res2.headers['content-type']).toContain("application/json")
});
it('valid update should return 200', async () => {
let runnercopy = added_runner
runnercopy.firstname = "second"
const res3 = await axios.put(base + '/api/runners/' + added_runner.id, runnercopy, { validateStatus: undefined });
expect(res3.status).toEqual(200);
expect(res3.headers['content-type']).toContain("application/json")
updated_runner = res3.data
expect(updated_runner).toEqual(runnercopy);
});
});
// ---------------
describe('Update runner group after adding', () => {
let added_org_id;
let added_org_2;
let added_runner;
let updated_runner;
it('creating a new org with just a name should return 200', async () => {
const res1 = await axios.post(base + '/api/organisations', {
"name": "test123"
});
let added_org = res1.data
added_org_id = added_org.id;
expect(res1.status).toEqual(200);
expect(res1.headers['content-type']).toContain("application/json")
});
it('creating a new runner with only needed params should return 200', async () => {
const res2 = await axios.post(base + '/api/runners', {
"firstname": "first",
"lastname": "last",
"group": added_org_id
}, { validateStatus: undefined });
added_runner = res2.data;
expect(res2.status).toEqual(200);
expect(res2.headers['content-type']).toContain("application/json")
});
it('creating a new org with just a name should return 200', async () => {
const res3 = await axios.post(base + '/api/organisations', {
"name": "test123"
});
added_org_2 = res3.data
delete added_org_2.address;
delete added_org_2.contact;
delete added_org_2.teams;
expect(res3.status).toEqual(200);
expect(res3.headers['content-type']).toContain("application/json")
});
it('valid update should return 200', async () => {
added_runner.group = added_org_2;
const res3 = await axios.put(base + '/api/runners/' + added_runner.id, added_runner, { validateStatus: undefined });
expect(res3.status).toEqual(200);
expect(res3.headers['content-type']).toContain("application/json")
updated_runner = res3.data
expect(updated_runner).toEqual(added_runner);
});
});
// ---------------
describe('Update runner id after adding(should fail)', () => {
let added_org_id;
let added_runner;
let added_runner_id;
it('creating a new org with just a name should return 200', async () => {
const res1 = await axios.post(base + '/api/organisations', {
"name": "test123"
});
let added_org = res1.data
added_org_id = added_org.id;
expect(res1.status).toEqual(200);
expect(res1.headers['content-type']).toContain("application/json")
});
it('creating a new runner with only needed params should return 200', async () => {
const res2 = await axios.post(base + '/api/runners', {
"firstname": "first",
"lastname": "last",
"group": added_org_id
}, { validateStatus: undefined });
added_runner = res2.data;
added_runner_id = added_runner.id;
expect(res2.status).toEqual(200);
expect(res2.headers['content-type']).toContain("application/json")
});
it('invalid update should return 406', async () => {
added_runner.id++;
const res3 = await axios.put(base + '/api/runners/' + added_runner_id, added_runner, { validateStatus: undefined });
expect(res3.status).toEqual(406);
expect(res3.headers['content-type']).toContain("application/json")
});
});
// ---------------
describe('Update runner group with invalid group after adding', () => {
let added_org;
let added_runner;
it('creating a new org with just a name should return 200', async () => {
const res1 = await axios.post(base + '/api/organisations', {
"name": "test123"
});
added_org = res1.data
expect(res1.status).toEqual(200);
expect(res1.headers['content-type']).toContain("application/json")
});
it('creating a new runner with only needed params should return 200', async () => {
const res2 = await axios.post(base + '/api/runners', {
"firstname": "first",
"lastname": "last",
"group": added_org.id
}, { validateStatus: undefined });
added_runner = res2.data;
expect(res2.status).toEqual(200);
expect(res2.headers['content-type']).toContain("application/json")
});
it('invalid update should return 404', async () => {
added_org.id = 0;
added_runner.group = added_org;
const res3 = await axios.put(base + '/api/runners/' + added_runner.id, added_runner, { validateStatus: undefined });
expect(res3.status).toEqual(404);
expect(res3.headers['content-type']).toContain("application/json")
});
});

104
src/tests/tracks.spec.ts Normal file
View File

@ -0,0 +1,104 @@
import axios from 'axios';
import { config } from '../config';
const base = "http://localhost:" + config.internal_port
describe('GET /api/tracks', () => {
it('basic get should return 200', async () => {
const res = await axios.get(base + '/api/tracks');
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json")
});
it('correct distance input should return 200', async () => {
const res = await axios.post(base + '/api/tracks', {
"name": "string",
"distance": 400
});
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json")
});
});
// ---------------
describe('POST /api/tracks', () => {
it('illegal distance input should return 400', async () => {
const res = await axios.post(base + '/api/tracks', {
"name": "string",
"distance": -1
}, { validateStatus: undefined });
expect(res.status).toEqual(400);
expect(res.headers['content-type']).toContain("application/json")
});
it('correct distance input should return 200', async () => {
const res = await axios.post(base + '/api/tracks', {
"name": "string",
"distance": 400
});
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json")
});
});
// ---------------
describe('adding + getting tracks', () => {
it('correct distance input should return 200', async () => {
const res = await axios.post(base + '/api/tracks', {
"name": "string",
"distance": 1000
});
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json")
});
it('check if track was added', async () => {
const res = await axios.get(base + '/api/tracks');
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json")
let added_track = res.data[res.data.length - 1]
delete added_track.id
expect(added_track).toEqual({
"name": "string",
"distance": 1000
})
});
});
// ---------------
describe('adding + getting + updating', () => {
let added_track_id
it('correct distance input should return 200', async () => {
const res = await axios.post(base + '/api/tracks', {
"name": "string",
"distance": 1500
});
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json")
});
it('get should return 200', async () => {
const res1 = await axios.get(base + '/api/tracks');
expect(res1.status).toEqual(200);
expect(res1.headers['content-type']).toContain("application/json")
let added_track = res1.data[res1.data.length - 1]
added_track_id = added_track.id
delete added_track.id
expect(added_track).toEqual({
"name": "string",
"distance": 1500
})
})
it('get should return 200', async () => {
const res2 = await axios.put(base + '/api/tracks/' + added_track_id, {
"id": added_track_id,
"name": "apitrack",
"distance": 5100
});
expect(res2.status).toEqual(200);
expect(res2.headers['content-type']).toContain("application/json")
})
it('get should return 200', async () => {
const res3 = await axios.get(base + '/api/tracks');
expect(res3.status).toEqual(200);
expect(res3.headers['content-type']).toContain("application/json")
let added_track2 = res3.data[res3.data.length - 1]
delete added_track2.id
expect(added_track2).toEqual({
"name": "apitrack",
"distance": 5100
})
});
});