Skip to content

Commit e2e4d14

Browse files
authored
fix: validate scores only needed (#203)
1 parent 70edc9f commit e2e4d14

File tree

2 files changed

+6
-21
lines changed

2 files changed

+6
-21
lines changed

packages/spacecat-shared-data-access/src/models/audit.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import { hasText, isIsoDate, isObject } from '@adobe/spacecat-shared-utils';
1414
import { Base } from './base.js';
1515

16+
// some of these unused exports are being imported from other projects. Handle with care.
1617
export const AUDIT_TYPE_404 = '404';
1718
export const AUDIT_TYPE_BROKEN_BACKLINKS = 'broken-backlinks';
1819
export const AUDIT_TYPE_EXPERIMENTATION = 'experimentation';
@@ -25,12 +26,6 @@ export const AUDIT_TYPE_LHS_MOBILE = 'lhs-mobile';
2526
const EXPIRES_IN_DAYS = 30;
2627

2728
const AUDIT_TYPE_PROPERTIES = {
28-
[AUDIT_TYPE_404]: [],
29-
[AUDIT_TYPE_BROKEN_BACKLINKS]: [],
30-
[AUDIT_TYPE_EXPERIMENTATION]: [],
31-
[AUDIT_TYPE_ORGANIC_KEYWORDS]: [],
32-
[AUDIT_TYPE_ORGANIC_TRAFFIC]: [],
33-
[AUDIT_TYPE_CWV]: [],
3429
[AUDIT_TYPE_LHS_DESKTOP]: ['performance', 'seo', 'accessibility', 'best-practices'],
3530
[AUDIT_TYPE_LHS_MOBILE]: ['performance', 'seo', 'accessibility', 'best-practices'],
3631
};
@@ -52,13 +47,12 @@ const validateScores = (auditResult, auditType) => {
5247
}
5348

5449
const expectedProperties = AUDIT_TYPE_PROPERTIES[auditType];
55-
if (!expectedProperties) {
56-
throw new Error(`Unknown audit type: ${auditType}`);
57-
}
5850

59-
for (const prop of expectedProperties) {
60-
if (!(prop in auditResult.scores)) {
61-
throw new Error(`Missing expected property '${prop}' for audit type '${auditType}'`);
51+
if (expectedProperties) {
52+
for (const prop of expectedProperties) {
53+
if (!(prop in auditResult.scores)) {
54+
throw new Error(`Missing expected property '${prop}' for audit type '${auditType}'`);
55+
}
6256
}
6357
}
6458

packages/spacecat-shared-data-access/test/unit/service/audits/index.test.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,6 @@ describe('Audit Access Pattern Tests', () => {
270270
await expect(exportedFunctions.addAudit(auditData)).to.be.rejectedWith('Audit already exists');
271271
});
272272

273-
it('throws an error for unknown audit type', async () => {
274-
const invalidAuditData = {
275-
...auditData,
276-
auditType: 'unknownType', // An unknown audit type
277-
};
278-
279-
await expect(exportedFunctions.addAudit(invalidAuditData)).to.be.rejectedWith('Unknown audit type');
280-
});
281-
282273
it('throws an error if an expected property is missing in audit results', async () => {
283274
const incompleteAuditData = {
284275
...auditData,

0 commit comments

Comments
 (0)