Files
kandev/apps/backend/internal/agent/settings/controller/profile_contract_test.go
T
2026-09-25 10:31:58 +01:00

48 lines
2.0 KiB
Go

package controller
import (
"testing"
"github.com/kandev/kandev/internal/agent/settings/dto"
)
func TestProfileContractConversionsPreserveExplicitValues(t *testing.T) {
model := ""
autoApprove := false
cursorMCPAuthEnabled := false
flags := []dto.CLIFlagDTO{}
request := dto.ProfileUpdateRequest{
ID: "profile-1",
Model: &model,
AutoApprove: &autoApprove,
CursorMCPAuthEnabled: &cursorMCPAuthEnabled,
CLIFlags: &flags,
Force: true,
}
converted := UpdateProfileRequestFromDTO(request)
if converted.ID != request.ID || converted.Model == nil || *converted.Model != "" ||
converted.AutoApprove == nil || *converted.AutoApprove || converted.CursorMCPAuthEnabled == nil || *converted.CursorMCPAuthEnabled || converted.CLIFlags == nil ||
len(*converted.CLIFlags) != 0 || !converted.Force {
t.Fatalf("converted update = %#v, explicit values were not preserved", converted)
}
}
func TestProfileCreateContractConversionCopiesAllFields(t *testing.T) {
request := dto.ProfileCreateRequest{
AgentID: "agent-1", Name: "Profile", Model: "model", FallbackModel: "fallback",
AutoFallback: true, Mode: "plan", ConfigOptions: map[string]string{"x": "y"},
AllowIndexing: true, AutoApprove: true, CLIPassthrough: true,
CLIFlags: []dto.CLIFlagDTO{{Flag: "--verbose"}}, EnvVars: []dto.ProfileEnvVarDTO{{Key: "X", Value: "Y"}},
CommandPrefix: "prefix",
CursorMCPAuthEnabled: boolPointer(false),
}
converted := CreateProfileRequestFromDTO(request)
if converted.AgentID != request.AgentID || converted.Name != request.Name || converted.CommandPrefix != request.CommandPrefix ||
len(converted.CLIFlags) != 1 || len(converted.EnvVars) != 1 || !converted.AutoFallback || !converted.CLIPassthrough ||
converted.CursorMCPAuthEnabled == nil || *converted.CursorMCPAuthEnabled {
t.Fatalf("converted create = %#v, fields were not copied", converted)
}
}
func boolPointer(value bool) *bool { return &value }