a74edbf715
## Summary - Fixes object `color` to use the `standardOverrides` mechanism for standard objects, matching how `label`, `description`, and `icon` already work - Previously, color was written directly to the `objectMetadata.color` column for **both** standard and custom objects, which meant user color customizations on standard objects could be overwritten during metadata syncs - Custom objects continue to have `color` updated directly on the entity (no change) ## Changes | File | What changed | |------|-------------| | `object-metadata-standard-overrides-properties.constant.ts` | Added `'color'` to `OBJECT_METADATA_STANDARD_OVERRIDES_PROPERTIES` so `sanitizeRawUpdateObjectInput` routes color into `standardOverrides` for standard objects | | `resolve-object-metadata-standard-override.util.ts` | Extended to support `'color'` as a key — handled like `icon` (no i18n/translation, just direct override check) | | `object-metadata.resolver.ts` | Added `@ResolveField` for `color` that resolves through `resolveObjectMetadataStandardOverride`, matching the existing `labelSingular`/`labelPlural`/`description`/`icon` resolve fields | | `flat-object-metadata-validator.service.ts` | Removed `'color'` from `allowedOverrideKeys` for system objects since it now flows through `standardOverrides` | | `resolve-object-metadata-standard-override.util.spec.ts` | Added test cases for custom object color, standard object color override, and standard object color fallback | | `successful-update-one-standard-object-metadata.integration-spec.ts` | Added `'when updating color'` test case, included `color` in GraphQL queries and `standardOverrides` fragment, reset color in `afterEach` cleanup | ## How it works now | Object type | Color update flow | |---|---| | **Custom** | Written directly to `objectMetadata.color` column | | **Standard** | Stored in `objectMetadata.standardOverrides.color`, resolved via `@ResolveField` at query time | This is identical to how `label`, `description`, and `icon` have always worked. ## Test plan - [x] Unit tests pass (`resolve-object-metadata-standard-override.util.spec.ts` — 21 tests) - [x] Typecheck passes (`npx nx typecheck twenty-server`) - [x] Lint passes (`npx nx lint:diff-with-main twenty-server`) - [ ] Integration test snapshot regenerates correctly (`successful-update-one-standard-object-metadata`) - [ ] Verify standard object color editing from sidebar persists via `standardOverrides` - [ ] Verify custom object color editing from sidebar persists directly on entity Made with [Cursor](https://cursor.com)
160 lines
4.3 KiB
TypeScript
160 lines
4.3 KiB
TypeScript
import { findManyObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/find-many-object-metadata.util';
|
|
import { updateOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/update-one-object-metadata.util';
|
|
import { extractRecordIdsAndDatesAsExpectAny } from 'test/utils/extract-record-ids-and-dates-as-expect-any';
|
|
import { jestExpectToBeDefined } from 'test/utils/jest-expect-to-be-defined.util.test';
|
|
import {
|
|
eachTestingContextFilter,
|
|
type EachTestingContext,
|
|
} from 'twenty-shared/testing';
|
|
|
|
import { type ObjectMetadataDTO } from 'src/engine/metadata-modules/object-metadata/dtos/object-metadata.dto';
|
|
import { type UpdateObjectPayload } from 'src/engine/metadata-modules/object-metadata/dtos/update-object.input';
|
|
|
|
type TestingRuntimeContext = {
|
|
objectMetadataId: string;
|
|
};
|
|
|
|
type UpdateOneStandardObjectMetadataTestingContext = EachTestingContext<
|
|
| ((args: TestingRuntimeContext) => Partial<UpdateObjectPayload>)
|
|
| Partial<UpdateObjectPayload>
|
|
>[];
|
|
|
|
const successfulUpdateTestsUseCase: UpdateOneStandardObjectMetadataTestingContext =
|
|
[
|
|
{
|
|
title: 'when updating description',
|
|
context: {
|
|
description: 'Updated test description for company',
|
|
},
|
|
},
|
|
{
|
|
title: 'when updating icon',
|
|
context: {
|
|
icon: 'IconBuildingSkyscraper',
|
|
},
|
|
},
|
|
{
|
|
title: 'when setting isActive to false',
|
|
context: {
|
|
isActive: false,
|
|
},
|
|
},
|
|
{
|
|
title: 'when updating labelSingular and labelPlural',
|
|
context: {
|
|
labelSingular: 'Business',
|
|
labelPlural: 'Businesses',
|
|
},
|
|
},
|
|
{
|
|
title: 'when updating color',
|
|
context: {
|
|
color: 'red',
|
|
},
|
|
},
|
|
];
|
|
|
|
const allTestsUseCases = [...successfulUpdateTestsUseCase];
|
|
|
|
describe('Standard object metadata update should succeed', () => {
|
|
let companyObjectMetadataId: string;
|
|
let originalCompanyMetadata: ObjectMetadataDTO;
|
|
|
|
beforeAll(async () => {
|
|
const { objects } = await findManyObjectMetadata({
|
|
expectToFail: false,
|
|
input: {
|
|
filter: {},
|
|
paging: { first: 100 },
|
|
},
|
|
gqlFields: `
|
|
id
|
|
nameSingular
|
|
namePlural
|
|
labelSingular
|
|
labelPlural
|
|
color
|
|
description
|
|
icon
|
|
isActive
|
|
shortcut
|
|
`,
|
|
});
|
|
|
|
const companyObject = objects.find((o) => o.nameSingular === 'company');
|
|
|
|
jestExpectToBeDefined(companyObject);
|
|
companyObjectMetadataId = companyObject.id;
|
|
originalCompanyMetadata = companyObject;
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await updateOneObjectMetadata({
|
|
expectToFail: false,
|
|
input: {
|
|
idToUpdate: companyObjectMetadataId,
|
|
updatePayload: {
|
|
labelSingular: originalCompanyMetadata.labelSingular,
|
|
labelPlural: originalCompanyMetadata.labelPlural,
|
|
description: originalCompanyMetadata.description,
|
|
icon: originalCompanyMetadata.icon,
|
|
isActive: originalCompanyMetadata.isActive,
|
|
shortcut: originalCompanyMetadata.shortcut,
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
it.each(eachTestingContextFilter(allTestsUseCases))(
|
|
'$title',
|
|
async ({ context }) => {
|
|
const updatePayload =
|
|
typeof context === 'function'
|
|
? context({ objectMetadataId: companyObjectMetadataId })
|
|
: context;
|
|
|
|
const {
|
|
data: { updateOneObject },
|
|
errors,
|
|
} = await updateOneObjectMetadata({
|
|
input: {
|
|
idToUpdate: companyObjectMetadataId,
|
|
updatePayload,
|
|
},
|
|
expectToFail: false,
|
|
gqlFields: `
|
|
id
|
|
nameSingular
|
|
namePlural
|
|
labelSingular
|
|
labelPlural
|
|
color
|
|
description
|
|
icon
|
|
isActive
|
|
shortcut
|
|
standardOverrides {
|
|
labelSingular
|
|
labelPlural
|
|
color
|
|
description
|
|
icon
|
|
}
|
|
`,
|
|
});
|
|
|
|
expect(errors).toBeUndefined();
|
|
expect(updateOneObject).toBeDefined();
|
|
expect(updateOneObject.id).toBe(companyObjectMetadataId);
|
|
|
|
expect(updateOneObject).toMatchObject({
|
|
...updatePayload,
|
|
});
|
|
|
|
expect(updateOneObject).toMatchSnapshot(
|
|
extractRecordIdsAndDatesAsExpectAny({ ...updateOneObject }),
|
|
);
|
|
},
|
|
);
|
|
});
|