mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
fix test setup
This commit is contained in:
parent
738b7942c1
commit
f12176c35f
@ -17,18 +17,12 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@hyperswarm/dht": "^6.3.3",
|
||||
"apollo-server-express": "2.25.2",
|
||||
"class-validator": "^0.13.2",
|
||||
"cross-env": "^7.0.3",
|
||||
"dotenv": "10.0.0",
|
||||
"express": "4.17.1",
|
||||
"graphql": "15.5.1",
|
||||
"log4js": "^6.7.1",
|
||||
"nodemon": "^2.0.20",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"ts-node": "^10.9.1",
|
||||
"tsconfig-paths": "^4.1.2",
|
||||
"type-graphql": "^1.1.1",
|
||||
"typescript": "^4.9.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
@ -36,9 +30,7 @@
|
||||
"@typescript-eslint/parser": "^5.48.0",
|
||||
"@types/dotenv": "^8.2.0",
|
||||
"@types/jest": "^27.0.2",
|
||||
"@types/lodash.clonedeep": "^4.5.7",
|
||||
"@types/node": "^18.11.18",
|
||||
"apollo-server-testing": "^2.25.2",
|
||||
"eslint": "^8.31.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-config-standard": "^17.0.0",
|
||||
|
||||
@ -3,8 +3,25 @@ import { startDHT } from '@/dht_node/index'
|
||||
|
||||
// config
|
||||
import CONFIG from './config'
|
||||
import { logger } from './server/logger'
|
||||
import connection from './typeorm/connection'
|
||||
import { checkDBVersion } from './typeorm/DBVersion'
|
||||
|
||||
async function main() {
|
||||
// open mysql connection
|
||||
const con = await connection()
|
||||
if (!con || !con.isConnected) {
|
||||
logger.fatal(`Couldn't open connection to database!`)
|
||||
throw new Error(`Fatal: Couldn't open connection to database`)
|
||||
}
|
||||
|
||||
// check for correct database version
|
||||
const dbVersion = await checkDBVersion(CONFIG.DB_VERSION)
|
||||
if (!dbVersion) {
|
||||
logger.fatal('Fatal: Database Version incorrect')
|
||||
throw new Error('Fatal: Database Version incorrect')
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(
|
||||
`starting Federation on ${CONFIG.FEDERATION_DHT_TOPIC} ${
|
||||
|
||||
@ -8,15 +8,13 @@ const options = JSON.parse(readFileSync(CONFIG.LOG4JS_CONFIG, 'utf-8'))
|
||||
options.categories.dht.level = CONFIG.LOG_LEVEL
|
||||
options.categories.apollo.level = CONFIG.LOG_LEVEL
|
||||
let filename: string = options.appenders.dht.filename
|
||||
options.appenders.dht.filename = filename
|
||||
.replace('apiversion-%v', 'dht-' + CONFIG.FEDERATION_DHT_TOPIC)
|
||||
.replace('%p', CONFIG.PORT.toString())
|
||||
options.appenders.dht.filename = filename.replace(
|
||||
'apiversion-%v',
|
||||
'dht-' + CONFIG.FEDERATION_DHT_TOPIC,
|
||||
)
|
||||
filename = options.appenders.access.filename
|
||||
options.appenders.access.filename = filename.replace('%p', CONFIG.PORT.toString())
|
||||
filename = options.appenders.apollo.filename
|
||||
options.appenders.apollo.filename = filename.replace('%p', CONFIG.PORT.toString())
|
||||
filename = options.appenders.errorFile.filename
|
||||
options.appenders.errorFile.filename = filename.replace('%p', CONFIG.PORT.toString())
|
||||
|
||||
log4js.configure(options)
|
||||
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||
|
||||
import { createTestClient } from 'apollo-server-testing'
|
||||
import createServer from '../src/server/createServer'
|
||||
import CONFIG from '@/config'
|
||||
import connection from '@/typeorm/connection'
|
||||
import { checkDBVersion } from '@/typeorm/DBVersion'
|
||||
import { initialize } from '@dbTools/helpers'
|
||||
import { entities } from '@entity/index'
|
||||
import { logger } from './testSetup'
|
||||
@ -28,13 +29,21 @@ export const cleanDB = async () => {
|
||||
}
|
||||
|
||||
export const testEnvironment = async (testLogger: any = logger) => {
|
||||
const server = await createServer(testLogger)
|
||||
const con = server.con
|
||||
const testClient = createTestClient(server.apollo)
|
||||
const mutate = testClient.mutate
|
||||
const query = testClient.query
|
||||
// open mysql connection
|
||||
const con = await connection()
|
||||
if (!con || !con.isConnected) {
|
||||
logger.fatal(`Couldn't open connection to database!`)
|
||||
throw new Error(`Fatal: Couldn't open connection to database`)
|
||||
}
|
||||
|
||||
// check for correct database version
|
||||
const dbVersion = await checkDBVersion(CONFIG.DB_VERSION)
|
||||
if (!dbVersion) {
|
||||
logger.fatal('Fatal: Database Version incorrect')
|
||||
throw new Error('Fatal: Database Version incorrect')
|
||||
}
|
||||
await initialize()
|
||||
return { mutate, query, con }
|
||||
return { con }
|
||||
}
|
||||
|
||||
export const resetEntity = async (entity: any) => {
|
||||
|
||||
1331
dht-node/yarn.lock
1331
dht-node/yarn.lock
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user