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
200 lines
6.6 KiB
TypeScript
200 lines
6.6 KiB
TypeScript
import { updateOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/update-one-object-metadata.util';
|
|
import { getAppProviderByClassName } from 'test/integration/utils/get-app-provider-by-class-name.util';
|
|
import { getCoreRepository } from 'test/integration/utils/get-core-repository.util';
|
|
import { STANDARD_OBJECT_FIELDS } from 'twenty-shared/metadata';
|
|
import { MetadataReadability } from 'twenty-shared/types';
|
|
import { In } from 'typeorm';
|
|
|
|
import { type MakeNotesAndTasksInheritTheirTargetsCommand } from 'src/database/commands/upgrade-version-command/2-41/2-41-workspace-command-1789373200002-make-notes-and-tasks-inherit-their-targets.command';
|
|
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
|
import { buildSystemAuthContext } from 'src/engine/twenty-orm/utils/build-system-auth-context.util';
|
|
import { WorkspaceOrmManager } from 'src/engine/twenty-orm/workspace-orm.manager';
|
|
import { SEED_APPLE_WORKSPACE_ID } from 'src/engine/workspace-manager/dev-seeder/core/constants/seeder-workspaces.constant';
|
|
|
|
const authContext = buildSystemAuthContext(SEED_APPLE_WORKSPACE_ID);
|
|
|
|
// Listed here rather than imported from the command: a value import would load
|
|
// the command's module graph, which jest cannot resolve in this suite
|
|
const STANDARD_OBJECTS_TO_INHERIT_THROUGH_TARGETS = [
|
|
{
|
|
nameSingular: 'note',
|
|
readabilityParentFieldUniversalIdentifiers: [
|
|
STANDARD_OBJECT_FIELDS.note.noteTargets.universalIdentifier,
|
|
],
|
|
},
|
|
{
|
|
nameSingular: 'noteTarget',
|
|
readabilityParentFieldUniversalIdentifiers: [
|
|
STANDARD_OBJECT_FIELDS.noteTarget.targetPerson.universalIdentifier,
|
|
],
|
|
},
|
|
{
|
|
nameSingular: 'task',
|
|
readabilityParentFieldUniversalIdentifiers: [
|
|
STANDARD_OBJECT_FIELDS.task.taskTargets.universalIdentifier,
|
|
],
|
|
},
|
|
{
|
|
nameSingular: 'taskTarget',
|
|
readabilityParentFieldUniversalIdentifiers: [
|
|
STANDARD_OBJECT_FIELDS.taskTarget.targetPerson.universalIdentifier,
|
|
],
|
|
},
|
|
];
|
|
|
|
const OBJECT_NAMES_SINGULAR = STANDARD_OBJECTS_TO_INHERIT_THROUGH_TARGETS.map(
|
|
({ nameSingular }) => nameSingular,
|
|
);
|
|
|
|
const RUN_ON_WORKSPACE_ARGS = {
|
|
workspaceId: SEED_APPLE_WORKSPACE_ID,
|
|
options: {},
|
|
index: 0,
|
|
total: 1,
|
|
};
|
|
|
|
type ReadabilityState = {
|
|
readability: MetadataReadability;
|
|
readabilityParentFieldUniversalIdentifiers: string[] | null;
|
|
};
|
|
|
|
const EXPECTED_TARGET_STATE: Record<string, ReadabilityState> =
|
|
Object.fromEntries(
|
|
STANDARD_OBJECTS_TO_INHERIT_THROUGH_TARGETS.map(
|
|
({ nameSingular, readabilityParentFieldUniversalIdentifiers }) => [
|
|
nameSingular,
|
|
{
|
|
readability: MetadataReadability.INHERITED,
|
|
readabilityParentFieldUniversalIdentifiers: [
|
|
...readabilityParentFieldUniversalIdentifiers,
|
|
],
|
|
},
|
|
],
|
|
),
|
|
);
|
|
|
|
// The state the previous 2-41 command leaves: targets inherit from their note
|
|
// or task, notes and tasks are still OPEN
|
|
const LEGACY_STATE: Record<string, ReadabilityState> = {
|
|
note: {
|
|
readability: MetadataReadability.OPEN,
|
|
readabilityParentFieldUniversalIdentifiers: null,
|
|
},
|
|
noteTarget: {
|
|
readability: MetadataReadability.INHERITED,
|
|
readabilityParentFieldUniversalIdentifiers: [
|
|
STANDARD_OBJECT_FIELDS.noteTarget.note.universalIdentifier,
|
|
],
|
|
},
|
|
task: {
|
|
readability: MetadataReadability.OPEN,
|
|
readabilityParentFieldUniversalIdentifiers: null,
|
|
},
|
|
taskTarget: {
|
|
readability: MetadataReadability.INHERITED,
|
|
readabilityParentFieldUniversalIdentifiers: [
|
|
STANDARD_OBJECT_FIELDS.taskTarget.task.universalIdentifier,
|
|
],
|
|
},
|
|
};
|
|
|
|
describe('2-41 workspace command 1789373200002 - MakeNotesAndTasksInheritTheirTargetsCommand (integration)', () => {
|
|
let command: MakeNotesAndTasksInheritTheirTargetsCommand;
|
|
let workspaceOrmManager: WorkspaceOrmManager;
|
|
let objectMetadataIdByNameSingular: Record<string, string>;
|
|
|
|
const objectMetadataRepository = () =>
|
|
getCoreRepository<ObjectMetadataEntity>(ObjectMetadataEntity);
|
|
|
|
const runCommand = (options: { dryRun?: boolean } = {}) =>
|
|
workspaceOrmManager.executeInWorkspaceContext(
|
|
() => command.runOnWorkspace({ ...RUN_ON_WORKSPACE_ARGS, options }),
|
|
authContext,
|
|
);
|
|
|
|
const findReadabilityStates = async (): Promise<
|
|
Record<string, ReadabilityState>
|
|
> => {
|
|
const objectMetadataItems = await objectMetadataRepository().find({
|
|
where: {
|
|
workspaceId: SEED_APPLE_WORKSPACE_ID,
|
|
nameSingular: In(OBJECT_NAMES_SINGULAR),
|
|
},
|
|
});
|
|
|
|
return Object.fromEntries(
|
|
objectMetadataItems.map((objectMetadata) => [
|
|
objectMetadata.nameSingular,
|
|
{
|
|
readability: objectMetadata.readability,
|
|
readabilityParentFieldUniversalIdentifiers:
|
|
objectMetadata.readabilityParentFieldUniversalIdentifiers,
|
|
},
|
|
]),
|
|
);
|
|
};
|
|
|
|
const setLegacyState = async () => {
|
|
for (const [nameSingular, state] of Object.entries(LEGACY_STATE)) {
|
|
const objectMetadataId = objectMetadataIdByNameSingular[nameSingular];
|
|
|
|
await objectMetadataRepository().update(objectMetadataId, state);
|
|
|
|
const { errors } = await updateOneObjectMetadata({
|
|
expectToFail: false,
|
|
input: {
|
|
idToUpdate: objectMetadataId,
|
|
updatePayload: { description: 'readability reset to legacy state' },
|
|
},
|
|
});
|
|
|
|
expect(errors).toBeUndefined();
|
|
}
|
|
};
|
|
|
|
beforeAll(async () => {
|
|
command =
|
|
getAppProviderByClassName<MakeNotesAndTasksInheritTheirTargetsCommand>(
|
|
'MakeNotesAndTasksInheritTheirTargetsCommand',
|
|
);
|
|
workspaceOrmManager = getAppProviderByClassName<WorkspaceOrmManager>(
|
|
'WorkspaceOrmManager',
|
|
);
|
|
|
|
const objectMetadataItems = await objectMetadataRepository().find({
|
|
where: {
|
|
workspaceId: SEED_APPLE_WORKSPACE_ID,
|
|
nameSingular: In(OBJECT_NAMES_SINGULAR),
|
|
},
|
|
});
|
|
|
|
expect(objectMetadataItems).toHaveLength(OBJECT_NAMES_SINGULAR.length);
|
|
|
|
objectMetadataIdByNameSingular = Object.fromEntries(
|
|
objectMetadataItems.map((objectMetadata) => [
|
|
objectMetadata.nameSingular,
|
|
objectMetadata.id,
|
|
]),
|
|
);
|
|
|
|
await setLegacyState();
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await runCommand();
|
|
});
|
|
|
|
it('leaves the legacy state on a dry run', async () => {
|
|
await runCommand({ dryRun: true });
|
|
|
|
expect(await findReadabilityStates()).toEqual(LEGACY_STATE);
|
|
});
|
|
|
|
it('makes notes and tasks inherit through their targets and skips them on a second run', async () => {
|
|
await runCommand();
|
|
await runCommand();
|
|
|
|
expect(await findReadabilityStates()).toEqual(EXPECTED_TARGET_STATE);
|
|
});
|
|
});
|