forked from baron/baron-sso
fix(backend): fix UserGroup model and NewTenantService signature in bootstrap and tests
This commit is contained in:
@@ -31,8 +31,9 @@ func SeedTenants(db *gorm.DB) error {
|
|||||||
slog.Info("[Bootstrap] Seeding initial tenants...")
|
slog.Info("[Bootstrap] Seeding initial tenants...")
|
||||||
repo := repository.NewTenantRepository(db)
|
repo := repository.NewTenantRepository(db)
|
||||||
userRepo := repository.NewUserRepository(db)
|
userRepo := repository.NewUserRepository(db)
|
||||||
|
userGroupRepo := repository.NewUserGroupRepository(db)
|
||||||
outboxRepo := repository.NewKetoOutboxRepository(db)
|
outboxRepo := repository.NewKetoOutboxRepository(db)
|
||||||
svc := service.NewTenantService(repo, userRepo, outboxRepo)
|
svc := service.NewTenantService(repo, userRepo, userGroupRepo, outboxRepo)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
for _, config := range defaultTenants {
|
for _, config := range defaultTenants {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ type UserGroup struct {
|
|||||||
TenantID string `gorm:"type:uuid;index;not null" json:"tenantId"`
|
TenantID string `gorm:"type:uuid;index;not null" json:"tenantId"`
|
||||||
ParentID *string `gorm:"type:uuid;index" json:"parentId,omitempty"` // 상위 조직 ID
|
ParentID *string `gorm:"type:uuid;index" json:"parentId,omitempty"` // 상위 조직 ID
|
||||||
Name string `gorm:"not null" json:"name"`
|
Name string `gorm:"not null" json:"name"`
|
||||||
|
Slug string `gorm:"index" json:"slug"` // 추가
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
UnitType string `json:"unitType"` // 부, 국, 팀, 셀 등
|
UnitType string `json:"unitType"` // 부, 국, 팀, 셀 등
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
func TestTenantService_RegisterTenant_DuplicateSlug(t *testing.T) {
|
func TestTenantService_RegisterTenant_DuplicateSlug(t *testing.T) {
|
||||||
mockRepo := new(MockTenantRepoForSvc)
|
mockRepo := new(MockTenantRepoForSvc)
|
||||||
svc := NewTenantService(mockRepo, nil, nil)
|
svc := NewTenantService(mockRepo, nil, nil, nil)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
slug := "duplicate-slug"
|
slug := "duplicate-slug"
|
||||||
@@ -28,7 +28,7 @@ func TestTenantService_RegisterTenant_DuplicateSlug(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestTenantService_RegisterTenant_InvalidSlug(t *testing.T) {
|
func TestTenantService_RegisterTenant_InvalidSlug(t *testing.T) {
|
||||||
svc := NewTenantService(nil, nil, nil)
|
svc := NewTenantService(nil, nil, nil, nil)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
// Case 1: Too short
|
// Case 1: Too short
|
||||||
@@ -41,7 +41,7 @@ func TestTenantService_RegisterTenant_InvalidSlug(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestTenantService_RequestRegistration_EmailMismatch(t *testing.T) {
|
func TestTenantService_RequestRegistration_EmailMismatch(t *testing.T) {
|
||||||
svc := NewTenantService(nil, nil, nil)
|
svc := NewTenantService(nil, nil, nil, nil)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
// admin email domain (gmail.com) != tenant domain (company.com)
|
// admin email domain (gmail.com) != tenant domain (company.com)
|
||||||
@@ -53,7 +53,7 @@ func TestTenantService_RequestRegistration_EmailMismatch(t *testing.T) {
|
|||||||
|
|
||||||
func TestTenantService_ApproveTenant_NotFound(t *testing.T) {
|
func TestTenantService_ApproveTenant_NotFound(t *testing.T) {
|
||||||
mockRepo := new(MockTenantRepoForSvc)
|
mockRepo := new(MockTenantRepoForSvc)
|
||||||
svc := NewTenantService(mockRepo, nil, nil)
|
svc := NewTenantService(mockRepo, nil, nil, nil)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
id := "non-existent-id"
|
id := "non-existent-id"
|
||||||
@@ -67,7 +67,7 @@ func TestTenantService_ApproveTenant_NotFound(t *testing.T) {
|
|||||||
|
|
||||||
func TestTenantService_GetTenantByDomain_Inactive(t *testing.T) {
|
func TestTenantService_GetTenantByDomain_Inactive(t *testing.T) {
|
||||||
mockRepo := new(MockTenantRepoForSvc)
|
mockRepo := new(MockTenantRepoForSvc)
|
||||||
svc := NewTenantService(mockRepo, nil, nil)
|
svc := NewTenantService(mockRepo, nil, nil, nil)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
domainName := "inactive.com"
|
domainName := "inactive.com"
|
||||||
@@ -88,7 +88,7 @@ func TestTenantService_ApproveTenant_UserNotFound(t *testing.T) {
|
|||||||
mockUserRepo := new(MockUserRepoForTenant)
|
mockUserRepo := new(MockUserRepoForTenant)
|
||||||
mockOutbox := new(MockKetoOutboxRepositoryShared)
|
mockOutbox := new(MockKetoOutboxRepositoryShared)
|
||||||
|
|
||||||
svc := NewTenantService(mockRepo, mockUserRepo, mockOutbox)
|
svc := NewTenantService(mockRepo, mockUserRepo, nil, mockOutbox)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
tenantID := "t1"
|
tenantID := "t1"
|
||||||
adminEmail := "notfound@tenant.com"
|
adminEmail := "notfound@tenant.com"
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ func (m *MockUserRepoForTenant) CountByCompanyCodes(ctx context.Context, codes [
|
|||||||
func TestTenantService_RegisterTenant_AutoVerify(t *testing.T) {
|
func TestTenantService_RegisterTenant_AutoVerify(t *testing.T) {
|
||||||
mockRepo := new(MockTenantRepoForSvc)
|
mockRepo := new(MockTenantRepoForSvc)
|
||||||
mockOutbox := new(MockKetoOutboxRepositoryShared)
|
mockOutbox := new(MockKetoOutboxRepositoryShared)
|
||||||
svc := NewTenantService(mockRepo, nil, mockOutbox)
|
svc := NewTenantService(mockRepo, nil, nil, mockOutbox)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
name := "New Tenant"
|
name := "New Tenant"
|
||||||
@@ -172,7 +172,7 @@ func TestTenantService_RegisterTenant_AutoVerify(t *testing.T) {
|
|||||||
func TestTenantService_RegisterTenant_WithCreator(t *testing.T) {
|
func TestTenantService_RegisterTenant_WithCreator(t *testing.T) {
|
||||||
mockRepo := new(MockTenantRepoForSvc)
|
mockRepo := new(MockTenantRepoForSvc)
|
||||||
mockOutbox := new(MockKetoOutboxRepositoryShared)
|
mockOutbox := new(MockKetoOutboxRepositoryShared)
|
||||||
svc := NewTenantService(mockRepo, nil, mockOutbox)
|
svc := NewTenantService(mockRepo, nil, nil, mockOutbox)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
name := "Creator Tenant"
|
name := "Creator Tenant"
|
||||||
@@ -213,7 +213,7 @@ func TestTenantService_RegisterTenant_WithCreator(t *testing.T) {
|
|||||||
func TestTenantService_RequestRegistration_NoVerify(t *testing.T) {
|
func TestTenantService_RequestRegistration_NoVerify(t *testing.T) {
|
||||||
mockRepo := new(MockTenantRepoForSvc)
|
mockRepo := new(MockTenantRepoForSvc)
|
||||||
mockOutbox := new(MockKetoOutboxRepositoryShared)
|
mockOutbox := new(MockKetoOutboxRepositoryShared)
|
||||||
svc := NewTenantService(mockRepo, nil, mockOutbox)
|
svc := NewTenantService(mockRepo, nil, nil, mockOutbox)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
name := "Public Tenant"
|
name := "Public Tenant"
|
||||||
@@ -238,7 +238,7 @@ func TestTenantService_ApproveTenant_SyncAdmin(t *testing.T) {
|
|||||||
mockKeto := new(MockKetoSvcForTenant)
|
mockKeto := new(MockKetoSvcForTenant)
|
||||||
mockOutbox := new(MockKetoOutboxRepositoryShared)
|
mockOutbox := new(MockKetoOutboxRepositoryShared)
|
||||||
|
|
||||||
svc := NewTenantService(mockRepo, mockUserRepo, mockOutbox)
|
svc := NewTenantService(mockRepo, mockUserRepo, nil, mockOutbox)
|
||||||
svc.SetKetoService(mockKeto)
|
svc.SetKetoService(mockKeto)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
@@ -275,7 +275,7 @@ func TestTenantService_ApproveTenant_SyncAdmin(t *testing.T) {
|
|||||||
|
|
||||||
func TestTenantService_ListTenants(t *testing.T) {
|
func TestTenantService_ListTenants(t *testing.T) {
|
||||||
mockRepo := new(MockTenantRepoForSvc)
|
mockRepo := new(MockTenantRepoForSvc)
|
||||||
svc := NewTenantService(mockRepo, nil, nil)
|
svc := NewTenantService(mockRepo, nil, nil, nil)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
tenants := []domain.Tenant{{ID: "t1", Name: "Tenant 1"}}
|
tenants := []domain.Tenant{{ID: "t1", Name: "Tenant 1"}}
|
||||||
|
|||||||
Reference in New Issue
Block a user