Skip to content
Snippets Groups Projects
Commit 816fd798 authored by Marcos Pieras's avatar Marcos Pieras
Browse files

test: handles message invalid insights

parent 90263c2f
Branches test/validateTypeInsight
No related tags found
1 merge request!42test: adds return message to handle e2e tests
Pipeline #147233 passed
...@@ -57,10 +57,31 @@ export const insightProcessor = async (frontendPublisher: RabbitMqBroker) => { ...@@ -57,10 +57,31 @@ export const insightProcessor = async (frontendPublisher: RabbitMqBroker) => {
let insight = message.insight; let insight = message.insight;
if (!validateInsight(insight, message.force)) { if (!validateInsight(insight, message.force)) {
if (ENV == 'develop') {
const message: WsMessageBackend2Frontend = {
type: wsReturnKey.error,
callID: headers.callID,
status: 'success',
value: 'Insight no valid',
};
frontendPublisher.publishMessageToFrontend(message, headers.routingKey, headers);
}
return; return;
} }
if (!validateTypeInsight(insight, message.force)) { if (!validateTypeInsight(insight, message.force)) {
if (ENV == 'develop') {
const message: WsMessageBackend2Frontend = {
type: wsReturnKey.error,
callID: headers.callID,
status: 'success',
value: 'Insight Type no valid',
};
frontendPublisher.publishMessageToFrontend(message, headers.routingKey, headers);
}
return; return;
} }
...@@ -102,16 +123,14 @@ export const insightProcessor = async (frontendPublisher: RabbitMqBroker) => { ...@@ -102,16 +123,14 @@ export const insightProcessor = async (frontendPublisher: RabbitMqBroker) => {
insight = statCheck(insight, result); insight = statCheck(insight, result);
} }
log.info('Insight save: ', insight);
await ums.updateInsight(insight.userId as number, insight.id, insight); await ums.updateInsight(insight.userId as number, insight.id, insight);
if (ENV == 'develop') { if (ENV == 'develop') {
const message: WsMessageBackend2Frontend = { const message: WsMessageBackend2Frontend = {
type: wsReturnKey.insightResults, type: wsReturnKey.insightResult,
callID: headers.callID, callID: headers.callID,
insight,
status: 'success', status: 'success',
value: insight,
}; };
frontendPublisher.publishMessageToFrontend(message, headers.routingKey, headers); frontendPublisher.publishMessageToFrontend(message, headers.routingKey, headers);
......
import { type InsightModel } from 'ts-common'; import { type InsightModel, isValidEmail, isValidCronExpression } from 'ts-common';
import { log } from '../../logger'; import { log } from '../../logger';
export function validateInsight(insight: InsightModel, force: boolean) { export function validateInsight(insight: InsightModel, force: boolean) {
...@@ -8,7 +8,19 @@ export function validateInsight(insight: InsightModel, force: boolean) { ...@@ -8,7 +8,19 @@ export function validateInsight(insight: InsightModel, force: boolean) {
} }
if (!insight.recipients || insight.recipients.length === 0) { if (!insight.recipients || insight.recipients.length === 0) {
log.debug('No recipients found in the insight, skipping'); log.error('No recipients found in the insight, skipping');
return false;
}
for (const recipient of insight.recipients) {
if (!isValidEmail(recipient)) {
log.error(`Invalid email for recipient: ${recipient}`);
return false;
}
}
if (!insight.frequency || !isValidCronExpression(insight.frequency)) {
log.error('No frequency found in the insight, skipping');
return false; return false;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment