From 54b6f516135e36c6e9ef042ee7441a5a5f762b50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Tymczuk?= Date: Mon, 27 May 2024 18:47:28 +0200 Subject: [PATCH] fix(web): workflow run test tab and failing e2e tests (#5637) --- .../layout/components/EnsureOnboardingComplete.tsx | 4 ++-- apps/web/src/pages/auth/LoginPage.tsx | 4 ++-- .../src/pages/auth/components/HubspotSignupForm.tsx | 8 ++++---- .../src/pages/auth/components/QuestionnaireForm.tsx | 8 ++++---- .../src/pages/templates/components/TestWorkflow.tsx | 10 ++-------- apps/web/tests/main-functionality.spec.ts | 4 ++-- apps/web/tests/utils.ts/integrations.ts | 2 +- libs/shared-web/src/hooks/useAuth.ts | 7 +------ libs/testing/src/testing-queue.service.ts | 4 ---- 9 files changed, 18 insertions(+), 33 deletions(-) diff --git a/apps/web/src/components/layout/components/EnsureOnboardingComplete.tsx b/apps/web/src/components/layout/components/EnsureOnboardingComplete.tsx index a5d6fb1423d..32f75037d54 100644 --- a/apps/web/src/components/layout/components/EnsureOnboardingComplete.tsx +++ b/apps/web/src/components/layout/components/EnsureOnboardingComplete.tsx @@ -6,9 +6,9 @@ import { useBlueprint } from '../../../hooks/index'; export function EnsureOnboardingComplete({ children }: any) { useBlueprint(); const location = useLocation(); - const { currentUser } = useAuth(); + const { claims } = useAuth(); - if ((!currentUser?.organizationId || !currentUser?.environmentId) && location.pathname !== ROUTES.AUTH_APPLICATION) { + if ((!claims?.organizationId || !claims?.environmentId) && location.pathname !== ROUTES.AUTH_APPLICATION) { return ; } diff --git a/apps/web/src/pages/auth/LoginPage.tsx b/apps/web/src/pages/auth/LoginPage.tsx index 337775376e5..e726a0a7862 100644 --- a/apps/web/src/pages/auth/LoginPage.tsx +++ b/apps/web/src/pages/auth/LoginPage.tsx @@ -12,7 +12,7 @@ import { ROUTES } from '../../constants/routes.enum'; export default function LoginPage() { useBlueprint(); - const { login, token: oldToken, currentUser } = useAuth(); + const { login, token: oldToken, currentUser, claims } = useAuth(); const segment = useSegment(); const navigate = useNavigate(); const [params] = useSearchParams(); @@ -28,7 +28,7 @@ export default function LoginPage() { useEffect(() => { if (token) { - if (!invitationToken && currentUser?._id && (!currentUser?.organizationId || !currentUser?.environmentId)) { + if (!invitationToken && currentUser?._id && (!claims?.organizationId || !claims?.environmentId)) { const authApplicationLink = isFromVercel ? `${ROUTES.AUTH_APPLICATION}?code=${code}&next=${next}` : ROUTES.AUTH_APPLICATION; diff --git a/apps/web/src/pages/auth/components/HubspotSignupForm.tsx b/apps/web/src/pages/auth/components/HubspotSignupForm.tsx index a978cb0d199..b61d6d632c2 100644 --- a/apps/web/src/pages/auth/components/HubspotSignupForm.tsx +++ b/apps/web/src/pages/auth/components/HubspotSignupForm.tsx @@ -17,7 +17,7 @@ import { successMessage } from '@novu/design-system'; export function HubspotSignupForm() { const [loading, setLoading] = useState(); const navigate = useNavigate(); - const { login, token, currentUser } = useAuth(); + const { login, token, claims, currentUser } = useAuth(); const { startVercelSetup } = useVercelIntegration(); const { isFromVercel } = useVercelParams(); const { colorScheme } = useMantineColorScheme(); @@ -32,7 +32,7 @@ export function HubspotSignupForm() { useEffect(() => { if (token) { - if (currentUser?.environmentId) { + if (claims?.environmentId) { if (isFromVercel) { startVercelSetup(); @@ -42,7 +42,7 @@ export function HubspotSignupForm() { navigate(ROUTES.HOME); } } - }, [token, navigate, isFromVercel, startVercelSetup, currentUser]); + }, [token, navigate, isFromVercel, startVercelSetup, claims]); async function createOrganization(data: IOrganizationCreateForm) { const { organizationName, jobTitle, ...rest } = data; @@ -64,7 +64,7 @@ export function HubspotSignupForm() { setLoading(true); - if (!currentUser?.organizationId) { + if (!claims?.organizationId) { await createOrganization({ ...data }); } diff --git a/apps/web/src/pages/auth/components/QuestionnaireForm.tsx b/apps/web/src/pages/auth/components/QuestionnaireForm.tsx index 7c076372286..61f78221db4 100644 --- a/apps/web/src/pages/auth/components/QuestionnaireForm.tsx +++ b/apps/web/src/pages/auth/components/QuestionnaireForm.tsx @@ -34,7 +34,7 @@ export function QuestionnaireForm() { control, } = useForm({}); const navigate = useNavigate(); - const { login, token, currentUser } = useAuth(); + const { login, token, claims } = useAuth(); const { startVercelSetup } = useVercelIntegration(); const { isFromVercel } = useVercelParams(); const { parse } = useDomainParser(); @@ -47,7 +47,7 @@ export function QuestionnaireForm() { useEffect(() => { if (token) { - if (currentUser?.environmentId) { + if (claims?.environmentId) { if (isFromVercel) { startVercelSetup(); @@ -57,7 +57,7 @@ export function QuestionnaireForm() { navigate(ROUTES.HOME); } } - }, [token, navigate, isFromVercel, startVercelSetup, currentUser]); + }, [token, navigate, isFromVercel, startVercelSetup, claims]); async function createOrganization(data: IOrganizationCreateForm) { const { organizationName, ...rest } = data; @@ -72,7 +72,7 @@ export function QuestionnaireForm() { setLoading(true); - if (!currentUser?.organizationId) { + if (!claims?.organizationId) { await createOrganization({ ...data }); } diff --git a/apps/web/src/pages/templates/components/TestWorkflow.tsx b/apps/web/src/pages/templates/components/TestWorkflow.tsx index d75bd25b600..85f5c95b50a 100644 --- a/apps/web/src/pages/templates/components/TestWorkflow.tsx +++ b/apps/web/src/pages/templates/components/TestWorkflow.tsx @@ -60,12 +60,6 @@ export function TestWorkflow({ trigger }) { return [{ name: 'subscriberId' }, ...(trigger?.subscriberVariables || [])]; }, [trigger]); - const currentUserDependencies = subscriberVariables.map((variable) => - currentUser ? currentUser[variable.name === 'subscriberId' ? '_id' : variable.name] : null - ); - // eslint-disable-next-line react-hooks/exhaustive-deps - const memoizedCurrentUser = useMemo(() => currentUser, [...currentUserDependencies]); - const variables = useMemo(() => [...(trigger?.variables || [])], [trigger]); const reservedVariables = useMemo(() => [...(trigger?.reservedVariables || [])], [trigger]); @@ -97,8 +91,8 @@ export function TestWorkflow({ trigger }) { const { setValues } = form; useEffect(() => { - setValues({ toValue: makeToValue(subscriberVariables, memoizedCurrentUser) }); - }, [setValues, subscriberVariables, memoizedCurrentUser]); + setValues({ toValue: makeToValue(subscriberVariables, currentUser) }); + }, [setValues, subscriberVariables, currentUser]); const onTrigger = async ({ toValue, payloadValue, overridesValue, snippetValue }) => { const to = JSON.parse(toValue); diff --git a/apps/web/tests/main-functionality.spec.ts b/apps/web/tests/main-functionality.spec.ts index 5bcebcfa25c..d884b5fa10a 100644 --- a/apps/web/tests/main-functionality.spec.ts +++ b/apps/web/tests/main-functionality.spec.ts @@ -80,7 +80,7 @@ test('should update to empty data when switching from editor to customHtml', asy await subjectEl.clear(); await subjectEl.fill('new email subject'); - await updateWorkflowButtonClick(page, { noWaitAfter: true }); + await updateWorkflowButtonClick(page); const templatesLinkPage = getByTestId(page, 'side-nav-templates-link'); await templatesLinkPage.click(); @@ -326,7 +326,7 @@ test('should show the brand logo on main page', async ({ page }) => { await addAndEditChannel(page, 'email'); const brandLogo = getByTestId(page, 'brand-logo'); - await expect(brandLogo).toHaveAttribute('src', 'https://web.novu.co/static/images/logo-light.webp'); + await expect(brandLogo).toHaveAttribute('src', 'https://web.novu.co/static/images/logo-light.png'); }); test('should support RTL text content', async ({ page }) => { diff --git a/apps/web/tests/utils.ts/integrations.ts b/apps/web/tests/utils.ts/integrations.ts index f16ed59cfb5..9cd7b191aad 100644 --- a/apps/web/tests/utils.ts/integrations.ts +++ b/apps/web/tests/utils.ts/integrations.ts @@ -13,7 +13,7 @@ export const navigateToGetStarted = async (page: Page, card = 'channel-card-emai const integrationsModal = getByTestId(page, 'integrations-list-modal'); await expect(integrationsModal).toBeVisible(); - await expect(integrationsModal).toContainText('Integrations Store'); + await expect(integrationsModal.getByRole('heading')).toContainText('Integration Store'); }; export const checkTableLoading = async (page: Page | Locator) => { diff --git a/libs/shared-web/src/hooks/useAuth.ts b/libs/shared-web/src/hooks/useAuth.ts index a22fc62ae6b..193951dc554 100644 --- a/libs/shared-web/src/hooks/useAuth.ts +++ b/libs/shared-web/src/hooks/useAuth.ts @@ -150,12 +150,7 @@ export function useAuth() { inPublicRoute, inPrivateRoute, isLoading: inPrivateRoute && (isUserLoading || isOrganizationLoading), - // TODO: Remove orgId and envId from currentUser and add them to the useAuth hook returned object - currentUser: { - ...user, - organizationId: claims?.organizationId, - environmentId: claims?.environmentId, - } satisfies IUserWithContext, + currentUser: user, organizations, currentOrganization, token, diff --git a/libs/testing/src/testing-queue.service.ts b/libs/testing/src/testing-queue.service.ts index 2f2dd080fa5..c5f6f383f13 100644 --- a/libs/testing/src/testing-queue.service.ts +++ b/libs/testing/src/testing-queue.service.ts @@ -19,9 +19,5 @@ export class TestingQueueService { removeOnComplete: true, }, }); - - if (process.env.NODE_ENV === 'test' && !process.env.CI) { - this.queue.obliterate({ force: true }); - } } }