Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: org config access #518

Merged
merged 1 commit into from
Dec 31, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,26 @@ 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);
}
});

it('gets an organization by id', 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()),
Expand All @@ -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()),
Expand All @@ -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(
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
Loading