Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/spacecat-shared-data-access/src/models/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ export const createAudit = (data) => {
throw new Error('Audit result must be an object');
}

if (!newState.scores) {
newState.scores = {};
if (!newState.auditResult.scores) {
newState.auditResult.scores = {};
}
validateScores(data.auditResult, data.auditType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,25 @@ describe('Audit Model Tests', () => {
expect(audit.getPreviousAuditResult()).to.be.undefined;
});

it('automatically initializes scores with empty object if not provided', () => {
const noScoresAuditResult = {
siteId: '123',
auditedAt: new Date().toISOString(),
auditType: 'broken-backlinks',
auditResult: {
brokenBacklinks: [],
},
fullAuditRef: 'ref123',
};

const audit = createAudit(noScoresAuditResult);
expect(audit).to.be.an('object');
expect(audit.getAuditResult()).to.deep.equal({
...noScoresAuditResult.auditResult,
scores: {},
});
});

it('throws an error when updating with invalid previous audit', () => {
const audit = createAudit(validData);

Expand Down