From 59c3dbc4079298473c1014de514fb59da8587147 Mon Sep 17 00:00:00 2001 From: martinst06 <132879041+martinst06@users.noreply.github.com> Date: Wed, 18 Dec 2024 18:53:47 +0100 Subject: [PATCH] refactor: change defaultMessageSender function to noop (#533) * refactor: change defaultMessageSender function to noop * refactor: refactored audit tests --- src/common/audit.js | 8 ++------ test/common/audit.test.js | 21 +++------------------ 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/src/common/audit.js b/src/common/audit.js index 303b9898..d1cb650b 100644 --- a/src/common/audit.js +++ b/src/common/audit.js @@ -16,12 +16,8 @@ import URI from 'urijs'; import { createAudit } from '@adobe/spacecat-shared-data-access/src/models/audit.js'; import { retrieveSiteBySiteId } from '../utils/data-access.js'; -export async function defaultMessageSender(resultMessage, context) { - const { sqs } = context; - const { AUDIT_RESULTS_QUEUE_URL: queueUrl } = context.env; - - await sqs.sendMessage(queueUrl, resultMessage); -} +// eslint-disable-next-line no-empty-function +export async function defaultMessageSender() {} export async function defaultPersister(auditData, context) { const { dataAccess } = context; diff --git a/test/common/audit.test.js b/test/common/audit.test.js index dcf2a5af..8fa4fa76 100755 --- a/test/common/audit.test.js +++ b/test/common/audit.test.js @@ -136,8 +136,7 @@ describe('Audit tests', () => { await defaultMessageSender(resultMessage, context); - expect(context.sqs.sendMessage).to.have.been.calledOnce; - expect(context.sqs.sendMessage).to.have.been.calledWith(queueUrl, resultMessage); + expect(context.sqs.sendMessage).not.to.have.been.calledOnce; }); it('default url resolves gets the base url and follows redirects', async () => { @@ -269,14 +268,7 @@ describe('Audit tests', () => { expect(context.dataAccess.addAudit).to.have.been.calledWith(auditData); const finalUrl = 'space.cat'; - const expectedMessage = { - type: message.type, - url: 'https://space.cat', - auditContext: { someField: 431, finalUrl, fullAuditRef }, - auditResult: { metric: 42 }, - }; - expect(context.sqs.sendMessage).to.have.been.calledOnce; - expect(context.sqs.sendMessage).to.have.been.calledWith(queueUrl, expectedMessage); + expect(context.sqs.sendMessage).not.to.have.been.calledOnce; expect(postProcessors[0]).to.have.been.calledWith(finalUrl, auditData); expect(postProcessors[1]).to.have.been.calledWith(finalUrl, auditData); expect(postProcessors[2]).to.not.have.been.called; @@ -333,14 +325,7 @@ describe('Audit tests', () => { id: 'some-audit-id', }); - const expectedMessage = { - type: message.type, - url: 'https://space.cat', - auditContext: { finalUrl: 'space.cat', fullAuditRef }, - auditResult: { metric: 42 }, - }; - expect(context.sqs.sendMessage).to.have.been.calledOnce; - expect(context.sqs.sendMessage).to.have.been.calledWith(queueUrl, expectedMessage); + expect(context.sqs.sendMessage).not.to.have.been.calledOnce; }); it('wwwUrlResolver calculates audit urls correctly', async () => {