From d850b6ae232c05ad3d987ee26ebf11de0e643c89 Mon Sep 17 00:00:00 2001
From: MarcosPierasNL <pieras.marcos@gmail.com>
Date: Tue, 18 Mar 2025 14:30:33 +0100
Subject: [PATCH] test: e2e wip

---
 src/index.ts                    |  2 +-
 src/readers/insightProcessor.ts | 22 ++++++++++++++++++----
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/src/index.ts b/src/index.ts
index 15b50d0..34c70e3 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -24,7 +24,7 @@ async function main() {
   log.info('Connected to Redis!');
 
   await queryServiceReader(frontendPublisher, mlPublisher, 'neo4j');
-  await insightProcessor();
+  await insightProcessor(frontendPublisher);
 }
 
 await main();
diff --git a/src/readers/insightProcessor.ts b/src/readers/insightProcessor.ts
index 71014ea..be9fe29 100644
--- a/src/readers/insightProcessor.ts
+++ b/src/readers/insightProcessor.ts
@@ -1,4 +1,4 @@
-import { rabbitMq, ums, mail, SMTP_USER, DEBUG_EMAIL } from '../variables';
+import { rabbitMq, ums, mail, SMTP_USER, DEBUG_EMAIL, ENV } from '../variables';
 import { log } from '../logger';
 import { type InsightModel } from 'ts-common';
 import { createHeadlessEditor } from '@lexical/headless';
@@ -12,6 +12,7 @@ import { diffCheck } from './diffCheck';
 import { VariableNode } from '../utils/lexical';
 import { populateTemplate } from '../utils/insights';
 import { RabbitMqBroker } from 'ts-common/rabbitMq';
+import type { WsMessageBackend2Frontend } from 'ts-common';
 
 const dom = new JSDOM();
 function setUpDom() {
@@ -34,10 +35,10 @@ function setUpDom() {
   };
 }
 
-export const insightProcessor = async () => {
+export const insightProcessor = async (frontendPublisher: RabbitMqBroker) => {
   if (mail == null) {
     log.warn('Mail is not configured. Insight processor will be disabled');
-    return;
+    //return;
   }
 
   log.info('Starting insight processor');
@@ -107,7 +108,20 @@ export const insightProcessor = async () => {
         }
 
         if (insight.userId == null) return; // fixes ts but never is the case
-        await ums.updateInsight(insight.userId, insight.id, insight);
+
+        //await ums.updateInsight(insight.userId, insight.id, insight);
+
+        // For testing only, not in production
+        if (ENV == 'develop') {
+          const message: WsMessageBackend2Frontend = {
+            type: 'queryStatusUpdate',
+            callID: headers.callID,
+            insight,
+            status: 'success',
+          };
+
+          frontendPublisher.publishMessageToFrontend(message, headers.routingKey, headers);
+        }
 
         if (insight.status || message.force) {
           if (insight.status) log.debug('Insight passed the check');
-- 
GitLab