From 7957ffaabadd1b5f8c78fba6060d4d6bf2649e62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominique=20J=C3=A4ggi?= Date: Tue, 31 Dec 2024 16:27:03 +0100 Subject: [PATCH] fix: org config access --- .../organization/organization.schema.js | 3 ++- .../test/it/organization/organization.test.js | 22 +++++++++++++++++++ .../test/it/site/site.test.js | 4 ++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/packages/spacecat-shared-data-access/src/v2/models/organization/organization.schema.js b/packages/spacecat-shared-data-access/src/v2/models/organization/organization.schema.js index 753ececf..89625036 100644 --- a/packages/spacecat-shared-data-access/src/v2/models/organization/organization.schema.js +++ b/packages/spacecat-shared-data-access/src/v2/models/organization/organization.schema.js @@ -14,7 +14,7 @@ import { isNonEmptyObject } from '@adobe/spacecat-shared-utils'; -import { DEFAULT_CONFIG, validateConfiguration } from '../../../models/site/config.js'; +import { Config, DEFAULT_CONFIG, validateConfiguration } from '../../../models/site/config.js'; import SchemaBuilder from '../base/schema.builder.js'; import Organization from './organization.model.js'; import OrganizationCollection from './organization.collection.js'; @@ -33,6 +33,7 @@ const schema = new SchemaBuilder(Organization, OrganizationCollection) required: true, default: DEFAULT_CONFIG, validate: (value) => isNonEmptyObject(validateConfiguration(value)), + get: (value) => Config(value), }) .addAttribute('name', { type: 'string', diff --git a/packages/spacecat-shared-data-access/test/it/organization/organization.test.js b/packages/spacecat-shared-data-access/test/it/organization/organization.test.js index bc280210..0a7f2bf8 100644 --- a/packages/spacecat-shared-data-access/test/it/organization/organization.test.js +++ b/packages/spacecat-shared-data-access/test/it/organization/organization.test.js @@ -42,7 +42,16 @@ describe('Organization IT', async () => { const org = sanitizeTimestamps(organizations[i].toJSON()); const sampleOrg = sanitizeTimestamps(sampleData.organizations[i].toJSON()); + const expectedConfig = { + ...sampleOrg.config, + }; + const actualConfig = { + ...org.config.state, + }; + delete sampleOrg.config; + delete org.config; expect(org).to.eql(sampleOrg); + expect(actualConfig).to.eql(expectedConfig); } }); @@ -50,6 +59,9 @@ describe('Organization IT', async () => { const sampleOrganization = sampleData.organizations[0]; const organization = await Organization.findById(sampleOrganization.getId()); + delete sampleOrganization.record.config; + delete organization.record.config; + expect(organization).to.be.an('object'); expect( sanitizeTimestamps(organization.toJSON()), @@ -62,6 +74,9 @@ describe('Organization IT', async () => { const sampleOrganization = sampleData.organizations[0]; const organization = await Organization.findByImsOrgId(sampleOrganization.getImsOrgId()); + delete sampleOrganization.record.config; + delete organization.record.config; + expect(organization).to.be.an('object'); expect( sanitizeTimestamps(organization.toJSON()), @@ -84,6 +99,9 @@ describe('Organization IT', async () => { const organization = await Organization.create(data); + delete data.config; + delete organization.record.config; + expect(organization).to.be.an('object'); expect( @@ -118,6 +136,10 @@ describe('Organization IT', async () => { await organization.save(); const updatedOrganization = await Organization.findById(organization.getId()); + + delete updatedOrganization.record.config; + delete expectedOrganization.config; + expect(updatedOrganization.getId()).to.equal(organization.getId()); expect(updatedOrganization.record.createdAt).to.equal(organization.record.createdAt); expect(updatedOrganization.record.updatedAt).to.not.equal(organization.record.updatedAt); diff --git a/packages/spacecat-shared-data-access/test/it/site/site.test.js b/packages/spacecat-shared-data-access/test/it/site/site.test.js index 95269a09..12bbedef 100644 --- a/packages/spacecat-shared-data-access/test/it/site/site.test.js +++ b/packages/spacecat-shared-data-access/test/it/site/site.test.js @@ -91,6 +91,10 @@ describe('Site IT', async () => { const organization = await site.getOrganization(); expect(site.getOrganizationId()).to.equal(organizationId); + + delete organization.record.config; + delete sampleData.organizations[0].record.config; + expect(organization).to.be.an('object'); expect( sanitizeTimestamps(organization.toJSON()),