package tests import ( "encoding/json" "kontor-api-gin/internal/helpers" "testing" ) func TestMultiFormatTimeUnmarshal(t *testing.T) { tests := []struct { name string input string wantErr bool want string // Expected time string for comparison }{ { name: "Date Only", input: `"2005-04-01"`, wantErr: false, want: "2005-04-01 00:00:00 +0000 UTC", }, { name: "KontorTime Format", input: `"2026-04-30T13:54:26.334Z"`, wantErr: false, want: "2026-04-30 13:54:26.334 +0000 UTC", }, { name: "Null Value", input: `null`, wantErr: false, want: "", // Zero time }, { name: "Invalid Format", input: `"not-a-date"`, wantErr: true, want: "", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var m helpers.KontorTime err := json.Unmarshal([]byte(tt.input), &m) if (err != nil) != tt.wantErr { t.Errorf("UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr) return } if !tt.wantErr && !m.Time.IsZero() && m.Time.String() != tt.want { t.Errorf("UnmarshalJSON() = %v, want %v", m.Time.String(), tt.want) } }) } }