refactor: enhance onboarding logic and update default redirect path

This commit is contained in:
Abhimanyu Saharan
2026-02-09 22:20:19 +05:30
parent f8860bbc71
commit 6f76e430f4
6 changed files with 97 additions and 12 deletions

View File

@@ -0,0 +1,47 @@
import { describe, expect, it } from "vitest";
import { isOnboardingComplete } from "@/lib/onboarding";
describe("isOnboardingComplete", () => {
it("returns false when profile is missing", () => {
expect(isOnboardingComplete(null)).toBe(false);
expect(isOnboardingComplete(undefined)).toBe(false);
});
it("returns false when timezone is missing", () => {
expect(
isOnboardingComplete({
preferred_name: "Asha",
timezone: "",
}),
).toBe(false);
});
it("returns false when both name fields are missing", () => {
expect(
isOnboardingComplete({
name: " ",
preferred_name: " ",
timezone: "America/New_York",
}),
).toBe(false);
});
it("accepts preferred_name + timezone", () => {
expect(
isOnboardingComplete({
preferred_name: "Asha",
timezone: "America/New_York",
}),
).toBe(true);
});
it("accepts fallback name + timezone", () => {
expect(
isOnboardingComplete({
name: "Asha",
timezone: "America/New_York",
}),
).toBe(true);
});
});

View File

@@ -0,0 +1,13 @@
type OnboardingProfileLike = {
name?: string | null;
preferred_name?: string | null;
timezone?: string | null;
};
export function isOnboardingComplete(
profile: OnboardingProfileLike | null | undefined,
): boolean {
if (!profile) return false;
const resolvedName = profile.preferred_name?.trim() || profile.name?.trim();
return Boolean(resolvedName) && Boolean(profile.timezone?.trim());
}