diff --git a/mite/mite_test.go b/mite/mite_test.go new file mode 100644 index 0000000..517d163 --- /dev/null +++ b/mite/mite_test.go @@ -0,0 +1,46 @@ +package mite + +import ( + "encoding/json" + "testing" +) + +func TestUnmarshalTimeTracking(t *testing.T) { + trackerOn := []byte(` +{ + "tracker": { + "tracking_time_entry": { + "id": 36135321, + "minutes": 247, + "since": "2015-10-15T17:05:04+02:00" + } + } + }`) + trackerOff := []byte(`{ + "tracker": {} +}`) + off := apiTimeTrackerEntry{} + err := json.Unmarshal(trackerOff, &off) + if err != nil { + t.Error(err) + } else { + if off.TimeTrackerHolder.TrackingTimeEntry != nil { + t.Error("expected nil, but is not") + } + } + + on := apiTimeTrackerEntry{} + err = json.Unmarshal(trackerOn, &on) + if err != nil { + t.Error(err) + } else { + if on.TimeTrackerHolder.TrackingTimeEntry == nil { + t.Error("expected note nil, but is not") + } else { + if on.TimeTrackerHolder.TrackingTimeEntry.ID != 36135321 { + t.Error("bad unmarshal?") + } + } + } + +}