Compare commits

..

58 Commits

Author SHA1 Message Date
5eabc1fe18 Merge branch 'dev' into feature/19-user_seeding
# Conflicts:
#	ormconfig.ts
#	package.json
2020-12-11 19:32:53 +01:00
57f6775140 Merge pull request 'feature/17-automated_tests' (#21) from feature/17-automated_tests into dev
Reviewed-on: #21
closes: #17
2020-12-10 19:36:07 +00:00
5a27689e80 new get test
ref #17
2020-12-10 20:33:36 +01:00
d295100a48 refactoring: cleaned up the names
ref #17
2020-12-10 20:32:57 +01:00
6eee80d357 Runner update tests now run clean
ref #17
2020-12-10 20:08:20 +01:00
cada962e5a Merge branch 'dev' into feature/17-automated_tests
# Conflicts:
#	src/controllers/RunnerTeamController.ts
2020-12-10 20:05:52 +01:00
92dee666ee Added team update test
ref #17
2020-12-10 19:53:19 +01:00
6e12b014e7 future proved the group update failture
ref #17
2020-12-10 19:48:50 +01:00
c20f01f485 Added runner update tests 2020-12-10 19:48:03 +01:00
eda8abb668 Merge branch 'dev' into feature/17-automated_tests
# Conflicts:
#	src/controllers/RunnerController.ts
#	src/models/actions/CreateParticipant.ts
2020-12-10 19:37:52 +01:00
068e5bd72b Merge branch 'dev' into feature/17-automated_tests
# Conflicts:
#	src/models/responses/ResponseEmpty.ts
2020-12-10 18:51:50 +01:00
64725d9e7a Added basic update test 2020-12-10 18:39:40 +01:00
d2e0384f3c Added runner deletion tests
ref #17
2020-12-10 18:30:26 +01:00
e223c060d4 Fixed runner get test
ref #17
2020-12-10 18:30:09 +01:00
49ac7be367 Moded runner get tests to a new file and added more of them
ref #17
2020-12-10 17:59:12 +01:00
9df86953cf Merge branch 'dev' into feature/17-automated_tests
# Conflicts:
#	src/app.ts
#	src/controllers/RunnerController.ts
#	src/controllers/RunnerOrganisationController.ts
#	src/controllers/RunnerTeamController.ts
#	src/models/actions/CreateParticipant.ts
2020-12-10 17:45:23 +01:00
47862f2e1d Added runner creation tests
ref #17
2020-12-10 17:41:15 +01:00
d0d050e6c6 Added basic runner get tests
ref #17
2020-12-10 16:18:23 +01:00
e2feffa1c5 Merge branch 'dev' into feature/17-automated_tests 2020-12-10 16:13:40 +01:00
ff6a4eaca1 Removed sqlite jurnal (however it managed to end up here) 2020-12-10 16:13:05 +01:00
32a92b1ad7 Added org deletion tests (orgs that still have teams)
ref #17
2020-12-10 16:10:35 +01:00
105efdd454 Added team update tests
ref #17
2020-12-09 20:08:01 +01:00
6e316a7533 Cleanup
ref #17
2020-12-09 19:57:02 +01:00
71e5be2ba4 added non-existant deletion test for teams
ref #17
2020-12-09 19:55:36 +01:00
80ef7e8c3a Adjustes responsecode 2020-12-09 19:43:51 +01:00
d2898ff60f Merge branch 'dev' into feature/17-automated_tests 2020-12-09 19:42:51 +01:00
6396fffc04 Added test for non-existant deletion
ref #17
2020-12-09 19:20:33 +01:00
5845a91f15 Fixed typos 2020-12-09 19:20:19 +01:00
f4abbfcee4 Added test for getting an non-existant team 2020-12-09 19:16:10 +01:00
c3258b9304 Added team delete test 2020-12-09 19:15:54 +01:00
ff96ba23d7 Merge branch 'dev' into feature/17-automated_tests 2020-12-09 19:02:29 +01:00
00215a81a7 Merge branch 'dev' into feature/17-automated_tests 2020-12-09 18:54:06 +01:00
b4b52717fc Added more negative tests for the teams
ref #17
2020-12-09 18:47:15 +01:00
862834c877 Added first team creation tests 2020-12-09 18:42:08 +01:00
76065538c9 Renamed b/c runner teams also need dedicated tests
ref #17
2020-12-09 18:14:29 +01:00
99209981d9 Merge branch 'dev' into feature/17-automated_tests 2020-12-09 18:13:12 +01:00
13f96e3190 Added delete test
ref #17
2020-12-09 18:08:45 +01:00
4e3b038dec Added bad test to the put 2020-12-09 17:56:37 +01:00
42d3f9cb98 Merge branch 'dev' into feature/17-automated_tests 2020-12-09 17:52:22 +01:00
0a0050368f Added put tests for runner orgs 2020-12-09 17:52:04 +01:00
6da7c23c04 Renamed to better fit the content 2020-12-09 16:28:18 +01:00
db5feb00cc Added more basic tests for the runner orgs
ref #17
2020-12-09 16:27:01 +01:00
381ce9c828 Merge branch 'dev' into feature/17-automated_tests 2020-12-09 16:11:46 +01:00
34fa94ea4f First tests for orgs
ref #17
2020-12-09 16:10:17 +01:00
39cefbc593 ⚙ use new config loader
ref #18 ,ref #17
2020-12-06 10:48:25 +01:00
2cdc91ec83 Merge branch 'feature/18-exported-env-vars' into feature/17-automated_tests 2020-12-06 10:45:15 +01:00
1748fd4034 Merge branch 'feature/17-automated_tests' of https://git.odit.services/lfk/backend into feature/17-automated_tests 2020-12-05 20:45:38 +01:00
34567f24c3 test:watch script 2020-12-05 20:45:22 +01:00
def7ca3eb2 🧪tracks.spec.ts - move to baseurl
ref #17
2020-12-05 20:45:06 +01:00
4dd0217c93 Merge branch 'feature/17-automated_tests' of git.odit.services:lfk/backend into feature/17-automated_tests 2020-12-05 20:33:41 +01:00
a3e8973004 Merge branch 'dev' into feature/17-automated_tests 2020-12-05 20:33:31 +01:00
29acabfca3 🧪tracks.spec.ts - adding + getting + updating tracks
ref #17
2020-12-05 20:32:38 +01:00
4ff6f8c540 ⚙ nodemon config - ignore tests
ref #17
2020-12-05 20:32:15 +01:00
a671bf8bcb 🚧 tracks.spec.ts - sample track adding + getting
ref #17
2020-12-05 20:19:41 +01:00
15e3d04215 🚧tracks.spec.ts - check if track was added
ref #17
2020-12-05 20:17:42 +01:00
07e03ff04e basic track testing
ref #17
2020-12-05 20:11:52 +01:00
431fd608a6 sample json validation
ref #17
2020-12-05 18:52:36 +01:00
8ae5cea631 basic jest + typescript support
ref #17
2020-12-05 18:49:09 +01:00
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
})
});
});