/** * A sign-in screen in Arabic answered a mistyped password with «Invalid login * credentials», in English, in a red box. Worse, Supabase uses that same * sentence for an address it never confirmed - so the one message a person saw * covered two entirely different problems and named neither. */ import { describe, expect, it } from "vitest"; import { inArabic } from "./authErrors"; const arabic = /[ء-ي]/; function asError(message: string, code?: string) { const e = new Error(message) as Error & { code?: string }; if (code) e.code = code; return e; } describe("inArabic", () => { it("translates the message the live screen was showing", () => { expect(inArabic(asError("Invalid login credentials"))).toBe( "البريد أو كلمة المرور غير صحيحة.", ); }); it("prefers the code, because the English wording moves between releases", () => { const changed = asError("Some new wording nobody predicted", "invalid_credentials"); expect(inArabic(changed)).toBe("البريد أو كلمة المرور غير صحيحة."); }); it("keeps an unconfirmed address distinct from a wrong password", () => { expect(inArabic(asError("Email not confirmed"))).not.toBe( inArabic(asError("Invalid login credentials")), ); }); it("answers every error it knows in Arabic", () => { for (const message of [ "Invalid login credentials", "User already registered", "Password should be at least 8 characters", "Email rate limit exceeded", "Token has expired or is invalid", "Unable to validate email address: invalid format", "Failed to fetch", ]) { expect(inArabic(asError(message)), message).toMatch(arabic); } }); it("shows the English rather than swallowing an error it does not know", () => { expect(inArabic(asError("something entirely new"))).toBe("something entirely new"); }); it("says nothing when nothing went wrong", () => { expect(inArabic(null)).toBe(""); }); });