| 1 | import { getCurrentRequestId } from '@yikart/common' |
| 2 | import { describe, expect, it, vi } from 'vitest' |
| 3 | import { createPinoTelemetry } from './pino-telemetry' |
| 4 | |
| 5 | const pinoLoggerMocks = vi.hoisted(() => { |
| 6 | const logger = { child: vi.fn() } |
| 7 | logger.child.mockReturnValue(logger) |
| 8 | return { logger } |
| 9 | }) |
| 10 | |
| 11 | vi.mock('nestjs-pino', () => ({ |
| 12 | PinoLogger: { |
| 13 | root: pinoLoggerMocks.logger, |
| 14 | }, |
| 15 | })) |
| 16 | |
| 17 | describe('pino telemetry context manager', () => { |
| 18 | it('restores propagation request id inside queue job context', () => { |
| 19 | const contextManager = createPinoTelemetry().contextManager |
| 20 | |
| 21 | contextManager.with({ requestId: 'req-1' }, () => { |
| 22 | expect(getCurrentRequestId()).toBe('req-1') |
| 23 | expect(contextManager.active()).toEqual({ requestId: 'req-1' }) |
| 24 | }) |
| 25 | |
| 26 | expect(getCurrentRequestId()).toBeUndefined() |
| 27 | }) |
| 28 | }) |
| 29 |