Skip to content

Commit

Permalink
added update time entries test
Browse files Browse the repository at this point in the history
  • Loading branch information
gosticks committed Feb 28, 2019
1 parent ca7ee35 commit 340391f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
11 changes: 8 additions & 3 deletions time_enties.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
48 changes: 48 additions & 0 deletions time_enties_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mite_test

import (
"fmt"
"os"
"testing"
"time"
Expand Down Expand Up @@ -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)
}
}

0 comments on commit 340391f

Please sign in to comment.