tests for v2

This commit is contained in:
2023-04-08 20:22:10 +02:00
parent a9243b4ba7
commit 57c532c9bb
3 changed files with 50 additions and 32 deletions
+45
View File
@@ -0,0 +1,45 @@
import { afterAll, beforeAll, describe, expect, test } from '@jest/globals'
import clientMain from '../src/clientMain'
import * as dotenv from 'dotenv'
dotenv.config()
let listenServer
beforeAll(async () => {
listenServer = await clientMain;
})
describe('client', () => {
test('server list', async () => {
const request = await fetch("http://127.0.0.1:3000/servers")
const data = await request.json()
expect(data.length).toBeGreaterThan(0)
expect(data[0]).toHaveProperty('name')
expect(data[0]).toHaveProperty('id')
expect(data[0]).toHaveProperty('description')
})
test('player list', async () => {
const request = await fetch("http://127.0.0.1:3000/players")
const data = await request.json()
const first = Object.entries(data)[0]
expect(first[1]).toHaveProperty('max_distance')
expect(first[1]).toHaveProperty('total_distance')
expect(first[1]).toHaveProperty('kills')
})
test('weapon list', async () => {
const request = await fetch("http://127.0.0.1:3000/weapons")
const data = await request.json()
const first = Object.entries(data)[0]
expect(first[1]).toHaveProperty('max_distance')
expect(first[1]).toHaveProperty('total_distance')
expect(first[1]).toHaveProperty('kills')
})
})
afterAll((done) => {
listenServer.close(() => {
done()
})
})
-29
View File
@@ -1,29 +0,0 @@
import { afterAll, beforeAll, describe, expect, test } from '@jest/globals'
import clientMain from '../src/clientMain'
import processMain from '../src/processMain'
import cache from '../src/cache/redis'
import db from "../src/db/db"
import * as dotenv from 'dotenv'
dotenv.config()
let listenServer
beforeAll(async () => {
/*await cache.FLUSHDB()
await processMain
await cache.quit()
await db.destroy()
listenServer = await clientMain;*/
})
describe('client', () => {
test('fetchServerList', () => {
expect(200).toBe(200)
})
})
afterAll((done) => {
cache.quit().then(() => {
db.destroy().then(() => { done() })
})
})
+5 -3
View File
@@ -8,7 +8,6 @@ let listenServer
beforeAll(async () => {
listenServer = await serverMain;
await db.deleteFrom('kill').where('attacker_id', '=', '0').orWhere('attacker_id', '=', '1').execute()
})
describe('server', () => {
@@ -125,6 +124,9 @@ describe('server', () => {
})
afterAll((done) => {
listenServer.close()
db.destroy().then(() => { done() })
listenServer.close(() => {
db.deleteFrom('kill').where('attacker_id', '=', '0').orWhere('attacker_id', '=', '1').execute().then(() => {
db.destroy().then(() => { done() })
})
})
})