@@ -3,6 +3,9 @@ import app from '../app.js';
33const request = agent ( app ) ;
44
55describe ( "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 ( / u s e _ d a t h o s t .* s e r v e r _ i d / ) ;
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 ( / D a t H o s t | n o t c o n f i g u r e d / ) ;
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 ( / s u c c e s s f u l l y / ) ;
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 ( / s u c c e s s f u l l y / ) ;
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 ( / s u c c e s s f u l l y / ) ;
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 ( / I n v a l i d g a m e v a l u e / ) ;
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 ( / I n v a l i d g a m e v a l u e / ) ;
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 ( / s u c c e s s f u l l y / ) ;
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