register match working
This commit is contained in:
+101
-97
@@ -2,10 +2,93 @@ import { afterAll, beforeAll, describe, expect, test } from '@jest/globals'
|
||||
import serverMain from '../src/serverMain'
|
||||
import db from "../src/db/db"
|
||||
import * as dotenv from 'dotenv'
|
||||
import {type KillData} from '../src/server/types'
|
||||
dotenv.config()
|
||||
|
||||
let listenServer
|
||||
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
'Authorization': `Bearer ${Buffer.from(process.env.SERVERAUTH_TOKEN + '').toString('base64')}`
|
||||
}
|
||||
const testMatch = { air_accel:false, server_name:Math.floor(Math.random()*100).toString(), game_map:"testMap", gamemode:"test" }
|
||||
const testKill = {
|
||||
"game_time": 22.616668701171876,
|
||||
"player_count": 1,
|
||||
"match_id": 1,
|
||||
"victim": {
|
||||
"velocity": 0.0,
|
||||
"name": "Legonzaur",
|
||||
"loadout": {
|
||||
"ordnance": {
|
||||
"name": "mp_weapon_satchel",
|
||||
"mods": 0
|
||||
},
|
||||
"secondary": {
|
||||
"name": "mp_weapon_wingman",
|
||||
"mods": 140
|
||||
},
|
||||
"primary": {
|
||||
"name": "mp_weapon_sniper",
|
||||
"mods": 1168
|
||||
},
|
||||
"tactical": {
|
||||
"name": "mp_ability_grapple",
|
||||
"mods": 8
|
||||
},
|
||||
"anti_titan": {
|
||||
"name": "mp_weapon_defender",
|
||||
"mods": 134
|
||||
}
|
||||
},
|
||||
"current_weapon": {
|
||||
"name": "mp_weapon_sniper",
|
||||
"mods": 1168
|
||||
},
|
||||
"state": "OnGround",
|
||||
"titan": "null",
|
||||
"id": 1005930844007n,
|
||||
"cloaked": false
|
||||
},
|
||||
"attacker": {
|
||||
"velocity": 0.0,
|
||||
"name": "Legonzaur",
|
||||
"loadout": {
|
||||
"ordnance": {
|
||||
"name": "mp_weapon_satchel",
|
||||
"mods": 0
|
||||
},
|
||||
"secondary": {
|
||||
"name": "mp_weapon_wingman",
|
||||
"mods": 140
|
||||
},
|
||||
"primary": {
|
||||
"name": "mp_weapon_sniper",
|
||||
"mods": 1168
|
||||
},
|
||||
"tactical": {
|
||||
"name": "mp_ability_grapple",
|
||||
"mods": 8
|
||||
},
|
||||
"anti_titan": {
|
||||
"name": "mp_weapon_defender",
|
||||
"mods": 134
|
||||
}
|
||||
},
|
||||
"current_weapon": {
|
||||
"name": "mp_weapon_sniper",
|
||||
"mods": 1168
|
||||
},
|
||||
"state": "OnGround",
|
||||
"titan": "null",
|
||||
"id": 1005930844007n,
|
||||
"cloaked": false
|
||||
},
|
||||
"distance": 0.0,
|
||||
"cause_of_death": "mp_weapon_satchel"
|
||||
} as KillData
|
||||
|
||||
|
||||
beforeAll(async () => {
|
||||
listenServer = await serverMain;
|
||||
})
|
||||
@@ -46,69 +129,30 @@ describe('server', () => {
|
||||
expect(response2.status).toBe(403)
|
||||
})
|
||||
|
||||
|
||||
test('good auth prefetch', async () => {
|
||||
const response = await fetch(`http://127.0.0.1:3001/`, {
|
||||
method: "POST", // *GET, POST, PUT, DELETE, etc.
|
||||
credentials: "same-origin", // include, *same-origin, omit
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
'Authorization': `Bearer ${Buffer.from('' + process.env.SERVERAUTH_TOKEN).toString('base64')}`
|
||||
}
|
||||
headers
|
||||
});
|
||||
expect(response.status).toBe(200)
|
||||
})
|
||||
|
||||
test('register a match', async () => {
|
||||
const response = await fetch(`http://127.0.0.1:3001/match`, {
|
||||
method: "POST",
|
||||
headers,
|
||||
body: JSON.stringify(testMatch),
|
||||
});
|
||||
expect(await response.json()).toHaveProperty("match")
|
||||
expect(response.status).toBe(201)
|
||||
})
|
||||
|
||||
test('register a kill', async () => {
|
||||
const data = {
|
||||
servername: 'testserver',
|
||||
attacker_weapon_1_mods: 0,
|
||||
victim_id: '0',
|
||||
victim_name: 'TestVictim',
|
||||
victim_offhand_weapon_2: 'offhand_weapon_test',
|
||||
victim_offhand_weapon_2_mods: 0,
|
||||
victim_weapon_3_mods: 0,
|
||||
attacker_weapon_2_mods: 0,
|
||||
attacker_offhand_weapon_1: 'offhand_weapon_test',
|
||||
attacker_offhand_weapon_1_mods: 0,
|
||||
attacker_weapon_3_mods: 0,
|
||||
attacker_offhand_weapon_2: 'offhand_weapon_test',
|
||||
attacker_offhand_weapon_2_mods: 0,
|
||||
victim_offhand_weapon_1: 'offhand_weapon_test',
|
||||
victim_offhand_weapon_1_mods: 0,
|
||||
attacker_weapon_3: 'defender',
|
||||
killstat_version: 'ks_3.0.0',
|
||||
attacker_weapon_1: 'smr',
|
||||
match_id: '31b1f34d',
|
||||
distance: 0,
|
||||
victim_current_weapon: 'smr',
|
||||
cause_of_death: 'smr',
|
||||
victim_weapon_2_mods: 0,
|
||||
victim_current_weapon_mods: 0,
|
||||
attacker_current_weapon_mods: 0,
|
||||
game_time: 377.799,
|
||||
player_count: 1,
|
||||
attacker_current_weapon: 'smr',
|
||||
attacker_id: '1',
|
||||
game_mode: 'tdm',
|
||||
map: 'thaw',
|
||||
attacker_weapon_2: 'autopistol',
|
||||
victim_weapon_1: 'smr',
|
||||
victim_weapon_2: 'autopistol',
|
||||
victim_weapon_1_mods: 0,
|
||||
victim_weapon_3: 'defender',
|
||||
attacker_name: 'TestAttacker',
|
||||
victim_titan: 'null',
|
||||
attacker_titan: 'null'
|
||||
}
|
||||
const response = await fetch(`http://127.0.0.1:3001/kill`, {
|
||||
method: "POST", // *GET, POST, PUT, DELETE, etc.
|
||||
credentials: "same-origin", // include, *same-origin, omit
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
'Authorization': `Bearer ${Buffer.from(process.env.SERVERAUTH_TOKEN + '').toString('base64')}`
|
||||
},
|
||||
body: JSON.stringify(data), // body data type must match "Content-Type" header
|
||||
method: "POST",
|
||||
headers,
|
||||
body: JSON.stringify(testKill),
|
||||
});
|
||||
console.log(await response.text())
|
||||
expect(response.status).toBe(201)
|
||||
@@ -116,47 +160,7 @@ describe('server', () => {
|
||||
|
||||
|
||||
test('register a kill with missing data', async () => {
|
||||
const data = {
|
||||
servername: 'testserver',
|
||||
attacker_weapon_1_mods: 0,
|
||||
victim_id: '0',
|
||||
victim_name: 'TestVictim',
|
||||
victim_offhand_weapon_2: 'null',
|
||||
victim_offhand_weapon_2_mods: 0,
|
||||
victim_weapon_3_mods: 0,
|
||||
attacker_weapon_2_mods: NaN,
|
||||
attacker_offhand_weapon_1: 'null',
|
||||
attacker_offhand_weapon_1_mods: 0,
|
||||
attacker_weapon_3_mods: NaN,
|
||||
attacker_offhand_weapon_2: 'null',
|
||||
attacker_offhand_weapon_2_mods: NaN,
|
||||
victim_offhand_weapon_1: 'offhand_weapon_test',
|
||||
victim_offhand_weapon_1_mods: 0,
|
||||
attacker_weapon_3: 'defender',
|
||||
killstat_version: 'ks_3.0.0',
|
||||
attacker_weapon_1: 'smr',
|
||||
match_id: '31b1f34d',
|
||||
distance: 0,
|
||||
victim_current_weapon: 'smr',
|
||||
cause_of_death: 'smr',
|
||||
victim_weapon_2_mods: 0,
|
||||
victim_current_weapon_mods: 0,
|
||||
attacker_current_weapon_mods: 0,
|
||||
game_time: 377.799,
|
||||
player_count: 1,
|
||||
attacker_current_weapon: 'smr',
|
||||
attacker_id: '1',
|
||||
game_mode: 'tdm',
|
||||
map: 'thaw',
|
||||
attacker_weapon_2: 'autopistol',
|
||||
victim_weapon_1: 'null',
|
||||
victim_weapon_2: 'autopistol',
|
||||
victim_weapon_1_mods: 0,
|
||||
victim_weapon_3: 'defender',
|
||||
attacker_name: 'TestAttacker',
|
||||
victim_titan: 'null',
|
||||
attacker_titan: 'null'
|
||||
}
|
||||
const data = testKill
|
||||
const response = await fetch(`http://127.0.0.1:3001/kill`, {
|
||||
method: "POST", // *GET, POST, PUT, DELETE, etc.
|
||||
credentials: "same-origin", // include, *same-origin, omit
|
||||
@@ -164,17 +168,17 @@ describe('server', () => {
|
||||
"Content-Type": "application/json",
|
||||
'Authorization': `Bearer ${Buffer.from(process.env.SERVERAUTH_TOKEN + '').toString('base64')}`
|
||||
},
|
||||
body: JSON.stringify(data), // body data type must match "Content-Type" header
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
expect(response.status).toBe(201)
|
||||
})
|
||||
})
|
||||
|
||||
afterAll((done) => {
|
||||
db.deleteFrom('kill').where('attacker_id', '=', '0').orWhere('attacker_id', '=', '1').execute().then(() => {
|
||||
// db.deleteFrom('kill').where('attacker_id', '=', 0n).orWhere('attacker_id', '=', 1n).execute().then(() => {
|
||||
listenServer.close(async () => {
|
||||
await db.destroy()
|
||||
done()
|
||||
})
|
||||
})
|
||||
// })
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user