forked from baron/baron-sso
조직 연동 오류 해결
This commit is contained in:
@@ -68,6 +68,52 @@ func TestSanitizeLegacyUserMetadataRemovesClassificationFlags(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCanonicalizeLegacyUserStatuses(t *testing.T) {
|
||||
db := openBootstrapPostgresTestDB(t)
|
||||
if err := db.AutoMigrate(&domain.User{}); err != nil {
|
||||
t.Fatalf("failed to migrate users table: %v", err)
|
||||
}
|
||||
|
||||
users := []domain.User{
|
||||
{ID: "11000000-0000-0000-0000-000000000001", Email: "inactive@example.com", Name: "Inactive", Role: domain.RoleUser, Status: "inactive"},
|
||||
{ID: "11000000-0000-0000-0000-000000000002", Email: "leave@example.com", Name: "Leave", Role: domain.RoleUser, Status: "leave_of_absence"},
|
||||
{ID: "11000000-0000-0000-0000-000000000003", Email: "baron-only@example.com", Name: "Baron Only", Role: domain.RoleUser, Status: "baron_only"},
|
||||
{ID: "11000000-0000-0000-0000-000000000004", Email: "active@example.com", Name: "Active", Role: domain.RoleUser, Status: domain.UserStatusActive},
|
||||
}
|
||||
if err := db.Create(&users).Error; err != nil {
|
||||
t.Fatalf("failed to create users: %v", err)
|
||||
}
|
||||
|
||||
if err := CanonicalizeLegacyUserStatuses(db); err != nil {
|
||||
t.Fatalf("CanonicalizeLegacyUserStatuses returned error: %v", err)
|
||||
}
|
||||
if err := CanonicalizeLegacyUserStatuses(db); err != nil {
|
||||
t.Fatalf("CanonicalizeLegacyUserStatuses must be idempotent: %v", err)
|
||||
}
|
||||
|
||||
got := map[string]string{}
|
||||
var loaded []domain.User
|
||||
if err := db.Find(&loaded).Error; err != nil {
|
||||
t.Fatalf("failed to load users: %v", err)
|
||||
}
|
||||
for _, user := range loaded {
|
||||
got[user.Email] = user.Status
|
||||
}
|
||||
|
||||
if got["inactive@example.com"] != domain.UserStatusPreboarding {
|
||||
t.Fatalf("inactive status = %q, want %q", got["inactive@example.com"], domain.UserStatusPreboarding)
|
||||
}
|
||||
if got["leave@example.com"] != domain.UserStatusTemporaryLeave {
|
||||
t.Fatalf("leave status = %q, want %q", got["leave@example.com"], domain.UserStatusTemporaryLeave)
|
||||
}
|
||||
if got["baron-only@example.com"] != domain.UserStatusBaronGuest {
|
||||
t.Fatalf("baron_only status = %q, want %q", got["baron-only@example.com"], domain.UserStatusBaronGuest)
|
||||
}
|
||||
if got["active@example.com"] != domain.UserStatusActive {
|
||||
t.Fatalf("active status = %q, want %q", got["active@example.com"], domain.UserStatusActive)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunSanitizesLegacyUserMetadata(t *testing.T) {
|
||||
db := openBootstrapPostgresTestDB(t)
|
||||
if err := db.AutoMigrate(&domain.User{}); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user