Merge pull request #1131 from trheyi/main
Refactor error handling in category retrieval test and enhance time f…
This commit is contained in:
commit
2a8aafb64f
2 changed files with 17 additions and 4 deletions
19
job/data.go
19
job/data.go
|
|
@ -684,8 +684,9 @@ func mapToStruct(m maps.MapStr, v interface{}) error {
|
|||
// Clean up the map data to handle database type conversions
|
||||
cleanMap := make(map[string]interface{})
|
||||
for key, value := range m {
|
||||
// Convert numeric values to proper types for boolean fields
|
||||
if key == "enabled" || key == "system" || key == "readonly" {
|
||||
switch key {
|
||||
case "enabled", "system", "readonly":
|
||||
// Convert numeric values to proper types for boolean fields
|
||||
switch val := value.(type) {
|
||||
case int:
|
||||
cleanMap[key] = val != 0
|
||||
|
|
@ -698,7 +699,19 @@ func mapToStruct(m maps.MapStr, v interface{}) error {
|
|||
default:
|
||||
cleanMap[key] = value
|
||||
}
|
||||
} else {
|
||||
case "created_at", "updated_at", "next_run_at", "last_run_at", "scheduled_at", "started_at", "finished_at", "timestamp":
|
||||
// Handle time fields - convert database time format to RFC3339
|
||||
if str, ok := value.(string); ok && str != "" {
|
||||
// Try to parse database time format "2006-01-02 15:04:05"
|
||||
if t, err := time.Parse("2006-01-02 15:04:05", str); err == nil {
|
||||
cleanMap[key] = t.Format(time.RFC3339)
|
||||
} else {
|
||||
cleanMap[key] = value
|
||||
}
|
||||
} else {
|
||||
cleanMap[key] = value
|
||||
}
|
||||
default:
|
||||
cleanMap[key] = value
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ func TestCategoryCRUD(t *testing.T) {
|
|||
t.Fatalf("Failed to get categories: %v", err)
|
||||
}
|
||||
if len(categories) == 0 {
|
||||
t.Error("Expected to find the test category")
|
||||
t.Fatal("Expected to find the test category")
|
||||
}
|
||||
if categories[0].Name != testCategory.Name {
|
||||
t.Errorf("Expected category name '%s', got '%s'", testCategory.Name, categories[0].Name)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue