Skip to content

Commit e5a9c6f

Browse files
Merge pull request #336 from PhlexPlexico/2.2.0.0
Version 2.2.0.0 Co-authored-by: Mostafa Mahran <mfamahran@gmail.com>
2 parents 0310d4e + 8d71d25 commit e5a9c6f

48 files changed

Lines changed: 3719 additions & 97 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ docker container run --name g5api \
8686
-e USEREDIS="true" \
8787
-e UPLOADDEMOS="" \
8888
-e LOCALLOGINS="" \
89+
-e QUEUETTL="" \
90+
-e SERVERPINGTO="" \
91+
-e SERVERPROVIDER="local"
8992
yourname\g5api:latest
9093
```
9194

__test__/dathost.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Unit tests for DatHost service (isDathostConfigured, releaseManagedServer with null).
3+
* Does not require app or database.
4+
*/
5+
import { isDathostConfigured, releaseManagedServer } from "../src/services/dathost.js";
6+
7+
describe("DatHost service", () => {
8+
it("isDathostConfigured returns false when user dathost is not configured", async () => {
9+
await expect(isDathostConfigured(1)).resolves.toBe(false);
10+
});
11+
12+
it("releaseManagedServer(null) resolves without throwing", async () => {
13+
await expect(releaseManagedServer(null)).resolves.toBeUndefined();
14+
});
15+
16+
it("releaseManagedServer(undefined) resolves without throwing", async () => {
17+
await expect(releaseManagedServer(undefined)).resolves.toBeUndefined();
18+
});
19+
});

__test__/gameservers.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,26 @@ describe("Test the game server routes.", () => {
1414
.expect("Content-Type", /json/)
1515
.expect(200);
1616
});
17+
it("Should return public server count via GET /servers/publiccount", () => {
18+
return request
19+
.get("/servers/publiccount")
20+
.expect("Content-Type", /json/)
21+
.expect(200)
22+
.expect((res) => {
23+
expect(res.body).toHaveProperty("servers");
24+
expect(typeof res.body.servers).toBe("number");
25+
});
26+
});
27+
it("Should return available servers via GET /servers/available", () => {
28+
return request
29+
.get("/servers/available")
30+
.expect("Content-Type", /json/)
31+
.expect(200)
32+
.expect((res) => {
33+
expect(res.body).toHaveProperty("servers");
34+
expect(Array.isArray(res.body.servers)).toBe(true);
35+
});
36+
});
1737
it("Should setup a new server with the given values.", () => {
1838
let newServerData = [
1939
{

__test__/matches.test.js

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import app from '../app.js';
33
const request = agent(app);
44

55
describe("Test the matches routes", () => {
6+
let defaultGameMatchId;
7+
let csgoGameMatchId;
8+
69
beforeAll(() => {
710
return request.get('/auth/steam/return')
811
.expect(302);
@@ -11,6 +14,45 @@ describe("Test the matches routes", () => {
1114
return request.get('/matches/')
1215
.expect(404);
1316
});
17+
it('Should reject use_dathost when server_id is also provided (400).', () => {
18+
return request
19+
.post("/matches/")
20+
.set("Content-Type", "application/json")
21+
.set("Accept", "application/json")
22+
.send([{
23+
use_dathost: true,
24+
server_id: 3,
25+
team1_id: 4,
26+
team2_id: 3,
27+
max_maps: 1,
28+
title: "Map {MAPNUMBER} of {MAXMAPS}",
29+
veto_mappool: "de_dust2 de_mirage",
30+
skip_veto: 0
31+
}])
32+
.expect(400)
33+
.expect((result) => {
34+
expect(result.body.message).toMatch(/use_dathost.*server_id/);
35+
});
36+
});
37+
it('Should reject use_dathost when DatHost is not configured (503).', () => {
38+
return request
39+
.post("/matches/")
40+
.set("Content-Type", "application/json")
41+
.set("Accept", "application/json")
42+
.send([{
43+
use_dathost: true,
44+
team1_id: 4,
45+
team2_id: 3,
46+
max_maps: 1,
47+
title: "Map {MAPNUMBER} of {MAXMAPS}",
48+
veto_mappool: "de_dust2 de_mirage",
49+
skip_veto: 0
50+
}])
51+
.expect(503)
52+
.expect((result) => {
53+
expect(result.body.message).toMatch(/DatHost|not configured/);
54+
});
55+
});
1456
it('Should create a single match that is ready to be played with teams.', () => {
1557
// Min required data.
1658
let newMatchData = [
@@ -208,4 +250,135 @@ describe("Test the matches routes", () => {
208250
expect(result.body.message).toMatch(/successfully/);
209251
});
210252
});
253+
it('Should create a match without game and default to cs2.', () => {
254+
const newMatchData = [
255+
{
256+
server_id: 2,
257+
team1_id: 4,
258+
team2_id: 3,
259+
max_maps: 1,
260+
title: "Game default check",
261+
veto_mappool: "de_vertigo, de_inferno, de_mirage",
262+
skip_veto: 1,
263+
ignore_server: true
264+
}
265+
];
266+
return request
267+
.post("/matches/")
268+
.set("Content-Type", "application/json")
269+
.set("Accept", "application/json")
270+
.send(newMatchData)
271+
.expect(200)
272+
.expect((result) => {
273+
defaultGameMatchId = result.body.id;
274+
expect(result.body.message).toMatch(/successfully/);
275+
});
276+
});
277+
it('Should persist default game as cs2.', () => {
278+
return request
279+
.get(`/matches/${defaultGameMatchId}`)
280+
.expect(200)
281+
.expect((result) => {
282+
expect(result.body.match.game).toBe("cs2");
283+
});
284+
});
285+
it('Should create a match with game set to csgo.', () => {
286+
const newMatchData = [
287+
{
288+
server_id: 2,
289+
team1_id: 4,
290+
team2_id: 3,
291+
max_maps: 1,
292+
title: "Game csgo check",
293+
veto_mappool: "de_vertigo, de_inferno, de_mirage",
294+
skip_veto: 1,
295+
ignore_server: true,
296+
game: "csgo"
297+
}
298+
];
299+
return request
300+
.post("/matches/")
301+
.set("Content-Type", "application/json")
302+
.set("Accept", "application/json")
303+
.send(newMatchData)
304+
.expect(200)
305+
.expect((result) => {
306+
csgoGameMatchId = result.body.id;
307+
expect(result.body.message).toMatch(/successfully/);
308+
});
309+
});
310+
it('Should persist explicit game as csgo.', () => {
311+
return request
312+
.get(`/matches/${csgoGameMatchId}`)
313+
.expect(200)
314+
.expect((result) => {
315+
expect(result.body.match.game).toBe("csgo");
316+
});
317+
});
318+
it('Should reject invalid game values on create.', () => {
319+
const invalidMatchData = [
320+
{
321+
server_id: 2,
322+
team1_id: 4,
323+
team2_id: 3,
324+
max_maps: 1,
325+
title: "Invalid game create",
326+
veto_mappool: "de_vertigo, de_inferno, de_mirage",
327+
skip_veto: 1,
328+
ignore_server: true,
329+
game: "CS2"
330+
}
331+
];
332+
return request
333+
.post("/matches/")
334+
.set("Content-Type", "application/json")
335+
.set("Accept", "application/json")
336+
.send(invalidMatchData)
337+
.expect(400)
338+
.expect((result) => {
339+
expect(result.body.message).toMatch(/Invalid game value/);
340+
});
341+
});
342+
it('Should reject invalid game values on update.', () => {
343+
const invalidUpdate = [
344+
{
345+
match_id: defaultGameMatchId,
346+
game: "CSGO"
347+
}
348+
];
349+
return request
350+
.put("/matches/")
351+
.set("Content-Type", "application/json")
352+
.set("Accept", "application/json")
353+
.send(invalidUpdate)
354+
.expect(400)
355+
.expect((result) => {
356+
expect(result.body.message).toMatch(/Invalid game value/);
357+
});
358+
});
359+
it('Should update game to csgo on an existing match.', () => {
360+
const updateData = [
361+
{
362+
match_id: defaultGameMatchId,
363+
game: "csgo"
364+
}
365+
];
366+
return request
367+
.put("/matches/")
368+
.set("Content-Type", "application/json")
369+
.set("Accept", "application/json")
370+
.send(updateData)
371+
.expect(200)
372+
.expect((result) => {
373+
expect(result.body.message).toMatch(/successfully/);
374+
});
375+
});
376+
it('Should persist updated game after match update.', () => {
377+
return request
378+
.get(`/matches/${defaultGameMatchId}`)
379+
.expect(200)
380+
.expect((result) => {
381+
expect(result.body.match.game).toBe("csgo");
382+
});
383+
});
211384
});

0 commit comments

Comments
 (0)