Skip to content

The open alternative to Salesforce, designed for AI.

Rename the Emails record tab to Messages (#29343)

martmull5355c7fc8ad7
diff --git a/packages/twenty-docs/user-guide/calendar-emails/capabilities/calendar.mdx b/packages/twenty-docs/user-guide/calendar-emails/capabilities/calendar.mdx
index f71716cb8e1..9bc64d4ff7d 100644
--- a/packages/twenty-docs/user-guide/calendar-emails/capabilities/calendar.mdx
+++ b/packages/twenty-docs/user-guide/calendar-emails/capabilities/calendar.mdx
@@ -15,7 +15,7 @@ Twenty automatically syncs your calendar events and links them to the relevant C
## Calendar Tab
-Next to the Emails tab on records, you'll find a `Calendar` tab that contains the history of meetings scheduled with the record.
+Next to the Messages tab on records, you'll find a `Calendar` tab that contains the history of meetings scheduled with the record.
### Available For
@@ -26,7 +26,7 @@ Next to the Emails tab on records, you'll find a `Calendar` tab that contains th
### Viewing Meeting History
1. **Navigate to a Record**: Go to any Person, Company, or Opportunity record
-2. **Select the Calendar Tab**: Click on the `Calendar` tab next to the Emails tab
+2. **Select the Calendar Tab**: Click on the `Calendar` tab next to the Messages tab
3. **Browse Meeting History**: View all scheduled meetings and their details
4. **Access Meeting Context**: See meeting participants, times, and related information
diff --git a/packages/twenty-docs/user-guide/calendar-emails/capabilities/mailbox.mdx b/packages/twenty-docs/user-guide/calendar-emails/capabilities/mailbox.mdx
index 52dda54afe2..d200cde4424 100644
--- a/packages/twenty-docs/user-guide/calendar-emails/capabilities/mailbox.mdx
+++ b/packages/twenty-docs/user-guide/calendar-emails/capabilities/mailbox.mdx
@@ -24,7 +24,7 @@ Email conversations appear in three main objects:
### Viewing Email Threads
1. **Navigate to a Record**: Go to any Person, Company, or Opportunity record
-2. **Select the Emails Tab**: Click on the `Emails` tab to view synced emails
+2. **Select the Messages Tab**: Click on the `Messages` tab to view synced emails
3. **Open an Email Thread**: Click on any email to open and read the full conversation
4. **Browse History**: Scroll through the complete email history with that contact
diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-56/2-56-upgrade-version-command.module.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-56/2-56-upgrade-version-command.module.ts
index 9b9b7bc53ba..68539eb3185 100644
--- a/packages/twenty-server/src/database/commands/upgrade-version-command/2-56/2-56-upgrade-version-command.module.ts
+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-56/2-56-upgrade-version-command.module.ts
@@ -5,6 +5,7 @@ import { AddDirectMessagePairIdentityCommand } from 'src/database/commands/upgra
import { EnableDirectMessagePairIdentityCommand } from 'src/database/commands/upgrade-version-command/2-56/2-56-workspace-command-1793639083813-enable-direct-message-pair-identity.command';
import { MakeAgentTurnThreadOptionalCommand } from 'src/database/commands/upgrade-version-command/2-56/2-56-workspace-command-1793697418663-make-agent-turn-thread-optional.command';
import { InlineWorkflowStepAgentsCommand } from 'src/database/commands/upgrade-version-command/2-56/2-56-workspace-command-1793697418665-inline-workflow-step-agents.command';
+import { RenameEmailsTabToMessagesCommand } from 'src/database/commands/upgrade-version-command/2-56/2-56-workspace-command-1793707166734-rename-emails-tab-to-messages.command';
import { ApplicationModule } from 'src/engine/core-modules/application/application.module';
import { FeatureFlagModule } from 'src/engine/core-modules/feature-flag/feature-flag.module';
import { WorkspaceCacheModule } from 'src/engine/workspace-cache/workspace-cache.module';
@@ -25,6 +26,7 @@ import { WorkspaceMigrationModule } from 'src/engine/workspace-manager/workspace
EnableDirectMessagePairIdentityCommand,
MakeAgentTurnThreadOptionalCommand,
InlineWorkflowStepAgentsCommand,
+ RenameEmailsTabToMessagesCommand,
],
})
export class V2_56_UpgradeVersionCommandModule {}
diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-56/2-56-workspace-command-1793707166734-rename-emails-tab-to-messages.command.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-56/2-56-workspace-command-1793707166734-rename-emails-tab-to-messages.command.ts
new file mode 100644
index 00000000000..470a364b2e2
--- /dev/null
+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-56/2-56-workspace-command-1793707166734-rename-emails-tab-to-messages.command.ts
@@ -0,0 +1,89 @@
+import { Command } from 'nest-commander';
+import { TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER } from 'twenty-shared/application';
+import { isNonEmptyArray } from 'twenty-shared/utils';
+
+import { ProvisionedWorkspaceCommandRunner } from 'src/database/commands/command-runners/provisioned-workspace.command-runner';
+import { WorkspaceIteratorService } from 'src/database/commands/command-runners/workspace-iterator.service';
+import { type RunOnWorkspaceArgs } from 'src/database/commands/command-runners/workspace.command-runner';
+import { buildMessagesTabMigration } from 'src/database/commands/upgrade-version-command/2-56/utils/build-messages-tab-migration.util';
+import { RegisteredWorkspaceCommand } from 'src/engine/core-modules/upgrade/decorators/registered-workspace-command.decorator';
+import { WorkspaceCacheService } from 'src/engine/workspace-cache/services/workspace-cache.service';
+import { WorkspaceMigrationBuilderException } from 'src/engine/workspace-manager/workspace-migration/exceptions/workspace-migration-builder-exception';
+import { WorkspaceMigrationValidateBuildAndRunService } from 'src/engine/workspace-manager/workspace-migration/services/workspace-migration-validate-build-and-run-service';
+
+@RegisteredWorkspaceCommand('2.56.0', 1793707166734)
+@Command({
+ name: 'upgrade:2-56:rename-emails-tab-to-messages',
+ description: 'Rename the standard Emails record tab and widget to Messages',
+})
+export class RenameEmailsTabToMessagesCommand extends ProvisionedWorkspaceCommandRunner {
+ constructor(
+ protected readonly workspaceIteratorService: WorkspaceIteratorService,
+ private readonly workspaceCacheService: WorkspaceCacheService,
+ private readonly workspaceMigrationValidateBuildAndRunService: WorkspaceMigrationValidateBuildAndRunService,
+ ) {
+ super(workspaceIteratorService);
+ }
+
+ override async runOnWorkspace({
+ workspaceId,
+ options,
+ }: RunOnWorkspaceArgs): Promise<void> {
+ const { flatPageLayoutTabMaps, flatPageLayoutWidgetMaps } =
+ await this.workspaceCacheService.getOrRecompute(workspaceId, [
+ 'flatPageLayoutTabMaps',
+ 'flatPageLayoutWidgetMaps',
+ ]);
+
+ const { pageLayoutTabsToUpdate, pageLayoutWidgetsToUpdate } =
+ buildMessagesTabMigration({
+ flatPageLayoutTabsByUniversalIdentifier:
+ flatPageLayoutTabMaps.byUniversalIdentifier,
+ flatPageLayoutWidgetsByUniversalIdentifier:
+ flatPageLayoutWidgetMaps.byUniversalIdentifier,
+ now: new Date().toISOString(),
+ });
+
+ if (
+ !isNonEmptyArray(pageLayoutTabsToUpdate) &&
+ !isNonEmptyArray(pageLayoutWidgetsToUpdate)
+ ) {
+ return;
+ }
+
+ this.logger.log(
+ `${options.dryRun ? '[DRY RUN] ' : ''}Workspace ${workspaceId}: renaming ${pageLayoutTabsToUpdate.length} tab(s) and ${pageLayoutWidgetsToUpdate.length} widget(s) to Messages`,
+ );
+
+ if (options.dryRun) {
+ return;
+ }
+
+ const result =
+ await this.workspaceMigrationValidateBuildAndRunService.validateBuildAndRunLegacyWorkspaceMigration(
+ {
+ shouldDeferActions: false,
+ workspaceId,
+ isSystemBuild: true,
+ applicationUniversalIdentifier:
+ TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER,
+ allFlatEntityOperationByMetadataName: {
+ pageLayoutTab: {
+ flatEntityToCreate: [],
+ flatEntityToDelete: [],
+ flatEntityToUpdate: pageLayoutTabsToUpdate,
+ },
+ pageLayoutWidget: {
+ flatEntityToCreate: [],
+ flatEntityToDelete: [],
+ flatEntityToUpdate: pageLayoutWidgetsToUpdate,
+ },
+ },
+ },
+ );
+
+ if (result.status === 'fail') {
+ throw new WorkspaceMigrationBuilderException(result);
+ }
+ }
+}
diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-56/constants/messages-tab-migration-universal-identifiers.constant.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-56/constants/messages-tab-migration-universal-identifiers.constant.ts
new file mode 100644
index 00000000000..4f9dc1bf287
--- /dev/null
+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-56/constants/messages-tab-migration-universal-identifiers.constant.ts
@@ -0,0 +1,19 @@
+import { STANDARD_PAGE_LAYOUT_UNIVERSAL_IDENTIFIERS } from 'twenty-shared/metadata';
+
+const RECORD_PAGES_WITH_MESSAGES_TAB = [
+ STANDARD_PAGE_LAYOUT_UNIVERSAL_IDENTIFIERS.companyRecordPage,
+ STANDARD_PAGE_LAYOUT_UNIVERSAL_IDENTIFIERS.personRecordPage,
+ STANDARD_PAGE_LAYOUT_UNIVERSAL_IDENTIFIERS.opportunityRecordPage,
+];
+
+export const MESSAGES_TAB_MIGRATION_UNIVERSAL_IDENTIFIERS: {
+ tabs: string[];
+ widgets: string[];
+} = {
+ tabs: RECORD_PAGES_WITH_MESSAGES_TAB.map(
+ (recordPage) => recordPage.tabs.emails.universalIdentifier,
+ ),
+ widgets: RECORD_PAGES_WITH_MESSAGES_TAB.map(
+ (recordPage) => recordPage.tabs.emails.widgets.emails.universalIdentifier,
+ ),
+};
diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-56/utils/__tests__/build-messages-tab-migration.util.spec.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-56/utils/__tests__/build-messages-tab-migration.util.spec.ts
new file mode 100644
index 00000000000..70c020a780a
--- /dev/null
+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-56/utils/__tests__/build-messages-tab-migration.util.spec.ts
@@ -0,0 +1,93 @@
+import { STANDARD_PAGE_LAYOUT_UNIVERSAL_IDENTIFIERS } from 'twenty-shared/metadata';
+import { isDefined } from 'twenty-shared/utils';
+
+import { buildMessagesTabMigration } from 'src/database/commands/upgrade-version-command/2-56/utils/build-messages-tab-migration.util';
+import { type FlatPageLayoutTab } from 'src/engine/metadata-modules/flat-page-layout-tab/types/flat-page-layout-tab.type';
+import { type FlatPageLayoutWidget } from 'src/engine/metadata-modules/flat-page-layout-widget/types/flat-page-layout-widget.type';
+import { computeTwentyStandardApplicationAllFlatEntityMaps } from 'src/engine/workspace-manager/twenty-standard-application/utils/twenty-standard-application-all-flat-entity-maps.constant';
+
+const NOW = '2026-10-30T12:00:00.000Z';
+const { allFlatEntityMaps } = computeTwentyStandardApplicationAllFlatEntityMaps(
+ {
+ now: '2026-10-29T12:00:00.000Z',
+ workspaceId: '20202020-1111-4111-8111-111111111111',
+ twentyStandardApplicationId: '20202020-2222-4222-8222-222222222222',
+ isWorkspaceCreation: true,
+ },
+);
+
+const buildMigration = ({
+ tabs = [],
+ widgets = [],
+}: {
+ tabs?: FlatPageLayoutTab[];
+ widgets?: FlatPageLayoutWidget[];
+}) =>
+ buildMessagesTabMigration({
+ flatPageLayoutTabsByUniversalIdentifier: Object.fromEntries(
+ tabs.map((tab) => [tab.universalIdentifier, tab]),
+ ),
+ flatPageLayoutWidgetsByUniversalIdentifier: Object.fromEntries(
+ widgets.map((widget) => [widget.universalIdentifier, widget]),
+ ),
+ now: NOW,
+ });
+
+describe.each([
+ ['company', STANDARD_PAGE_LAYOUT_UNIVERSAL_IDENTIFIERS.companyRecordPage],
+ ['person', STANDARD_PAGE_LAYOUT_UNIVERSAL_IDENTIFIERS.personRecordPage],
+ [
+ 'opportunity',
+ STANDARD_PAGE_LAYOUT_UNIVERSAL_IDENTIFIERS.opportunityRecordPage,
+ ],
+])('buildMessagesTabMigration for %s', (_objectName, recordPage) => {
+ const tab =
+ allFlatEntityMaps.flatPageLayoutTabMaps.byUniversalIdentifier[
+ recordPage.tabs.emails.universalIdentifier
+ ];
+ const widget =
+ allFlatEntityMaps.flatPageLayoutWidgetMaps.byUniversalIdentifier[
+ recordPage.tabs.emails.widgets.emails.universalIdentifier
+ ];
+
+ if (!isDefined(tab) || !isDefined(widget)) {
+ throw new Error('Standard messages tab or widget is missing');
+ }
+
+ const legacyTab = { ...tab, title: 'Emails', icon: 'IconMail' };
+ const legacyWidget = { ...widget, title: 'Emails' };
+
+ it('should rename the Emails tab and widget to Messages', () => {
+ expect(
+ buildMigration({ tabs: [legacyTab], widgets: [legacyWidget] }),
+ ).toEqual({
+ pageLayoutTabsToUpdate: [
+ {
+ ...legacyTab,
+ title: 'Messages',
+ icon: 'IconMessage',
+ updatedAt: NOW,
+ },
+ ],
+ pageLayoutWidgetsToUpdate: [
+ { ...legacyWidget, title: 'Messages', updatedAt: NOW },
+ ],
+ });
+ });
+
+ it('should keep a customized title and only update the default icon', () => {
+ expect(
+ buildMigration({ tabs: [{ ...legacyTab, title: 'Inbox' }] })
+ .pageLayoutTabsToUpdate,
+ ).toEqual([
+ { ...legacyTab, title: 'Inbox', icon: 'IconMessage', updatedAt: NOW },
+ ]);
+ });
+
+ it('should do nothing once the workspace is migrated', () => {
+ expect(buildMigration({ tabs: [tab], widgets: [widget] })).toEqual({
+ pageLayoutTabsToUpdate: [],
+ pageLayoutWidgetsToUpdate: [],
+ });
+ });
+});
diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-56/utils/build-messages-tab-migration.util.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-56/utils/build-messages-tab-migration.util.ts
new file mode 100644
index 00000000000..b07bdb8369b
--- /dev/null
+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-56/utils/build-messages-tab-migration.util.ts
@@ -0,0 +1,100 @@
+import { TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER } from 'twenty-shared/application';
+import { isDefined } from 'twenty-shared/utils';
+
+import { MESSAGES_TAB_MIGRATION_UNIVERSAL_IDENTIFIERS } from 'src/database/commands/upgrade-version-command/2-56/constants/messages-tab-migration-universal-identifiers.constant';
+import { type FlatPageLayoutTab } from 'src/engine/metadata-modules/flat-page-layout-tab/types/flat-page-layout-tab.type';
+import { type FlatPageLayoutWidget } from 'src/engine/metadata-modules/flat-page-layout-widget/types/flat-page-layout-widget.type';
+
+const EMAILS_TAB_DEFAULTS = {
+ title: 'Emails',
+ icon: 'IconMail',
+};
+
+const MESSAGES_TAB_DEFAULTS = {
+ title: 'Messages',
+ icon: 'IconMessage',
+};
+
+const EMAILS_WIDGET_DEFAULTS = {
+ title: 'Emails',
+};
+
+const MESSAGES_WIDGET_DEFAULTS = {
+ title: 'Messages',
+};
+
+const isStandardPageLayoutItem = <
+ TPageLayoutItem extends FlatPageLayoutTab | FlatPageLayoutWidget,
+>(
+ pageLayoutItem: TPageLayoutItem | undefined,
+): pageLayoutItem is TPageLayoutItem =>
+ isDefined(pageLayoutItem) &&
+ !isDefined(pageLayoutItem.deletedAt) &&
+ pageLayoutItem.applicationUniversalIdentifier ===
+ TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER;
+
+const pickStandardPageLayoutItems = <
+ TPageLayoutItem extends FlatPageLayoutTab | FlatPageLayoutWidget,
+>(
+ universalIdentifiers: string[],
+ pageLayoutItemsByUniversalIdentifier: Record<string, TPageLayoutItem | undefined>,
+): TPageLayoutItem[] =>
+ universalIdentifiers
+ .map(
+ (universalIdentifier) =>
+ pageLayoutItemsByUniversalIdentifier[universalIdentifier],
+ )
+ .filter(isStandardPageLayoutItem);
+
+export const buildMessagesTabMigration = ({
+ flatPageLayoutTabsByUniversalIdentifier,
+ flatPageLayoutWidgetsByUniversalIdentifier,
+ now,
+}: {
+ flatPageLayoutTabsByUniversalIdentifier: Record<
+ string,
+ FlatPageLayoutTab | undefined
+ >;
+ flatPageLayoutWidgetsByUniversalIdentifier: Record<
+ string,
+ FlatPageLayoutWidget | undefined
+ >;
+ now: string;
+}): {
+ pageLayoutTabsToUpdate: FlatPageLayoutTab[];
+ pageLayoutWidgetsToUpdate: FlatPageLayoutWidget[];
+} => {
+ const pageLayoutTabsToUpdate = pickStandardPageLayoutItems(
+ MESSAGES_TAB_MIGRATION_UNIVERSAL_IDENTIFIERS.tabs,
+ flatPageLayoutTabsByUniversalIdentifier,
+ ).flatMap((tab) => {
+ const title =
+ tab.title === EMAILS_TAB_DEFAULTS.title
+ ? MESSAGES_TAB_DEFAULTS.title
+ : tab.title;
+ const icon =
+ tab.icon === EMAILS_TAB_DEFAULTS.icon ? MESSAGES_TAB_DEFAULTS.icon : tab.icon;
+
+ if (title === tab.title && icon === tab.icon) {
+ return [];
+ }
+
+ return [{ ...tab, title, icon, updatedAt: now }];
+ });
+
+ const pageLayoutWidgetsToUpdate = pickStandardPageLayoutItems(
+ MESSAGES_TAB_MIGRATION_UNIVERSAL_IDENTIFIERS.widgets,
+ flatPageLayoutWidgetsByUniversalIdentifier,
+ )
+ .filter((widget) => widget.title === EMAILS_WIDGET_DEFAULTS.title)
+ .map((widget) => ({
+ ...widget,
+ title: MESSAGES_WIDGET_DEFAULTS.title,
+ updatedAt: now,
+ }));
+
+ return {
+ pageLayoutTabsToUpdate,
+ pageLayoutWidgetsToUpdate,
+ };
+};
diff --git a/packages/twenty-server/src/engine/metadata-modules/page-layout-tab/constants/standard-page-layout-tab-titles.ts b/packages/twenty-server/src/engine/metadata-modules/page-layout-tab/constants/standard-page-layout-tab-titles.ts
index 12b5ae63708..5768b94f3a0 100644
--- a/packages/twenty-server/src/engine/metadata-modules/page-layout-tab/constants/standard-page-layout-tab-titles.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/page-layout-tab/constants/standard-page-layout-tab-titles.ts
@@ -8,6 +8,7 @@ export const getStandardPageLayoutTabTitles = () => [
msg({ message: `Notes`, context: 'pageLayoutTab.title' }),
msg({ message: `Files`, context: 'pageLayoutTab.title' }),
msg({ message: `Emails`, context: 'pageLayoutTab.title' }),
+ msg({ message: `Messages`, context: 'pageLayoutTab.title' }),
msg({ message: `Calendar`, context: 'pageLayoutTab.title' }),
msg({ message: `Note`, context: 'pageLayoutTab.title' }),
msg({ message: `Members`, context: 'pageLayoutTab.title' }),
diff --git a/packages/twenty-server/src/engine/metadata-modules/page-layout-widget/constants/standard-page-layout-widget-titles.ts b/packages/twenty-server/src/engine/metadata-modules/page-layout-widget/constants/standard-page-layout-widget-titles.ts
index f682c9a857c..f0a3a8ce4f9 100644
--- a/packages/twenty-server/src/engine/metadata-modules/page-layout-widget/constants/standard-page-layout-widget-titles.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/page-layout-widget/constants/standard-page-layout-widget-titles.ts
@@ -8,6 +8,7 @@ export const getStandardPageLayoutWidgetTitles = () => [
msg({ message: `Notes`, context: 'pageLayoutWidget.title' }),
msg({ message: `Files`, context: 'pageLayoutWidget.title' }),
msg({ message: `Emails`, context: 'pageLayoutWidget.title' }),
+ msg({ message: `Messages`, context: 'pageLayoutWidget.title' }),
msg({ message: `Calendar`, context: 'pageLayoutWidget.title' }),
msg({ message: `Note`, context: 'pageLayoutWidget.title' }),
msg({ message: `Task`, context: 'pageLayoutWidget.title' }),
diff --git a/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/constants/standard-page-layout-tabs.template.ts b/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/constants/standard-page-layout-tabs.template.ts
index ecfc518ef4e..edcd64a26ae 100644
--- a/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/constants/standard-page-layout-tabs.template.ts
+++ b/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/constants/standard-page-layout-tabs.template.ts
@@ -105,10 +105,10 @@ export const TAB_PROPS = {
},
emails: {
title: i18nLabel(
- msg({ message: `Emails`, context: 'pageLayoutTab.title' }),
+ msg({ message: `Messages`, context: 'pageLayoutTab.title' }),
),
position: 60,
- icon: 'IconMail',
+ icon: 'IconMessage',
layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,
},
conversations: {
@@ -205,7 +205,7 @@ export const WIDGET_PROPS = {
},
emails: {
title: i18nLabel(
- msg({ message: `Emails`, context: 'pageLayoutWidget.title' }),
+ msg({ message: `Messages`, context: 'pageLayoutWidget.title' }),
),
type: WidgetType.EMAILS,
position: VERTICAL_LIST_LAYOUT_POSITIONS.FIRST,
diff --git a/packages/twenty-server/test/integration/upgrade/suites/2-56-workspace-command-1793707166734-rename-emails-tab-to-messages.integration-spec.ts b/packages/twenty-server/test/integration/upgrade/suites/2-56-workspace-command-1793707166734-rename-emails-tab-to-messages.integration-spec.ts
new file mode 100644
index 00000000000..a823eff776f
--- /dev/null
+++ b/packages/twenty-server/test/integration/upgrade/suites/2-56-workspace-command-1793707166734-rename-emails-tab-to-messages.integration-spec.ts
@@ -0,0 +1,196 @@
+import { TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER } from 'twenty-shared/application';
+import { isDefined } from 'twenty-shared/utils';
+
+import { getAppProviderByClassName } from 'test/integration/utils/get-app-provider-by-class-name.util';
+
+import { type RenameEmailsTabToMessagesCommand } from 'src/database/commands/upgrade-version-command/2-56/2-56-workspace-command-1793707166734-rename-emails-tab-to-messages.command';
+import { MESSAGES_TAB_MIGRATION_UNIVERSAL_IDENTIFIERS } from 'src/database/commands/upgrade-version-command/2-56/constants/messages-tab-migration-universal-identifiers.constant';
+import { type FlatPageLayoutTab } from 'src/engine/metadata-modules/flat-page-layout-tab/types/flat-page-layout-tab.type';
+import { type FlatPageLayoutWidget } from 'src/engine/metadata-modules/flat-page-layout-widget/types/flat-page-layout-widget.type';
+import { type WorkspaceCacheService } from 'src/engine/workspace-cache/services/workspace-cache.service';
+import { SEED_APPLE_WORKSPACE_ID } from 'src/engine/workspace-manager/dev-seeder/core/constants/seeder-workspaces.constant';
+import { type WorkspaceMigrationValidateBuildAndRunService } from 'src/engine/workspace-manager/workspace-migration/services/workspace-migration-validate-build-and-run-service';
+
+const EMAILS_TITLE = 'Emails';
+const EMAILS_ICON = 'IconMail';
+const MESSAGES_TITLE = 'Messages';
+const MESSAGES_ICON = 'IconMessage';
+
+const RUN_ON_WORKSPACE_ARGS = {
+ workspaceId: SEED_APPLE_WORKSPACE_ID,
+ options: {},
+ index: 0,
+ total: 1,
+};
+
+describe('2-56 workspace command - rename Emails tab to Messages (integration)', () => {
+ let command: RenameEmailsTabToMessagesCommand;
+ let workspaceCacheService: WorkspaceCacheService;
+ let workspaceMigrationValidateBuildAndRunService: WorkspaceMigrationValidateBuildAndRunService;
+
+ const findMessagesTabsAndWidgets = async () => {
+ const { flatPageLayoutTabMaps, flatPageLayoutWidgetMaps } =
+ await workspaceCacheService.getOrRecompute(SEED_APPLE_WORKSPACE_ID, [
+ 'flatPageLayoutTabMaps',
+ 'flatPageLayoutWidgetMaps',
+ ]);
+
+ return {
+ tabs: MESSAGES_TAB_MIGRATION_UNIVERSAL_IDENTIFIERS.tabs
+ .map(
+ (universalIdentifier) =>
+ flatPageLayoutTabMaps.byUniversalIdentifier[universalIdentifier],
+ )
+ .filter(isDefined),
+ widgets: MESSAGES_TAB_MIGRATION_UNIVERSAL_IDENTIFIERS.widgets
+ .map(
+ (universalIdentifier) =>
+ flatPageLayoutWidgetMaps.byUniversalIdentifier[universalIdentifier],
+ )
+ .filter(isDefined),
+ };
+ };
+
+ const updateTabsAndWidgets = async ({
+ tabs,
+ widgets,
+ }: {
+ tabs: FlatPageLayoutTab[];
+ widgets: FlatPageLayoutWidget[];
+ }) => {
+ const result =
+ await workspaceMigrationValidateBuildAndRunService.validateBuildAndRunLegacyWorkspaceMigration(
+ {
+ workspaceId: SEED_APPLE_WORKSPACE_ID,
+ isSystemBuild: true,
+ applicationUniversalIdentifier:
+ TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER,
+ allFlatEntityOperationByMetadataName: {
+ pageLayoutTab: {
+ flatEntityToCreate: [],
+ flatEntityToDelete: [],
+ flatEntityToUpdate: tabs,
+ },
+ pageLayoutWidget: {
+ flatEntityToCreate: [],
+ flatEntityToDelete: [],
+ flatEntityToUpdate: widgets,
+ },
+ },
+ },
+ );
+
+ expect(result.status).toBe('success');
+ };
+
+ const resetToEmailsTabs = async ({
+ firstTabTitle = EMAILS_TITLE,
+ }: { firstTabTitle?: string } = {}) => {
+ const { tabs, widgets } = await findMessagesTabsAndWidgets();
+
+ await updateTabsAndWidgets({
+ tabs: tabs.map((tab, index) => ({
+ ...tab,
+ title: index === 0 ? firstTabTitle : EMAILS_TITLE,
+ icon: EMAILS_ICON,
+ })),
+ widgets: widgets.map((widget) => ({
+ ...widget,
+ title: EMAILS_TITLE,
+ })),
+ });
+ };
+
+ beforeAll(() => {
+ command = getAppProviderByClassName<RenameEmailsTabToMessagesCommand>(
+ 'RenameEmailsTabToMessagesCommand',
+ );
+ workspaceCacheService = getAppProviderByClassName<WorkspaceCacheService>(
+ 'WorkspaceCacheService',
+ );
+ workspaceMigrationValidateBuildAndRunService =
+ getAppProviderByClassName<WorkspaceMigrationValidateBuildAndRunService>(
+ 'WorkspaceMigrationValidateBuildAndRunService',
+ );
+ });
+
+ afterAll(async () => {
+ await resetToEmailsTabs();
+ await command.runOnWorkspace(RUN_ON_WORKSPACE_ARGS);
+ });
+
+ it('leaves the Emails tabs unchanged on a dry run', async () => {
+ await resetToEmailsTabs();
+
+ await command.runOnWorkspace({
+ ...RUN_ON_WORKSPACE_ARGS,
+ options: { dryRun: true },
+ });
+
+ const { tabs, widgets } = await findMessagesTabsAndWidgets();
+
+ expect(tabs).toHaveLength(3);
+ expect(widgets).toHaveLength(3);
+ for (const tab of tabs) {
+ expect(tab).toMatchObject({ title: EMAILS_TITLE, icon: EMAILS_ICON });
+ }
+
+ for (const widget of widgets) {
+ expect(widget.title).toBe(EMAILS_TITLE);
+ }
+ });
+
+ it('renames the Emails tabs and widgets to Messages', async () => {
+ await resetToEmailsTabs();
+
+ await command.runOnWorkspace(RUN_ON_WORKSPACE_ARGS);
+
+ const { tabs, widgets } = await findMessagesTabsAndWidgets();
+
+ expect(tabs).toHaveLength(3);
+ expect(widgets).toHaveLength(3);
+
+ for (const tab of tabs) {
+ expect(tab).toMatchObject({ title: MESSAGES_TITLE, icon: MESSAGES_ICON });
+ }
+
+ for (const widget of widgets) {
+ expect(widget.title).toBe(MESSAGES_TITLE);
+ }
+ });
+
+ it('keeps a customized tab title and only switches its icon', async () => {
+ await resetToEmailsTabs({ firstTabTitle: 'Inbox' });
+
+ await command.runOnWorkspace(RUN_ON_WORKSPACE_ARGS);
+
+ const { tabs } = await findMessagesTabsAndWidgets();
+ const [customizedTab, ...otherTabs] = tabs;
+
+ expect(tabs).toHaveLength(3);
+ expect(customizedTab).toMatchObject({
+ title: 'Inbox',
+ icon: MESSAGES_ICON,
+ });
+ for (const tab of otherTabs) {
+ expect(tab.title).toBe(MESSAGES_TITLE);
+ }
+ });
+
+ it('is a no-op once the workspace is migrated', async () => {
+ await resetToEmailsTabs();
+ await command.runOnWorkspace(RUN_ON_WORKSPACE_ARGS);
+
+ const before = await findMessagesTabsAndWidgets();
+
+ expect(before.tabs).toHaveLength(3);
+
+ for (const tab of before.tabs) {
+ expect(tab.title).toBe(MESSAGES_TITLE);
+ }
+
+ await command.runOnWorkspace(RUN_ON_WORKSPACE_ARGS);
+
+ expect(await findMessagesTabsAndWidgets()).toEqual(before);
+ });
+});