Skip to content

Commit

Permalink
refactor: change defaultMessageSender function to noop (#533)
Browse files Browse the repository at this point in the history
* refactor: change defaultMessageSender function to noop

* refactor: refactored audit tests
  • Loading branch information
martinst06 authored Dec 18, 2024
1 parent 06141c1 commit 59c3dbc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 24 deletions.
8 changes: 2 additions & 6 deletions src/common/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 3 additions & 18 deletions test/common/audit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 () => {
Expand Down

0 comments on commit 59c3dbc

Please sign in to comment.