-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
712 additions
and
512 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,8 @@ const config: StorybookConfig = { | |
"FIREBASE_AUTH_DOMAIN": btoa("some-domain"), | ||
"BACKEND_URL": btoa("http://foo.bar.com/api"), | ||
"SENSITIVE_PERSONAL_DATA_RSA_ENCRYPTION_KEY": btoa(\`${key}\`), | ||
"SENSITIVE_PERSONAL_DATA_RSA_ENCRYPTION_KEY_ID": btoa("1") | ||
"SENSITIVE_PERSONAL_DATA_RSA_ENCRYPTION_KEY_ID": btoa("1"), | ||
"SENTRY_FRONTEND_DSN": btoa("https://[email protected]/baz") | ||
}; | ||
//used for chat components | ||
sessionStorage.setItem("ChatSessionID", "1234") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
frontend-new/src/auth/components/requestInvitationCode/RequestInvitationCode.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import React from "react"; | ||
import { render, screen } from "src/_test_utilities/test-utils"; | ||
import userEvent from "@testing-library/user-event"; | ||
import * as Sentry from "@sentry/react"; | ||
|
||
import RequestInvitationCode, { DATA_TEST_ID as REQUEST_INVITATION_CODE_DATA_TEST_ID } from "./RequestInvitationCode"; | ||
import { InvitationType } from "src/auth/services/invitationsService/invitations.types"; | ||
import { DATA_TEST_ID as REQUEST_INVITATION_CODE_FORM_MODAL_DATA_TEST_ID } from "src/auth/components/requestInvitationCode/requestInvitationCodeFormModal/RequestInvitationCodeFormModal"; | ||
jest.mock("@sentry/react"); | ||
jest.mock("src/auth/components/requestInvitationCode/requestInvitationCodeFormModal/RequestInvitationCodeFormModal", () => { | ||
const actual = jest.requireActual("src/auth/components/requestInvitationCode/requestInvitationCodeFormModal/RequestInvitationCodeFormModal"); | ||
return { | ||
...actual, | ||
__esModule: true, | ||
default: jest.fn().mockImplementation(() => | ||
<div data-testid={actual.DATA_TEST_ID.CONTAINER} /> | ||
) | ||
}; | ||
}); | ||
|
||
describe("RequestInvitationCode", () => { | ||
test("renders null when Sentry is not initialized", () => { | ||
// GIVEN sentry is not initialized | ||
jest.spyOn(Sentry, "isInitialized").mockReturnValue(false); | ||
|
||
// WHEN the component is rendered | ||
render(<RequestInvitationCode invitationCodeType={InvitationType.AUTO_REGISTER} />); | ||
|
||
// THEN the link should not render | ||
expect(screen.queryByTestId(REQUEST_INVITATION_CODE_DATA_TEST_ID.REQUEST_INVITATION_CODE_LINK)).not.toBeInTheDocument(); | ||
// AND the modal should not render | ||
expect(screen.queryByTestId(REQUEST_INVITATION_CODE_FORM_MODAL_DATA_TEST_ID.CONTAINER)).not.toBeInTheDocument(); | ||
}); | ||
|
||
test("renders the correct text and link when Sentry is initialized", () => { | ||
// GIVEN sentry is initialized | ||
jest.spyOn(Sentry, "isInitialized").mockReturnValue(true); | ||
|
||
// WHEN the component is rendered | ||
render(<RequestInvitationCode invitationCodeType={InvitationType.AUTO_REGISTER} />); | ||
|
||
// THEN the component should render the correct text and link | ||
expect(screen.getByTestId(`${REQUEST_INVITATION_CODE_DATA_TEST_ID.REQUEST_INVITATION_CODE_LINK}-${InvitationType.AUTO_REGISTER}`)).toBeInTheDocument(); | ||
}); | ||
|
||
test("opens the modal when the link is clicked", async () => { | ||
// GIVEN sentry is initialized | ||
jest.spyOn(Sentry, "isInitialized").mockReturnValue(true); | ||
|
||
// WHEN the component is rendered | ||
render(<RequestInvitationCode invitationCodeType={InvitationType.AUTO_REGISTER} />); | ||
|
||
// THEN the modal should be opened when the link is clicked | ||
await userEvent.click(screen.getByTestId(`${REQUEST_INVITATION_CODE_DATA_TEST_ID.REQUEST_INVITATION_CODE_LINK}-${InvitationType.AUTO_REGISTER}`)); | ||
expect(screen.getByTestId(REQUEST_INVITATION_CODE_FORM_MODAL_DATA_TEST_ID.CONTAINER)).toBeInTheDocument(); | ||
}); | ||
|
||
test("renders the correct text for registration code type", () => { | ||
// GIVEN sentry is initialized | ||
jest.spyOn(Sentry, "isInitialized").mockReturnValue(true); | ||
|
||
// WHEN the component is rendered | ||
render(<RequestInvitationCode invitationCodeType={InvitationType.REGISTER} />); | ||
|
||
// THEN the component should render the correct text | ||
expect(screen.getByTestId(`${REQUEST_INVITATION_CODE_DATA_TEST_ID.REQUEST_INVITATION_CODE_LINK}-${InvitationType.REGISTER}`)).toBeInTheDocument(); | ||
}); | ||
}); |
48 changes: 48 additions & 0 deletions
48
frontend-new/src/auth/components/requestInvitationCode/RequestInvitationCode.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React, { useState, useContext } from 'react' | ||
import Typography from '@mui/material/Typography' | ||
import * as Sentry from '@sentry/react' | ||
import CustomLink from 'src/theme/CustomLink/CustomLink' | ||
import RequestInvitationCodeFormModal from "./requestInvitationCodeFormModal/RequestInvitationCodeFormModal"; | ||
import { InvitationType } from "src/auth/services/invitationsService/invitations.types"; | ||
import { IsOnlineContext } from "src/app/isOnlineProvider/IsOnlineProvider"; | ||
|
||
|
||
interface Props { | ||
invitationCodeType: InvitationType; | ||
} | ||
|
||
const uniqueId = "7ce9ba1f-bde0-48e2-88df-e4f697945cc4"; | ||
|
||
export const DATA_TEST_ID = { | ||
REQUEST_INVITATION_CODE_LINK: `request-invitation-code-link-${uniqueId}`, | ||
} | ||
|
||
const RequestInvitationCode = ({ invitationCodeType }: Props) => { | ||
const [isModalOpen, setIsModalOpen] = useState(false) | ||
const isOnline = useContext(IsOnlineContext); | ||
|
||
if (!Sentry.isInitialized()) { | ||
return null | ||
} | ||
|
||
const invitationCodeText = invitationCodeType === InvitationType.AUTO_REGISTER ? 'login code' : 'registration code'; | ||
|
||
return ( | ||
<> | ||
<Typography variant="caption" gutterBottom> | ||
Don't have a {invitationCodeText}?{" "} | ||
<CustomLink | ||
disabled={!isOnline} | ||
onClick={() => setIsModalOpen(true)} | ||
data-testid={`${DATA_TEST_ID.REQUEST_INVITATION_CODE_LINK}-${invitationCodeType}`} | ||
> | ||
Reach out | ||
</CustomLink> | ||
</Typography> | ||
|
||
<RequestInvitationCodeFormModal open={isModalOpen} onClose={() => setIsModalOpen(false)} /> | ||
</> | ||
) | ||
} | ||
|
||
export default RequestInvitationCode |
5 changes: 5 additions & 0 deletions
5
...ponents/requestInvitationCode/invitationCodeRequestService/InvitationCodeRequest.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface InvitationCodeRequestData { | ||
name: string; | ||
email: string; | ||
message: string; | ||
} |
50 changes: 50 additions & 0 deletions
50
...stInvitationCode/invitationCodeRequestService/SentryInvitationCodeRequest.service.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import * as Sentry from "@sentry/react"; | ||
import { requestInvitationCode } from "./SentryInvitationCodeRequest.service"; | ||
import { InvitationError } from "../../../../error/commonErrors"; | ||
|
||
jest.mock("@sentry/react"); | ||
|
||
describe("requestInvitationCode", () => { | ||
beforeEach(() => { | ||
// GIVEN a fresh mock state | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it("should send feedback to Sentry with the correct data", async () => { | ||
// GIVEN the request data | ||
const requestData = { | ||
name: "John Doe", | ||
email: "[email protected]", | ||
message: "I want to try Compass", | ||
}; | ||
|
||
// WHEN requesting an invitation code | ||
await requestInvitationCode(requestData); | ||
|
||
// THEN expect Sentry.captureFeedback to be called with the correct data | ||
expect(Sentry.captureFeedback).toHaveBeenCalledWith({ | ||
name: requestData.name, | ||
email: requestData.email, | ||
message: `A user has requested an invitation code. Additional information: ${requestData.message}`, | ||
}); | ||
}); | ||
|
||
it("should throw an error if Sentry.captureFeedback fails", async () => { | ||
// GIVEN Sentry will throw an error | ||
const error = new Error("Sentry error"); | ||
(Sentry.captureFeedback as jest.Mock).mockImplementation(() => { | ||
throw error; | ||
}); | ||
|
||
// GIVEN the request data | ||
const requestData = { | ||
name: "John Doe", | ||
email: "[email protected]", | ||
message: "I want to try Compass", | ||
}; | ||
|
||
// WHEN requesting an invitation code AND it fails | ||
// THEN expect the error to be thrown | ||
expect(() => requestInvitationCode(requestData)).toThrow(new InvitationError(`Something went wrong while attempting to request new invitation for user with email ${requestData.email}`)); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
...requestInvitationCode/invitationCodeRequestService/SentryInvitationCodeRequest.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as Sentry from "@sentry/react"; | ||
import { InvitationCodeRequestData } from "./InvitationCodeRequest.types"; | ||
import { InvitationError } from "../../../../error/commonErrors"; | ||
|
||
export function requestInvitationCode(data: InvitationCodeRequestData) { | ||
// we currently use sentry to capture user feedback | ||
try { | ||
Sentry.captureFeedback({ | ||
name: data.name, | ||
email: data.email, | ||
message: `A user has requested an invitation code. Additional information: ${data.message}`, | ||
}); | ||
} catch (e) { | ||
throw new InvitationError(`Something went wrong while attempting to request new invitation for user with email ${data.email}`, e as Error); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...equestInvitationCodeFormModal.stories.tsx → ...equestInvitationCodeFormModal.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.