Fix correlation id for tests
This commit is contained in:
parent
040af18765
commit
d8ab2decef
@ -15,7 +15,8 @@ export class Transaction implements IMiddleware {
|
|||||||
|
|
||||||
ns.run(() => {
|
ns.run(() => {
|
||||||
// use pregenerated request correlationId
|
// use pregenerated request correlationId
|
||||||
const correlationId = req.correlationId || shortid.generate();
|
const correlationId = ns.get(CORRELATION_ID) || req.correlationId ||
|
||||||
|
shortid.generate();
|
||||||
(req as any).correlationId = correlationId
|
(req as any).correlationId = correlationId
|
||||||
ns.set(CORRELATION_ID, correlationId)
|
ns.set(CORRELATION_ID, correlationId)
|
||||||
next()
|
next()
|
||||||
|
|||||||
@ -9,6 +9,8 @@ import {IRoutes} from '@rondo.dev/common'
|
|||||||
import {IBootstrap} from '../application/IBootstrap'
|
import {IBootstrap} from '../application/IBootstrap'
|
||||||
import {RequestTester} from './RequestTester'
|
import {RequestTester} from './RequestTester'
|
||||||
import {Role} from '../entities/Role'
|
import {Role} from '../entities/Role'
|
||||||
|
import {CORRELATION_ID} from '../middleware'
|
||||||
|
import shortid from 'shortid'
|
||||||
|
|
||||||
export class TestUtils<T extends IRoutes> {
|
export class TestUtils<T extends IRoutes> {
|
||||||
readonly username = `test${process.env.JEST_WORKER_ID}@user.com`
|
readonly username = `test${process.env.JEST_WORKER_ID}@user.com`
|
||||||
@ -41,6 +43,7 @@ export class TestUtils<T extends IRoutes> {
|
|||||||
connection = await database.connect()
|
connection = await database.connect()
|
||||||
queryRunner = connection.createQueryRunner()
|
queryRunner = connection.createQueryRunner()
|
||||||
await queryRunner.connect()
|
await queryRunner.connect()
|
||||||
|
namespace.set(CORRELATION_ID, shortid())
|
||||||
await queryRunner.startTransaction()
|
await queryRunner.startTransaction()
|
||||||
namespace.set(ENTITY_MANAGER, queryRunner.manager)
|
namespace.set(ENTITY_MANAGER, queryRunner.manager)
|
||||||
})
|
})
|
||||||
@ -51,6 +54,7 @@ export class TestUtils<T extends IRoutes> {
|
|||||||
await queryRunner.rollbackTransaction()
|
await queryRunner.rollbackTransaction()
|
||||||
}
|
}
|
||||||
await queryRunner.release()
|
await queryRunner.release()
|
||||||
|
namespace.set(CORRELATION_ID, undefined)
|
||||||
namespace.set(ENTITY_MANAGER, undefined)
|
namespace.set(ENTITY_MANAGER, undefined)
|
||||||
await connection.close()
|
await connection.close()
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user