Some checks failed
App Prod-Parity E2E Dispatch / dispatch (push) Failing after 10s
CD Storybook UI / build (push) Failing after 3m25s
CD Storybook UI / dispatch (push) Has been skipped
CD deploy main / website-changed-files (push) Successful in 18m8s
CI Agent Skills / changed-files-check (push) Successful in 18m9s
CI Create App E2E minimal / changed-files-check (push) Successful in 24s
CI Create App / changed-files-check (push) Successful in 26s
CI Docs / changed-files-check (push) Successful in 26s
CI Emails / changed-files-check (push) Successful in 28s
CI Example App Hello World / changed-files-check (push) Successful in 23s
CI Front / changed-files-check (push) Has been skipped
CI Example App Postcard / changed-files-check (push) Successful in 27s
CI UI / changed-files-check (push) Has been skipped
CI Utils Test / changed-files-check (push) Successful in 45s
CI Twenty Apps / discover (push) Successful in 1m3s
CD deploy main / deploy-main (push) Failing after 3s
CI Agent Skills / agent-skills-validate (push) Has been skipped
CI Create App / create-app-test (lint) (push) Has been skipped
CI Emails / emails-test (push) Has been skipped
CI Front / front-task (lingui:compile) (push) Has been skipped
CI Front / front-task (lint) (push) Has been skipped
CI Example App Postcard / example-app-postcard (push) Has been skipped
CI UI / ui-task (lint) (push) Has been skipped
CI UI / ui-task (pack-size) (push) Has been skipped
CI UI / ui-task (size) (push) Has been skipped
CI UI / ui-task (test) (push) Has been skipped
CI UI / ui-task (typecheck) (push) Has been skipped
CI Utils Test / utils-test (push) Has been skipped
CI Twenty Apps / ${{ matrix.app.name }} (push) Has been skipped
CI Emails / ci-emails-status-check (push) Successful in 2s
CI Example App Hello World / ci-example-app-hello-world-status-check (push) Successful in 2s
CI Example App Postcard / ci-example-app-postcard-status-check (push) Successful in 3s
CI UI / ui-sb-test (push) Has been skipped
CI Utils Test / ci-utils-test-status-check (push) Successful in 2s
CI Twenty Apps / ci-twenty-apps-status-check (push) Successful in 2s
CI UI / ci-ui-status-check (push) Successful in 2s
CI Desktop / desktop (push) Failing after 1m8s
Push docs to Crowdin / Push documentation to Crowdin (push) Failing after 55s
Push translations to Crowdin / Extract and upload translations (push) Failing after 5s
Push website translations to Crowdin / Extract and upload website translations (push) Failing after 5s
CI Create App / create-app-test (test) (push) Has been skipped
CI Create App / create-app-test (typecheck) (push) Has been skipped
CI Docs / docs-lint (push) Has been skipped
CI Example App Hello World / example-app-hello-world (push) Has been skipped
CI Front / front-task (lingui:extract) (push) Has been skipped
CI Front / front-task (test) (push) Has been skipped
CI Front / front-task (typecheck) (push) Has been skipped
CI UI / ui-sb-build (push) Failing after 1m32s
CI Twenty Apps / ${{ matrix.app.name }} (${{ matrix.server-source }}) (push) Has been skipped
CI Agent Skills / agent-skills-publish (push) Has been skipped
CI Create App / ci-create-app-status-check (push) Successful in 2s
CI Agent Skills / agent-skills-remote-source (push) Has been skipped
CI Create App E2E minimal / create-app-e2e-minimal (push) Has been cancelled
CI E2E Main / e2e-test (push) Has been cancelled
CI Front / front-sb-build (push) Has been cancelled
CI Front / front-build (push) Has been cancelled
CI Create App E2E minimal / ci-create-app-e2e-minimal-status-check (push) Has been cancelled
CI E2E Main / ci-e2e-main-status-check (push) Has been cancelled
CI E2E Main / notify-main-ci-failure (push) Has been cancelled
CI E2E Main / qa-scout-comment (push) Has been cancelled
CI Front / front-sb-test (push) Has been cancelled
CI Front / front-sb-screenshots (push) Has been cancelled
CI Front / ci-front-status-check (push) Has been cancelled
DPA Sub-Processor Sync / sync-subprocessors (push) Failing after 3s
AI Catalog Sync / sync-catalog (push) Failing after 3s
353 lines
9.6 KiB
TypeScript
353 lines
9.6 KiB
TypeScript
import { updateOneFieldMetadata } from 'test/integration/metadata/suites/field-metadata/utils/update-one-field-metadata.util';
|
|
import { createOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/create-one-object-metadata.util';
|
|
import { deleteOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/delete-one-object-metadata.util';
|
|
import { findManyObjectMetadataWithIndexes } from 'test/integration/metadata/suites/object-metadata/utils/find-many-object-metadata-with-indexes.util';
|
|
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 { isDefined } from 'twenty-shared/utils';
|
|
|
|
import { type FieldMetadataDTO } from 'src/engine/metadata-modules/field-metadata/dtos/field-metadata.dto';
|
|
import { type UpdateFieldInput } from 'src/engine/metadata-modules/field-metadata/dtos/update-field.input';
|
|
|
|
type UpdateOneStandardFieldMetadataTestingContext = EachTestingContext<
|
|
Partial<UpdateFieldInput>
|
|
>[];
|
|
|
|
const successfulUpdateTestsUseCase: UpdateOneStandardFieldMetadataTestingContext =
|
|
[
|
|
{
|
|
title: 'when updating description',
|
|
context: {
|
|
description: 'Updated test description for company name field',
|
|
},
|
|
},
|
|
{
|
|
title: 'when updating icon',
|
|
context: {
|
|
icon: 'IconBuildingFactory',
|
|
},
|
|
},
|
|
{
|
|
title: 'when setting isActive to false',
|
|
context: {
|
|
isActive: false,
|
|
},
|
|
},
|
|
{
|
|
title: 'when updating label',
|
|
context: {
|
|
label: 'Business Name',
|
|
},
|
|
},
|
|
{
|
|
title: 'when updating options',
|
|
context: {
|
|
options: [
|
|
{ value: 'NEW', label: 'New Lead', position: 0, color: 'red' },
|
|
{
|
|
value: 'SCREENING',
|
|
label: 'Under Review',
|
|
position: 1,
|
|
color: 'purple',
|
|
},
|
|
{ value: 'MEETING', label: 'Meeting', position: 2, color: 'sky' },
|
|
{
|
|
value: 'PROPOSAL',
|
|
label: 'Proposal Sent',
|
|
position: 3,
|
|
color: 'turquoise',
|
|
},
|
|
{
|
|
value: 'CUSTOMER',
|
|
label: 'Customer',
|
|
position: 4,
|
|
color: 'yellow',
|
|
},
|
|
{ value: 'CLOSED', label: 'Closed', position: 5, color: 'green' },
|
|
],
|
|
},
|
|
},
|
|
{
|
|
title: 'when updating defaultValue',
|
|
context: {
|
|
defaultValue: "'SCREENING'",
|
|
},
|
|
},
|
|
];
|
|
|
|
describe('Standard field metadata update should succeed', () => {
|
|
const opportunityObjectFields: FieldMetadataDTO[] = [];
|
|
let originalFieldMetadataToRestore: FieldMetadataDTO[] = [];
|
|
let originalStageFieldMetadata: FieldMetadataDTO | undefined;
|
|
|
|
beforeAll(async () => {
|
|
const { objects } = await findManyObjectMetadata({
|
|
expectToFail: false,
|
|
input: {
|
|
filter: {},
|
|
paging: { first: 100 },
|
|
},
|
|
gqlFields: `
|
|
id
|
|
nameSingular
|
|
fieldsList {
|
|
id
|
|
name
|
|
label
|
|
description
|
|
icon
|
|
isActive
|
|
type
|
|
options
|
|
settings
|
|
defaultValue
|
|
}
|
|
`,
|
|
});
|
|
|
|
const opportunityObject = objects.find(
|
|
(o) => o.nameSingular === 'opportunity',
|
|
);
|
|
|
|
jestExpectToBeDefined(opportunityObject?.fieldsList);
|
|
|
|
opportunityObjectFields.push(...opportunityObject.fieldsList);
|
|
|
|
originalStageFieldMetadata = opportunityObjectFields.find(
|
|
(field) => field.name === 'stage',
|
|
);
|
|
});
|
|
|
|
afterEach(async () => {
|
|
for (const originalFieldMetadata of originalFieldMetadataToRestore) {
|
|
await updateOneFieldMetadata({
|
|
expectToFail: false,
|
|
input: {
|
|
idToUpdate: originalFieldMetadata.id,
|
|
updatePayload: {
|
|
label: originalFieldMetadata.label,
|
|
description: originalFieldMetadata.description,
|
|
icon: originalFieldMetadata.icon,
|
|
isActive: originalFieldMetadata.isActive,
|
|
options: originalFieldMetadata.options,
|
|
defaultValue: originalFieldMetadata.defaultValue,
|
|
},
|
|
},
|
|
});
|
|
}
|
|
|
|
originalFieldMetadataToRestore = [];
|
|
});
|
|
|
|
describe('Atomic update test suite', () => {
|
|
it.each(eachTestingContextFilter(successfulUpdateTestsUseCase))(
|
|
'$title',
|
|
async ({ context }) => {
|
|
jestExpectToBeDefined(originalStageFieldMetadata);
|
|
originalFieldMetadataToRestore.push(originalStageFieldMetadata);
|
|
const updatePayload = context;
|
|
const { data } = await updateOneFieldMetadata({
|
|
input: {
|
|
idToUpdate: (originalStageFieldMetadata as FieldMetadataDTO).id,
|
|
updatePayload,
|
|
},
|
|
expectToFail: false,
|
|
gqlFields: `
|
|
id
|
|
name
|
|
label
|
|
description
|
|
icon
|
|
isActive
|
|
options
|
|
defaultValue
|
|
`,
|
|
});
|
|
|
|
expect(data.updateOneField.id).toBe(originalStageFieldMetadata.id);
|
|
expect(data.updateOneField).toMatchSnapshot(
|
|
extractRecordIdsAndDatesAsExpectAny({ ...data.updateOneField }),
|
|
);
|
|
},
|
|
);
|
|
});
|
|
|
|
it('Should deactivate and reactivate standard field successfully', async () => {
|
|
const deletedAtField = opportunityObjectFields.find(
|
|
(field) => field.name === 'deletedAt',
|
|
);
|
|
|
|
jestExpectToBeDefined(deletedAtField);
|
|
expect(deletedAtField.isActive).toBe(true);
|
|
|
|
const { data: firstUpdateData } = await updateOneFieldMetadata({
|
|
input: {
|
|
idToUpdate: deletedAtField.id,
|
|
updatePayload: {
|
|
isActive: false,
|
|
},
|
|
},
|
|
expectToFail: false,
|
|
gqlFields: `
|
|
id
|
|
name
|
|
label
|
|
description
|
|
icon
|
|
isActive
|
|
options
|
|
defaultValue
|
|
`,
|
|
});
|
|
|
|
expect(firstUpdateData.updateOneField.isActive).toBe(false);
|
|
|
|
const { data: secondUpdateData } = await updateOneFieldMetadata({
|
|
input: {
|
|
idToUpdate: deletedAtField.id,
|
|
updatePayload: {
|
|
isActive: true,
|
|
},
|
|
},
|
|
expectToFail: false,
|
|
gqlFields: `
|
|
id
|
|
name
|
|
label
|
|
description
|
|
icon
|
|
isActive
|
|
options
|
|
defaultValue
|
|
`,
|
|
});
|
|
|
|
expect(secondUpdateData.updateOneField.isActive).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('Standard field isUnique update should succeed', () => {
|
|
let nameFieldMetadata: FieldMetadataDTO | undefined;
|
|
let customObjectId: string;
|
|
|
|
beforeEach(async () => {
|
|
const customObject = {
|
|
labelSingular: `Test Unique Standard Field`,
|
|
labelPlural: `Test Unique Standard Fields`,
|
|
namePlural: `testUniqueStandardField`,
|
|
nameSingular: `testUniqueStandardFields`,
|
|
description: 'Test unique standard field for isUnique update',
|
|
icon: 'IconBox',
|
|
isLabelSyncedWithName: false,
|
|
};
|
|
|
|
const { data } = await createOneObjectMetadata({
|
|
expectToFail: false,
|
|
input: customObject,
|
|
gqlFields: `
|
|
id
|
|
nameSingular
|
|
`,
|
|
});
|
|
|
|
customObjectId = data.createOneObject.id;
|
|
|
|
const { objects } = await findManyObjectMetadata({
|
|
expectToFail: false,
|
|
input: {
|
|
filter: {},
|
|
paging: { first: 100 },
|
|
},
|
|
gqlFields: `
|
|
id
|
|
nameSingular
|
|
fieldsList {
|
|
id
|
|
name
|
|
label
|
|
isUnique
|
|
isActive
|
|
type
|
|
}
|
|
`,
|
|
});
|
|
|
|
const customObjectWithFields = objects.find((o) => o.id === customObjectId);
|
|
|
|
jestExpectToBeDefined(customObjectWithFields?.fieldsList);
|
|
|
|
nameFieldMetadata = customObjectWithFields.fieldsList?.find(
|
|
(field) => field.name === 'name',
|
|
);
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await updateOneObjectMetadata({
|
|
expectToFail: false,
|
|
input: {
|
|
idToUpdate: customObjectId,
|
|
updatePayload: {
|
|
isActive: false,
|
|
},
|
|
},
|
|
});
|
|
|
|
await deleteOneObjectMetadata({
|
|
input: {
|
|
idToDelete: customObjectId,
|
|
},
|
|
});
|
|
});
|
|
|
|
it('should set isUnique to true on standard field', async () => {
|
|
jestExpectToBeDefined(nameFieldMetadata);
|
|
|
|
const { data } = await updateOneFieldMetadata({
|
|
input: {
|
|
idToUpdate: nameFieldMetadata.id,
|
|
updatePayload: {
|
|
isUnique: true,
|
|
},
|
|
},
|
|
expectToFail: false,
|
|
gqlFields: `
|
|
id
|
|
name
|
|
label
|
|
isUnique
|
|
isActive
|
|
`,
|
|
});
|
|
|
|
expect(data.updateOneField.id).toBe(nameFieldMetadata.id);
|
|
expect(data.updateOneField.name).toBe('name');
|
|
expect(data.updateOneField.isUnique).toBe(true);
|
|
|
|
const objects = await findManyObjectMetadataWithIndexes({
|
|
expectToFail: false,
|
|
});
|
|
|
|
const customObject = objects.find((obj) => obj.id === customObjectId);
|
|
|
|
jestExpectToBeDefined(customObject);
|
|
|
|
const nameFieldIndex = customObject.indexMetadataList.find((index) =>
|
|
index.indexFieldMetadataList.some(
|
|
(indexField) =>
|
|
isDefined(nameFieldMetadata) &&
|
|
indexField.fieldMetadataId === nameFieldMetadata.id,
|
|
),
|
|
);
|
|
|
|
jestExpectToBeDefined(nameFieldIndex);
|
|
expect(nameFieldIndex.isUnique).toBe(true);
|
|
expect(nameFieldIndex.isCustom).toBe(true);
|
|
});
|
|
});
|