Files
loki/scripts/test/onboarding.ts
T
g-butandCursor ec6f423b0f feat(infra): Postgres portability, Oracle cutover scripts, and DB kill-switch essay
Vendor-neutral DATABASE_URL helpers, dump/restore/sync tooling, and one-command
Oracle migration after a single console VM step. Publishes the studio-stack
thoughts article and hardens build (dynamic layout, resilient sitemap).

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-23 11:24:20 +02:00

46 lines
1.3 KiB
TypeScript

/**
* Inline self-tests for onboarding helpers.
* Run: npm run test:onboarding
*/
import {
suggestUsername,
hasValidUsername,
isOnboardingComplete,
} from "@/lib/onboarding";
function assert(condition: boolean, message: string): void {
if (!condition) throw new Error(message);
}
function runTests(): void {
let passed = 0;
const check = (label: string, fn: () => void) => {
fn();
passed += 1;
console.log(` ✓ ${label}`);
};
check("suggestUsername from display name", () => {
assert(suggestUsername("Jane Doe", null) === "jane-doe", "expected jane-doe");
});
check("suggestUsername from email", () => {
assert(suggestUsername(null, "builder@example.com") === "builder", "expected builder");
});
check("hasValidUsername rejects short handles", () => {
assert(!hasValidUsername("a"), "single char invalid");
assert(hasValidUsername("ab"), "two chars valid");
});
check("isOnboardingComplete requires username and timestamp", () => {
assert(!isOnboardingComplete({ username: "you", onboardedAt: null }), "needs onboardedAt");
assert(!isOnboardingComplete({ username: null, onboardedAt: new Date() }), "needs username");
assert(isOnboardingComplete({ username: "you", onboardedAt: new Date() }), "complete");
});
console.log(`\n${passed}/${passed} passed`);
}
runTests();