forked from baron/baron-sso
test code 수정
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"baron-sso-backend/internal/domain"
|
||||
"baron-sso-backend/internal/service"
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http/httptest"
|
||||
@@ -32,13 +32,29 @@ func (m *MockKratosAdminForUser) ListIdentities(ctx context.Context) ([]service.
|
||||
return args.Get(0).([]service.KratosIdentity), args.Error(1)
|
||||
}
|
||||
|
||||
// Note: In reality, KratosAdminService might not be an interface.
|
||||
// If it's a struct, we'd need to mock the underlying client or use an interface.
|
||||
// For the sake of this test, let's assume we can mock it or use a wrapper.
|
||||
func (m *MockKratosAdminForUser) FindIdentityIDByIdentifier(ctx context.Context, identifier string) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (m *MockKratosAdminForUser) UpdateIdentity(ctx context.Context, identityID string, traits map[string]interface{}, state string) (*service.KratosIdentity, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *MockKratosAdminForUser) UpdateIdentityPassword(ctx context.Context, identityID, newPassword string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockKratosAdminForUser) DeleteIdentity(ctx context.Context, identityID string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestUserHandler_CreateUser_InvalidEmail(t *testing.T) {
|
||||
app := fiber.New()
|
||||
h := &UserHandler{}
|
||||
mockKratos := new(MockKratosAdminForUser)
|
||||
h := &UserHandler{
|
||||
KratosAdmin: mockKratos,
|
||||
OryProvider: &service.OryProvider{}, // Assuming it's a struct and non-nil is enough for this check
|
||||
}
|
||||
app.Post("/users", h.CreateUser)
|
||||
|
||||
payload := map[string]string{
|
||||
@@ -54,8 +70,8 @@ func TestUserHandler_CreateUser_InvalidEmail(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUserHandler_GetUser_Forbidden(t *testing.T) {
|
||||
app := fiber.New()
|
||||
mockKratos := new(MockKratosAdminForUser)
|
||||
// app := fiber.New()
|
||||
// mockKratos := new(MockKratosAdminForUser)
|
||||
// We need a way to inject mockKratos into UserHandler.
|
||||
// Since UserHandler uses *service.KratosAdminService (struct),
|
||||
// we'd typically use an interface here.
|
||||
|
||||
Reference in New Issue
Block a user