diff --git a/time_enties.go b/time_enties.go index 90395b6..26d6a5e 100644 --- a/time_enties.go +++ b/time_enties.go @@ -36,9 +36,14 @@ type TimeEntryCreator struct { // TimeEntry mapping to the mite return type type TimeEntry struct { - TimeEntryCreator - ID uint64 `json:"id"` - Locked bool `json:"locked"` + ID uint64 `json:"id"` + DateAt Time `json:"date_at"` + Minutes uint64 `json:"minutes"` + Note string `json:"note"` + UserID uint64 `json:"user_id"` + ProjectID uint64 `json:"project_id"` + ServiceID uint64 `json:"service_id"` + Locked bool `json:"locked"` // Revenue bool `json:"locked"` Billable bool `json:"billable"` HourlyRate uint64 `json:"hourly_rate"` diff --git a/time_enties_test.go b/time_enties_test.go index 70b2dca..372ff75 100644 --- a/time_enties_test.go +++ b/time_enties_test.go @@ -1,6 +1,7 @@ package mite_test import ( + "fmt" "os" "testing" "time" @@ -65,3 +66,50 @@ func TestCreateDeleteTimeEntry(t *testing.T) { t.Error(errDel) } } + +func TestCreateUpdateDeleteTimeEntry(t *testing.T) { + username, okUser := os.LookupEnv("MITE_USER") + team, okAddr := os.LookupEnv("MITE_TEAM") + key, okKey := os.LookupEnv("MITE_APIKEY") + if !okAddr || !okUser || !okKey { + t.Errorf("username=%s, team=%s and key=%s are required", username, team, key) + t.FailNow() + } + + m := mite.NewMiteAPI(username, team, key, "test@go-mite") + + newEntry := &mite.TimeEntryCreator{ + DateAt: mite.Time{time.Now()}, + Minutes: 60, + Note: "TEST NOTE CREATED BY GO-MITE API. PLEASE REMOVE", + } + + entry, errEntry := m.CreateTimeEntry(newEntry) + if errEntry != nil { + t.Error(errEntry) + } + + t.Logf("Created entry: %d", entry.ID) + + errUpdate := m.UpdateTimeEntry(entry.ID, &mite.TimeEntry{ + Note: "Updated note", + Minutes: 66, + }) + if errUpdate != nil { + t.Error(errUpdate) + } + + updated, errGet := m.GetTimeEntry(entry.ID) + if errGet != nil { + t.Error(errGet) + } + + if updated.Minutes != 66 || updated.Note != "Updated note" { + t.Error(fmt.Errorf("Update failed values did not change")) + } + + errDel := m.DeleteTimeEntry(entry.ID) + if errDel != nil { + t.Error(errDel) + } +}