From dc68bc18731197baad167b4c72acb5a098029408 Mon Sep 17 00:00:00 2001 From: sorenjohanson Date: Mon, 23 Dec 2024 12:09:28 +0000 Subject: [PATCH] add mock for typeormAnalyzer --- teammapper-backend/src/database/typeorm-analyzer.ts | 9 ++------- teammapper-backend/src/map/services/maps.service.spec.ts | 7 ++++++- teammapper-backend/src/map/services/maps.service.ts | 2 ++ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/teammapper-backend/src/database/typeorm-analyzer.ts b/teammapper-backend/src/database/typeorm-analyzer.ts index 1477bc3b..96b4d8cf 100644 --- a/teammapper-backend/src/database/typeorm-analyzer.ts +++ b/teammapper-backend/src/database/typeorm-analyzer.ts @@ -81,13 +81,8 @@ Query Patterns: // Analyze query patterns const queryPatterns = new Map(); - this.queryLog.forEach(log => { - // Simplify query by removing specific values - const pattern = log.query.replace(/\b\d+\b/g, 'N') - .replace(/'[^']*'/g, '?') - .replace(/"[^"]*"/g, '?'); - - queryPatterns.set(pattern, (queryPatterns.get(pattern) || 0) + 1); + this.queryLog.forEach(log => { + queryPatterns.set(log.query, (queryPatterns.get(log.query) || 0) + 1); }); // Sort patterns by frequency diff --git a/teammapper-backend/src/map/services/maps.service.spec.ts b/teammapper-backend/src/map/services/maps.service.spec.ts index 22bb528d..d6fece3c 100644 --- a/teammapper-backend/src/map/services/maps.service.spec.ts +++ b/teammapper-backend/src/map/services/maps.service.spec.ts @@ -14,18 +14,23 @@ import { import { mapMmpNodeToClient } from '../utils/clientServerMapping' import { truncateDatabase } from 'test/helper' import { jest } from '@jest/globals' +import { TypeORMAnalyzerService } from 'src/database/typeorm-analyzer.service' describe('MapsController', () => { let mapsService: MapsService let nodesRepo: Repository let mapsRepo: Repository let moduleFixture: TestingModule + let typeormAnalyzer: jest.Mocked beforeAll(async () => { // Calling advanceTimers here is very important, as otherwise async ops like await will hang indefinitely // Ref: https://jestjs.io/docs/jest-object#jestusefaketimersfaketimersconfig jest.useFakeTimers({ advanceTimers: true }) + typeormAnalyzer = { + } as jest.Mocked + moduleFixture = await Test.createTestingModule({ imports: [ ConfigModule, @@ -41,7 +46,7 @@ describe('MapsController', () => { getRepositoryToken(MmpNode) ) - mapsService = new MapsService(nodesRepo, mapsRepo) + mapsService = new MapsService(nodesRepo, mapsRepo, typeormAnalyzer) }) afterAll(async () => { diff --git a/teammapper-backend/src/map/services/maps.service.ts b/teammapper-backend/src/map/services/maps.service.ts index 888302e3..6c55264f 100644 --- a/teammapper-backend/src/map/services/maps.service.ts +++ b/teammapper-backend/src/map/services/maps.service.ts @@ -294,6 +294,8 @@ export class MapsService { await callbacks[key](changes); } })); + + this.typeormAnalyzer.logAnalysis(); } async updateMapOptions(