diff --git a/.env.example b/.env.example index f7fc1de..8d6f21b 100644 --- a/.env.example +++ b/.env.example @@ -2,7 +2,4 @@ POSTGRES_HOST="localhost" POSTGRES_DATABASE="postgres" POSTGRES_USER="postgres" POSTGRES_PASSWORD="postgres" -REDIS_USER="default" -REDIS_PASSWORD="" -REDIS_URL="redis://awesome.redis.server:6379" -SERVERAUTH_TEST="1:f9f8fc8c-9185-47a8-8a99-9e3acf6ca007" \ No newline at end of file +SERVERAUTH_TOKEN="1:f9f8fc8c-9185-47a8-8a99-9e3acf6ca007" \ No newline at end of file diff --git a/src/process/onKill.ts b/src/process/onKill.ts index 9c90a7e..be726b8 100644 --- a/src/process/onKill.ts +++ b/src/process/onKill.ts @@ -1,7 +1,7 @@ import { Client } from 'pg' import { allData } from './process' -const pgClient = new Client({ +export const pgClient = new Client({ host: process.env.POSTGRES_HOST, database: process.env.POSTGRES_DATABASE, user: process.env.POSTGRES_USER, diff --git a/tests/client.test.ts b/tests/client.test.ts index 7a057d0..4fc66b7 100644 --- a/tests/client.test.ts +++ b/tests/client.test.ts @@ -1,11 +1,13 @@ -import { afterAll, beforeAll, describe, expect, test } from '@jest/globals' +import { afterAll, beforeAll, describe, expect, jest, test } from '@jest/globals' import clientMain from '../src/clientMain' +import { pgClient } from '../src/process/onKill' import * as dotenv from 'dotenv' import db from '../src/db/db' dotenv.config() let listenServer +jest.setTimeout(30000) beforeAll(async () => { listenServer = await clientMain; }) @@ -59,6 +61,7 @@ describe('client', () => { afterAll((done) => { listenServer.close(async () => { + await pgClient.end() await db.destroy() done() }) diff --git a/tests/realtime.test.ts b/tests/realtime.test.ts index dacce00..5715837 100644 --- a/tests/realtime.test.ts +++ b/tests/realtime.test.ts @@ -1,29 +1,30 @@ import { afterAll, beforeAll, describe, expect, jest, test } from '@jest/globals' import clientMain from '../src/clientMain' import serverMain from '../src/serverMain' -import listenKills from "../src/process/onKill" +import { pgClient } from '../src/process/onKill' import * as dotenv from 'dotenv' import db from '../src/db/db' dotenv.config() let listenClient let listenServer -let pgClient const data = { + servername: 'testserver', attacker_weapon_1_mods: 0, victim_id: '0', - servername: 'testServer', victim_name: 'TestVictim', - victim_offhand_weapon_2: 0, - attacker_offhand_weapon_3: '0', + victim_offhand_weapon_2: 'null', + victim_offhand_weapon_2_mods: 0, victim_weapon_3_mods: 0, - attacker_weapon_2_mods: 0, - attacker_offhand_weapon_1: 0, - attacker_weapon_3_mods: 0, - attacker_offhand_weapon_2: 0, - victim_offhand_weapon_3: '0', - victim_offhand_weapon_1: 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', @@ -41,11 +42,13 @@ const data = { game_mode: 'tdm', map: 'thaw', attacker_weapon_2: 'autopistol', - victim_weapon_1: 'smr', + victim_weapon_1: 'null', victim_weapon_2: 'autopistol', victim_weapon_1_mods: 0, victim_weapon_3: 'defender', - attacker_name: 'TestAttacker' + attacker_name: 'TestAttacker', + victim_titan: 'null', + attacker_titan: 'null' } function waitFor(time: number) { @@ -54,13 +57,11 @@ function waitFor(time: number) { }) } -jest.setTimeout(15000) +jest.setTimeout(30000) beforeAll(async () => { - jest.setTimeout(15000) listenClient = await clientMain; listenServer = await serverMain; - pgClient = await listenKills() const yea = waitFor(1000) const response = await fetch(`http://127.0.0.1:3001/kill`, { method: "POST", // *GET, POST, PUT, DELETE, etc. @@ -79,6 +80,7 @@ describe('realtime', () => { let playerKills let weaponKills let playerDeaths + let serverKills test('fetch player', async () => { const request = await fetch("http://127.0.0.1:3000/players") const data = await request.json() @@ -100,6 +102,14 @@ describe('realtime', () => { weaponKills = weapon.kills }) + test('fetch server', async () => { + const request = await fetch("http://127.0.0.1:3000/servers") + const data = await request.json() + const server = data.testserver + expect(server).toHaveProperty('kills') + serverKills = server.kills + }) + test('update player', async () => { jest.setTimeout(15000) const yea = waitFor(1000) @@ -130,6 +140,13 @@ describe('realtime', () => { expect(weapon.kills).toBe(weaponKills + 1) }) + test('check server update', async () => { + const request = await fetch("http://127.0.0.1:3000/servers") + const data = await request.json() + const server = data.testserver + expect(server.kills).toBe(serverKills + 1) + }) + }) afterAll((done) => { diff --git a/tests/server.test.ts b/tests/server.test.ts index 75f4d18..9eccf27 100644 --- a/tests/server.test.ts +++ b/tests/server.test.ts @@ -65,15 +65,17 @@ describe('server', () => { attacker_weapon_1_mods: 0, victim_id: '0', victim_name: 'TestVictim', - victim_offhand_weapon_2: 0, - attacker_offhand_weapon_3: '0', + 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: 0, + attacker_offhand_weapon_1: 'offhand_weapon_test', + attacker_offhand_weapon_1_mods: 0, attacker_weapon_3_mods: 0, - attacker_offhand_weapon_2: 0, - victim_offhand_weapon_3: '0', - victim_offhand_weapon_1: 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', @@ -95,7 +97,9 @@ describe('server', () => { victim_weapon_2: 'autopistol', victim_weapon_1_mods: 0, victim_weapon_3: 'defender', - attacker_name: 'TestAttacker' + 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. @@ -114,40 +118,44 @@ describe('server', () => { test('register a kill with missing data', async () => { const data = { servername: 'testserver', - attacker_weapon_1_mods: NaN, + attacker_weapon_1_mods: 0, victim_id: '0', victim_name: 'TestVictim', - victim_offhand_weapon_2: NaN, - attacker_offhand_weapon_3: 'null', - victim_weapon_3_mods: 19, + 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: NaN, + attacker_offhand_weapon_1: 'null', + attacker_offhand_weapon_1_mods: 0, attacker_weapon_3_mods: NaN, - attacker_offhand_weapon_2: NaN, - victim_offhand_weapon_3: '0', - victim_offhand_weapon_1: 1, - attacker_weapon_3: 'null', + 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: 'null', - match_id: '554fa7a3', - distance: 202, - victim_current_weapon: 'car', - cause_of_death: 'satchel', - victim_weapon_2_mods: NaN, - victim_current_weapon_mods: NaN, - attacker_current_weapon_mods: NaN, - game_time: 516.417, - player_count: 13, - attacker_current_weapon: 'null', + 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: 'ps', - map: 'grave', - attacker_weapon_2: 'null', - victim_weapon_1: 'car', + game_mode: 'tdm', + map: 'thaw', + attacker_weapon_2: 'autopistol', + victim_weapon_1: 'null', victim_weapon_2: 'autopistol', - victim_weapon_1_mods: NaN, - victim_weapon_3: 'arc_launcher', - attacker_name: 'TestAttacker' + 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.