AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
import { describe, expect, test } from "vitest";
import {
decideOnboardingRedirect,
shouldRedirectFromOnboarding,
} from "./helpers";
describe("shouldRedirectFromOnboarding", () => {
test("returns true once ONBOARDING_COMPLETE is completed", () => {
expect(
shouldRedirectFromOnboarding(["ONBOARDING_COMPLETE"], "/onboarding"),
).toBe(true);
});
test("returns false when ONBOARDING_COMPLETE is missing", () => {
expect(shouldRedirectFromOnboarding([], "/onboarding")).toBe(false);
});
test("does not redirect away from /onboarding/reset", () => {
expect(
shouldRedirectFromOnboarding(
["ONBOARDING_COMPLETE"],
"/onboarding/reset",
),
).toBe(false);
});
});
describe("decideOnboardingRedirect", () => {
// Defaults — most tests vary one bit at a time.
const base = {
isCompleted: false,
isOnOnboardingRoute: false,
isOnAuthRoute: false,
hasPendingAuthDeepLink: false,
};
test("pending deep link defers to the auth page (returns null)", () => {
// Both completed and incomplete users must yield — the auth page's
// `router.replace(nextUrl)` is in flight and we must not clobber it.
expect(
decideOnboardingRedirect({
...base,
isOnAuthRoute: true,
hasPendingAuthDeepLink: true,
}),
).toBeNull();
expect(
decideOnboardingRedirect({
...base,
isCompleted: true,
isOnAuthRoute: true,
hasPendingAuthDeepLink: true,
}),
).toBeNull();
});
test("incomplete user on any non-onboarding route is sent to /onboarding", () => {
// /signup, /login, /copilot, /library — all should funnel to /onboarding.
expect(decideOnboardingRedirect(base)).toBe("/onboarding");
expect(decideOnboardingRedirect({ ...base, isOnAuthRoute: true })).toBe(
"/onboarding",
);
});
test("incomplete user already on /onboarding stays put", () => {
expect(
decideOnboardingRedirect({ ...base, isOnOnboardingRoute: true }),
).toBeNull();
});
test("completed user on /onboarding is sent to /home", () => {
expect(
decideOnboardingRedirect({
...base,
isCompleted: true,
isOnOnboardingRoute: true,
}),
).toBe("/home");
});
test("completed user on /signup or /login is sent to /home", () => {
expect(
decideOnboardingRedirect({
...base,
isCompleted: true,
isOnAuthRoute: true,
}),
).toBe("/home");
});
test("completed user already on the product is left alone", () => {
// E.g., /copilot, /library — no redirect needed.
expect(decideOnboardingRedirect({ ...base, isCompleted: true })).toBeNull();
});
});