Skip to content

Commit

Permalink
fix(web): workflow run test tab and failing e2e tests (#5637)
Browse files Browse the repository at this point in the history
  • Loading branch information
LetItRock authored May 27, 2024
1 parent 635d365 commit 54b6f51
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Navigate to={ROUTES.AUTH_APPLICATION} replace />;
}

Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/pages/auth/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions apps/web/src/pages/auth/components/HubspotSignupForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { successMessage } from '@novu/design-system';
export function HubspotSignupForm() {
const [loading, setLoading] = useState<boolean>();
const navigate = useNavigate();
const { login, token, currentUser } = useAuth();
const { login, token, claims, currentUser } = useAuth();
const { startVercelSetup } = useVercelIntegration();
const { isFromVercel } = useVercelParams();
const { colorScheme } = useMantineColorScheme();
Expand All @@ -32,7 +32,7 @@ export function HubspotSignupForm() {

useEffect(() => {
if (token) {
if (currentUser?.environmentId) {
if (claims?.environmentId) {
if (isFromVercel) {
startVercelSetup();

Expand All @@ -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;
Expand All @@ -64,7 +64,7 @@ export function HubspotSignupForm() {

setLoading(true);

if (!currentUser?.organizationId) {
if (!claims?.organizationId) {
await createOrganization({ ...data });
}

Expand Down
8 changes: 4 additions & 4 deletions apps/web/src/pages/auth/components/QuestionnaireForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function QuestionnaireForm() {
control,
} = useForm<IOrganizationCreateForm>({});
const navigate = useNavigate();
const { login, token, currentUser } = useAuth();
const { login, token, claims } = useAuth();
const { startVercelSetup } = useVercelIntegration();
const { isFromVercel } = useVercelParams();
const { parse } = useDomainParser();
Expand All @@ -47,7 +47,7 @@ export function QuestionnaireForm() {

useEffect(() => {
if (token) {
if (currentUser?.environmentId) {
if (claims?.environmentId) {
if (isFromVercel) {
startVercelSetup();

Expand All @@ -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;
Expand All @@ -72,7 +72,7 @@ export function QuestionnaireForm() {

setLoading(true);

if (!currentUser?.organizationId) {
if (!claims?.organizationId) {
await createOrganization({ ...data });
}

Expand Down
10 changes: 2 additions & 8 deletions apps/web/src/pages/templates/components/TestWorkflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions apps/web/tests/main-functionality.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 }) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/web/tests/utils.ts/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
7 changes: 1 addition & 6 deletions libs/shared-web/src/hooks/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions libs/testing/src/testing-queue.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,5 @@ export class TestingQueueService {
removeOnComplete: true,
},
});

if (process.env.NODE_ENV === 'test' && !process.env.CI) {
this.queue.obliterate({ force: true });
}
}
}

0 comments on commit 54b6f51

Please sign in to comment.