Skip to content

Commit

Permalink
[SDK] Fix: Custom auth profile label (#5660)
Browse files Browse the repository at this point in the history
<!-- start pr-codex -->

## PR-Codex overview
This PR focuses on improving the display of linked profiles in the `LinkedProfilesScreen` component by correctly handling the "Custom Auth" profile type and enhancing unit tests for various profile types.

### Detailed summary
- Updated the label for the "Custom Auth" profile type to "Custom Profile".
- Added unit tests for various profile types including email, google, phone, wallet address, cognito, custom_auth_endpoint, and unknown types.
- Ensured guest profiles are not displayed.

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}`

<!-- end pr-codex -->
  • Loading branch information
gregfromstl committed Dec 10, 2024
1 parent dcd5822 commit d5a68c8
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-birds-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Fix: Correctly cleans the "Custom Auth" profile type label
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { render, screen } from "../../../../../../test/src/react-render.js";
import { useSocialProfiles } from "../../../../core/social/useSocialProfiles.js";
import { useProfiles } from "../../../hooks/wallets/useProfiles.js";
import { LinkedProfilesScreen } from "./LinkedProfilesScreen.jsx";

// Mock the hooks
vi.mock("../../../hooks/wallets/useProfiles");
vi.mock("../../../../core/social/useSocialProfiles");
vi.mock("../../components/Img", () => ({
Img: () => <div data-testid="mock-img">Mock Image</div>,
}));

describe("LinkedProfilesScreen", () => {
const mockClient = {
clientId: "test-client-id",
secretKey: undefined,
};

const mockProps = {
onBack: vi.fn(),
setScreen: vi.fn(),
locale: {
manageWallet: {
linkedProfiles: "Linked Profiles",
linkProfile: "Link Profile",
},
// biome-ignore lint/suspicious/noExplicitAny: Mocking data
} as any,
client: mockClient,
};

beforeEach(() => {
vi.mocked(useSocialProfiles).mockReturnValue({
data: undefined,
isLoading: false,
// biome-ignore lint/suspicious/noExplicitAny: Mocking data
} as any);
});

describe("getProfileDisplayName", () => {
it("should display email for email profile type", () => {
vi.mocked(useProfiles).mockReturnValue({
data: [{ type: "email", details: { email: "test@example.com" } }],
isLoading: false,
// biome-ignore lint/suspicious/noExplicitAny: Mocking data
} as any);

render(<LinkedProfilesScreen {...mockProps} />);
expect(screen.getByText("test@example.com")).toBeInTheDocument();
});

it("should display email for google profile type", () => {
vi.mocked(useProfiles).mockReturnValue({
data: [{ type: "google", details: { email: "google@example.com" } }],
isLoading: false,
// biome-ignore lint/suspicious/noExplicitAny: Mocking data
} as any);

render(<LinkedProfilesScreen {...mockProps} />);
expect(screen.getByText("google@example.com")).toBeInTheDocument();
});

it("should display phone number for phone profile type", () => {
vi.mocked(useProfiles).mockReturnValue({
data: [{ type: "phone", details: { phone: "+1234567890" } }],
isLoading: false,
// biome-ignore lint/suspicious/noExplicitAny: Mocking data
} as any);

render(<LinkedProfilesScreen {...mockProps} />);
expect(screen.getByText("+1234567890")).toBeInTheDocument();
});

it("should display shortened address when address is present", () => {
vi.mocked(useProfiles).mockReturnValue({
data: [
{
type: "wallet",
details: { address: "0x1234567890abcdef1234567890abcdef12345678" },
},
],
isLoading: false,
// biome-ignore lint/suspicious/noExplicitAny: Mocking data
} as any);

render(<LinkedProfilesScreen {...mockProps} />);
expect(screen.getByText("0x123456...345678")).toBeInTheDocument();
});

it("should display email for cognito profile type", () => {
vi.mocked(useProfiles).mockReturnValue({
data: [{ type: "cognito", details: { email: "cognito@example.com" } }],
isLoading: false,
// biome-ignore lint/suspicious/noExplicitAny: Mocking data
} as any);

render(<LinkedProfilesScreen {...mockProps} />);
expect(screen.getByText("cognito@example.com")).toBeInTheDocument();
});

it("should display Custom Profile for custom_auth_endpoint", () => {
vi.mocked(useProfiles).mockReturnValue({
data: [{ type: "Custom_auth_endpoint", details: {} }],
isLoading: false,
// biome-ignore lint/suspicious/noExplicitAny: Mocking data
} as any);

render(<LinkedProfilesScreen {...mockProps} />);
expect(screen.getByText("Custom Profile")).toBeInTheDocument();
});

it("should capitalize unknown profile types", () => {
vi.mocked(useProfiles).mockReturnValue({
data: [{ type: "unknown", details: {} }],
isLoading: false,
// biome-ignore lint/suspicious/noExplicitAny: Mocking data
} as any);

render(<LinkedProfilesScreen {...mockProps} />);
expect(screen.getByText("Unknown")).toBeInTheDocument();
});

it("should not display guest profiles", () => {
vi.mocked(useProfiles).mockReturnValue({
data: [{ type: "guest", details: {} }],
isLoading: false,
// biome-ignore lint/suspicious/noExplicitAny: Mocking data
} as any);

render(<LinkedProfilesScreen {...mockProps} />);
expect(screen.queryByText("Guest")).not.toBeInTheDocument();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ function getProfileDisplayName(profile: Profile) {
case (profile.type as string) === "cognito" &&
profile.details.email !== undefined:
return profile.details.email;
case (profile.type as string).toLowerCase() === "custom_auth_endpoint":
return "Custom Profile";
default:
return profile.type.slice(0, 1).toUpperCase() + profile.type.slice(1);
}
Expand Down

0 comments on commit d5a68c8

Please sign in to comment.