From daf9b8039a6fe567e283dc07eef156bfd13edc4f Mon Sep 17 00:00:00 2001 From: Iulia Grumaz Date: Mon, 29 Jan 2024 12:10:01 +0200 Subject: [PATCH 1/2] feat: default value for disabled property of audit config (#114) SEO-related audit types should have default value for disabled true (we enable one by one the sites, so we don't waste Ahrefs API units on sites not of interest at this post. --- .../src/models/site/audit-config.js | 19 ++++++++++++++++++- .../test/unit/models/site.test.js | 4 ++-- .../unit/models/site/audit-config.test.js | 18 ++++++------------ 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/packages/spacecat-shared-data-access/src/models/site/audit-config.js b/packages/spacecat-shared-data-access/src/models/site/audit-config.js index 675305ae..f0656f4c 100644 --- a/packages/spacecat-shared-data-access/src/models/site/audit-config.js +++ b/packages/spacecat-shared-data-access/src/models/site/audit-config.js @@ -11,10 +11,27 @@ */ import AuditConfigType from './audit-config-type.js'; +import { AUDIT_TYPE_BROKEN_BACKLINKS } from '../audit.js'; + +const AUDIT_TYPE_DISABLED_DEFAULTS = { + [AUDIT_TYPE_BROKEN_BACKLINKS]: true, +}; function getAuditTypeConfigs(auditTypeConfigs, auditsDisabled) { + if (!auditTypeConfigs || Object.keys(auditTypeConfigs).length === 0) { + return { + [AUDIT_TYPE_BROKEN_BACKLINKS]: AuditConfigType({ disabled: true }), + }; + } return Object.entries(auditTypeConfigs || {}).reduce((acc, [key, value]) => { - acc[key] = AuditConfigType(value, auditsDisabled); + const disabled = value.disabled !== undefined + ? value.disabled : (AUDIT_TYPE_DISABLED_DEFAULTS[key] || auditsDisabled || false); + acc[key] = AuditConfigType( + { + ...value, + disabled, + }, + ); return acc; }, {}); } diff --git a/packages/spacecat-shared-data-access/test/unit/models/site.test.js b/packages/spacecat-shared-data-access/test/unit/models/site.test.js index c2be0d29..61758035 100644 --- a/packages/spacecat-shared-data-access/test/unit/models/site.test.js +++ b/packages/spacecat-shared-data-access/test/unit/models/site.test.js @@ -74,9 +74,9 @@ describe('Site Model Tests', () => { expect(auditConfig).to.be.an('object'); expect(auditConfig.auditsDisabled()).to.be.true; expect(auditConfig.getAuditTypeConfig('type1')).to.be.an('object'); - expect(auditConfig.getAuditTypeConfig('type1').disabled()).to.be.false; + expect(auditConfig.getAuditTypeConfig('type1').disabled()).to.be.true; expect(auditConfig.getAuditTypeConfig('type2')).to.be.an('object'); - expect(auditConfig.getAuditTypeConfig('type2').disabled()).to.be.false; + expect(auditConfig.getAuditTypeConfig('type2').disabled()).to.be.true; }); }); diff --git a/packages/spacecat-shared-data-access/test/unit/models/site/audit-config.test.js b/packages/spacecat-shared-data-access/test/unit/models/site/audit-config.test.js index 0b20e909..2cc3a956 100644 --- a/packages/spacecat-shared-data-access/test/unit/models/site/audit-config.test.js +++ b/packages/spacecat-shared-data-access/test/unit/models/site/audit-config.test.js @@ -15,13 +15,16 @@ import { expect } from 'chai'; import AuditConfig from '../../../../src/models/site/audit-config.js'; +import { AUDIT_TYPE_BROKEN_BACKLINKS } from '../../../../src/models/audit.js'; describe('AuditConfig Tests', () => { describe('AuditConfig Creation', () => { it('creates an AuditConfig with defaults when no data is provided', () => { const auditConfig = AuditConfig(); expect(auditConfig.auditsDisabled()).to.be.false; - expect(auditConfig.getAuditTypeConfigs()).to.be.empty; + const auditTypeConfigs = auditConfig.getAuditTypeConfigs(); + expect(auditTypeConfigs[AUDIT_TYPE_BROKEN_BACKLINKS]).to.be.an('object'); + expect(auditTypeConfigs[AUDIT_TYPE_BROKEN_BACKLINKS].disabled()).to.be.true; }); it('creates an AuditConfig with provided data', () => { @@ -29,13 +32,13 @@ describe('AuditConfig Tests', () => { auditsDisabled: true, auditTypeConfigs: { type1: { disabled: true }, - type2: { disabled: false }, + [AUDIT_TYPE_BROKEN_BACKLINKS]: { disabled: false }, }, }; const auditConfig = AuditConfig(data); expect(auditConfig.auditsDisabled()).to.be.true; expect(auditConfig.getAuditTypeConfig('type1').disabled()).to.be.true; - expect(auditConfig.getAuditTypeConfig('type2').disabled()).to.be.false; + expect(auditConfig.getAuditTypeConfig(AUDIT_TYPE_BROKEN_BACKLINKS).disabled()).to.be.false; }); }); @@ -75,15 +78,6 @@ describe('AuditConfig Tests', () => { const typeConfigs = auditConfig.getAuditTypeConfigs(); expect(typeConfigs).to.have.keys(['type1', 'type2']); }); - - it('returns no audit type configurations', () => { - const data = { - auditTypeConfigs: {}, - }; - const auditConfig = AuditConfig(data); - const typeConfigs = auditConfig.getAuditTypeConfigs(); - expect(typeConfigs).to.be.an('object').that.is.empty; - }); }); describe('updateAuditsDisabled Method', () => { From 78bcc1d82173a7f90b95a84f20abbbf60a6fedd5 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Mon, 29 Jan 2024 10:11:25 +0000 Subject: [PATCH 2/2] chore(release): 1.11.0 [skip ci] # [@adobe/spacecat-shared-data-access-v1.11.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.10.5...@adobe/spacecat-shared-data-access-v1.11.0) (2024-01-29) ### Features * default value for disabled property of audit config ([#114](https://github.com/adobe/spacecat-shared/issues/114)) ([daf9b80](https://github.com/adobe/spacecat-shared/commit/daf9b8039a6fe567e283dc07eef156bfd13edc4f)) --- packages/spacecat-shared-data-access/CHANGELOG.md | 7 +++++++ packages/spacecat-shared-data-access/package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/spacecat-shared-data-access/CHANGELOG.md b/packages/spacecat-shared-data-access/CHANGELOG.md index da4717fc..018c5527 100644 --- a/packages/spacecat-shared-data-access/CHANGELOG.md +++ b/packages/spacecat-shared-data-access/CHANGELOG.md @@ -1,3 +1,10 @@ +# [@adobe/spacecat-shared-data-access-v1.11.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.10.5...@adobe/spacecat-shared-data-access-v1.11.0) (2024-01-29) + + +### Features + +* default value for disabled property of audit config ([#114](https://github.com/adobe/spacecat-shared/issues/114)) ([daf9b80](https://github.com/adobe/spacecat-shared/commit/daf9b8039a6fe567e283dc07eef156bfd13edc4f)) + # [@adobe/spacecat-shared-data-access-v1.10.5](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.10.4...@adobe/spacecat-shared-data-access-v1.10.5) (2024-01-27) diff --git a/packages/spacecat-shared-data-access/package.json b/packages/spacecat-shared-data-access/package.json index 0fd5da19..1093bec3 100644 --- a/packages/spacecat-shared-data-access/package.json +++ b/packages/spacecat-shared-data-access/package.json @@ -1,6 +1,6 @@ { "name": "@adobe/spacecat-shared-data-access", - "version": "1.10.5", + "version": "1.11.0", "description": "Shared modules of the Spacecat Services - Data Access", "type": "module", "main": "src/index.js",