Initial commit of Descrybe v2 without local scratch artifacts.
Drop one-shot tmp/axe scripts and agent i18n scratch so the Gitea tree is deployable.
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/descrybe/descrybe-v2/apps/api/internal/billing"
|
||||
)
|
||||
|
||||
func TestCompanyDisplayLabel(t *testing.T) {
|
||||
t.Parallel()
|
||||
got := companyDisplayLabel("A1 Slovenija", billing.A1LegacyCompanyID)
|
||||
if got != "A1 Slovenija" {
|
||||
t.Fatalf("got %q", got)
|
||||
}
|
||||
got = companyDisplayLabel("Local Demo Co", billing.A1LegacyCompanyID)
|
||||
if got != "A1 Slovenija" {
|
||||
t.Fatalf("legacy rename alias got %q", got)
|
||||
}
|
||||
got = companyDisplayLabel("Other Co", "")
|
||||
if got != "Other Co" {
|
||||
t.Fatalf("got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnrichSwitchableUserLabels(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
demo := switchableUserRow{Email: "demo@descrybe.local", CompanyName: "A1 Slovenija"}
|
||||
enrichSwitchableUser(&demo, billing.A1LegacyCompanyID)
|
||||
if !demo.IsDemoAdmin || demo.Label != "Demo admin" {
|
||||
t.Fatalf("demo: %+v", demo)
|
||||
}
|
||||
if demo.CompanyLabel != "A1 Slovenija" {
|
||||
t.Fatalf("company label: %q", demo.CompanyLabel)
|
||||
}
|
||||
|
||||
legacyID := "user_30AqqJ8uepxvPUzDSqy81U5w6Ll"
|
||||
name := "A1 user"
|
||||
primary := switchableUserRow{
|
||||
Email: "a1-primary@descrybe.local",
|
||||
Name: &name,
|
||||
LegacyUserID: &legacyID,
|
||||
CompanyName: "A1 Slovenija",
|
||||
}
|
||||
enrichSwitchableUser(&primary, billing.A1LegacyCompanyID)
|
||||
if !primary.IsPrimaryA1 {
|
||||
t.Fatalf("expected primary A1")
|
||||
}
|
||||
if primary.Label != "A1 · …81U5w6Ll" {
|
||||
t.Fatalf("primary label: %q", primary.Label)
|
||||
}
|
||||
if primary.Subtitle != "A1 Slovenija · user_30AqqJ8uepxvPUzDSqy81U5w6Ll" {
|
||||
t.Fatalf("primary subtitle: %q", primary.Subtitle)
|
||||
}
|
||||
|
||||
// Fallback path: legacy synthetic email still maps via Clerk id.
|
||||
legacyEmailPrimary := switchableUserRow{
|
||||
Email: "user_30aqqj8uepxvpuzdsqy81u5w6ll@legacy.local",
|
||||
LegacyUserID: &legacyID,
|
||||
CompanyName: "A1 Slovenija",
|
||||
}
|
||||
enrichSwitchableUser(&legacyEmailPrimary, billing.A1LegacyCompanyID)
|
||||
if !legacyEmailPrimary.IsPrimaryA1 {
|
||||
t.Fatalf("expected primary via legacy clerk id")
|
||||
}
|
||||
if legacyEmailPrimary.Label != "A1 · …81U5w6Ll" {
|
||||
t.Fatalf("legacy primary label: %q", legacyEmailPrimary.Label)
|
||||
}
|
||||
|
||||
otherID := "user_2tJxuYMnKOx8u9CrMvNA9sU2QMs"
|
||||
other := switchableUserRow{
|
||||
Email: "user_2tjxuymnkox8u9crmvna9su2qms@legacy.local",
|
||||
LegacyUserID: &otherID,
|
||||
CompanyName: "A1 Slovenija",
|
||||
}
|
||||
enrichSwitchableUser(&other, billing.A1LegacyCompanyID)
|
||||
if other.IsPrimaryA1 || other.IsDemoAdmin {
|
||||
t.Fatalf("other should be plain A1 member: %+v", other)
|
||||
}
|
||||
if other.Label != "A1 · …A9sU2QMs" {
|
||||
t.Fatalf("other label: %q", other.Label)
|
||||
}
|
||||
if other.Subtitle != "A1 Slovenija · user_2tJxuYMnKOx8u9CrMvNA9sU2QMs" {
|
||||
t.Fatalf("other subtitle: %q", other.Subtitle)
|
||||
}
|
||||
|
||||
// Non-A1 company with a clerk id must not get A1 labels.
|
||||
nonA1 := switchableUserRow{
|
||||
Email: "user_2tjxuymnkox8u9crmvna9su2qms@legacy.local",
|
||||
LegacyUserID: &otherID,
|
||||
CompanyName: "Other Co",
|
||||
}
|
||||
enrichSwitchableUser(&nonA1, "")
|
||||
if nonA1.IsPrimaryA1 || nonA1.Label == "A1 · …A9sU2QMs" {
|
||||
t.Fatalf("non-A1 company should not use A1 label: %+v", nonA1)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user