package services import ( "testing" "nearle/models" ) /* An account that is created perfectly and cannot sign in. `weblogin` matches `WHERE authname = ? AND configid = ?`. A form that sends an email and a name — which is every form in this console — produces a row with an empty authname and a configid of 0, so the sign-in query matches nothing and answers "we do not recognise that email". Observed on 1 Sep 2026: a merchant added their own administrator through the console, saw it succeed, saw it listed, and was refused at the login screen. */ func TestANewAccountCanActuallySignIn(t *testing.T) { ready := PrepareNewAccount(models.User{Email: "thiruomart@gmail.com"}) if ready.Authname != "thiruomart@gmail.com" { t.Errorf("authname was not derived from the email: %q", ready.Authname) } if ready.Configid != ConsoleConfigID { t.Errorf("configid = %d, want %d — 0 matches no console account", ready.Configid, ConsoleConfigID) } } // A caller with its own sign-in name keeps it. Deriving from the email is a // fallback for forms that do not ask, not a rule that overwrites an answer. func TestAnExplicitSignInNameIsKept(t *testing.T) { ready := PrepareNewAccount(models.User{Authname: "suriya.nsn", Email: "suriya@example.com"}) if ready.Authname != "suriya.nsn" { t.Errorf("an explicit authname was overwritten with %q", ready.Authname) } } func TestAnExplicitConfigIsKept(t *testing.T) { ready := PrepareNewAccount(models.User{Email: "a@b.com", Configid: 4}) if ready.Configid != 4 { t.Errorf("configid = %d, want the caller's 4", ready.Configid) } } // Whitespace around a pasted email would become an authname nothing can match — // the same invisible failure, one space wide. func TestASurroundingSpaceDoesNotBecomePartOfTheSignInName(t *testing.T) { ready := PrepareNewAccount(models.User{Email: " thiru@omart.com "}) if ready.Authname != "thiru@omart.com" { t.Errorf("authname = %q, want it trimmed", ready.Authname) } } // An account with no email at all cannot be given a sign-in name, and must not // be given a blank one that looks like it has been handled. func TestNoEmailLeavesTheSignInNameEmpty(t *testing.T) { ready := PrepareNewAccount(models.User{}) if ready.Authname != "" { t.Errorf("authname = %q, want empty", ready.Authname) } }