The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Fix flaky SavedSecretCanBeCleared story (#28423)
nitinea3cc73b280e
diff --git a/packages/twenty-front/src/pages/settings/accounts/__stories__/SettingsApplicationPreferences.stories.tsx b/packages/twenty-front/src/pages/settings/accounts/__stories__/SettingsApplicationPreferences.stories.tsxindex d5c3fbce597..9200ee46ce9 100644--- a/packages/twenty-front/src/pages/settings/accounts/__stories__/SettingsApplicationPreferences.stories.tsx+++ b/packages/twenty-front/src/pages/settings/accounts/__stories__/SettingsApplicationPreferences.stories.tsx@@ -42,6 +42,8 @@ const meta: Meta<PageDecoratorArgs> = {export default meta;+const NEW_PERSONAL_API_KEY = 'sk-2abcdefghijklmnopqrstuvwxyz0123456789';+export type Story = StoryObj<typeof SettingsApplicationPreferences>;export const VariablesTabSavesOnlyEditedValues: Story = {@@ -186,7 +188,7 @@ export const SavedSecretIsReplacedNotAppended: Story = {expect(saveButton).toBeDisabled();- await userEvent.type(personalApiKeyInput, 'sk-new-key');+ await userEvent.type(personalApiKeyInput, NEW_PERSONAL_API_KEY);await waitFor(() => expect(saveButton).toBeEnabled());await userEvent.click(saveButton);@@ -197,13 +199,13 @@ export const SavedSecretIsReplacedNotAppended: Story = {{applicationUniversalIdentifier: FATHOM_APPLICATION_ID,key: 'PERSONAL_API_KEY',- value: 'sk-new-key',+ value: NEW_PERSONAL_API_KEY,},],]),);await waitFor(() =>- expect(canvas.getByPlaceholderText('sk-1********')).toHaveValue(''),+ expect(canvas.getByPlaceholderText('sk-2********')).toHaveValue(''),);},};diff --git a/packages/twenty-front/src/pages/settings/accounts/__stories__/mockedApplicationPreferences.ts b/packages/twenty-front/src/pages/settings/accounts/__stories__/mockedApplicationPreferences.tsindex 29190fbb090..b36664de9d4 100644--- a/packages/twenty-front/src/pages/settings/accounts/__stories__/mockedApplicationPreferences.ts+++ b/packages/twenty-front/src/pages/settings/accounts/__stories__/mockedApplicationPreferences.ts@@ -2,6 +2,7 @@ import { isNonEmptyString } from '@sniptt/guards';import { HttpResponse, graphql } from 'msw';import { getWorker } from 'msw-storybook-addon';import { fn } from 'storybook/test';+import { isDefined } from 'twenty-shared/utils';import {ACCOUNT_GROUPS_GRAPHQL_HANDLERS,@@ -71,6 +72,22 @@ const buildSettingsMenuItem = ({const savedValueByKey = new Map<string, string>();+const SAVED_PERSONAL_API_KEY = 'sk-1abcdefghijklmnopqrstuvwxyz0123456789';++// Same masking as the server's SecretEncryptionService.maskDecryptedValue.+const maskStoredSecret = (storedValue: string | undefined) => {+ if (!isDefined(storedValue)) {+ return '';+ }++ const visibleCharacterCount = Math.min(+ 5,+ Math.floor(storedValue.length / 10),+ );++ return `${storedValue.slice(0, visibleCharacterCount)}********`;+};+export const updateMyUserApplicationVariable = fn();export const findOneFrontComponent = fn();export const findApplicationsGatedQuery = fn();@@ -89,8 +106,7 @@ const buildApplicationPreferences = () => [buildUserApplicationVariable({key: 'PERSONAL_API_KEY',label: 'Personal API key',- value:- savedValueByKey.get('PERSONAL_API_KEY') === '' ? '' : 'sk-1********',+ value: maskStoredSecret(savedValueByKey.get('PERSONAL_API_KEY')),isSecret: true,}),buildUserApplicationVariable({@@ -197,6 +213,7 @@ export const APPLICATION_PREFERENCES_GRAPHQL_HANDLERS = [export const seedApplicationPreferencesStory = async () => {savedValueByKey.clear();+ savedValueByKey.set('PERSONAL_API_KEY', SAVED_PERSONAL_API_KEY);updateMyUserApplicationVariable.mockClear();findOneFrontComponent.mockClear();findApplicationsGatedQuery.mockClear();