Skip to content

Commit f045d51

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents f9a0dcb + a51ab61 commit f045d51

File tree

6 files changed

+361
-51
lines changed

6 files changed

+361
-51
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ A [mite](https://mite.yo.lk/en/) time tracking command line interface.
44

55
## Setup
66

7-
1. Grab a release from https://github.com/leanovate/mite/releases for your operating system and unpack it into your
7+
1. Grab a release from https://github.com/leanovate/mite-go/releases for your operating system and unpack it into your
88
$PATH (or %PATH% on windows).
99
2. Make sure that the `mite` command is executable by executing `mite version` in your shell
1010
3. Setup `mite` to use your API key by:

mite/api_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
11
package mite_test
22

3+
import (
4+
"bytes"
5+
"encoding/json"
6+
)
7+
38
const testApiKey = "f00bar"
49
const testClientVersion = "vX"
510
const testUserAgent = "mite-go/" + testClientVersion + " (+github.com/leanovate/mite-go)"
611

712
type recorder struct {
813
method string
914
url string
15+
body []byte
1016
contentType string
1117
userAgent string
1218
miteKey string
1319
}
20+
21+
func prettifyJson(b []byte, indent string) []byte {
22+
buf := &bytes.Buffer{}
23+
err := json.Indent(buf, b, "", indent)
24+
if err != nil {
25+
panic(err)
26+
}
27+
28+
return buf.Bytes()
29+
}

mite/project_test.go

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,40 @@ import (
1111
)
1212

1313
const projectResponse = `{
14-
"project": {
15-
"id": 643,
16-
"name": "Open-Source",
17-
"note": "valvat, memento et all.",
18-
"customer_id": 291,
19-
"customer_name": "Yolk",
20-
"budget": 0,
21-
"budget_type": "minutes",
22-
"hourly_rate": 6000,
23-
"archived": false,
24-
"active_hourly_rate": "hourly_rate",
25-
"hourly_rates_per_service": [
26-
{
27-
"service_id": 31272,
28-
"hourly_rate": 4500
29-
},
30-
{
31-
"service_id": 149228,
32-
"hourly_rate": 5500
33-
}
34-
],
35-
"created_at": "2011-08-17T12:06:57+02:00",
36-
"updated_at": "2015-02-19T10:53:10+01:00"
37-
}
14+
"project": {
15+
"id": 643,
16+
"name": "Open-Source",
17+
"note": "valvat, memento et all.",
18+
"customer_id": 291,
19+
"customer_name": "Yolk",
20+
"budget": 0,
21+
"budget_type": "minutes",
22+
"hourly_rate": 6000,
23+
"archived": false,
24+
"active_hourly_rate": "hourly_rate",
25+
"hourly_rates_per_service": [
26+
{
27+
"service_id": 31272,
28+
"hourly_rate": 4500
29+
},
30+
{
31+
"service_id": 149228,
32+
"hourly_rate": 5500
33+
}
34+
],
35+
"created_at": "2011-08-17T12:06:57+02:00",
36+
"updated_at": "2015-02-19T10:53:10+01:00"
37+
}
3838
}`
3939

40+
var projectObject = domain.Project{
41+
Id: domain.NewProjectId(643),
42+
Name: "Open-Source",
43+
Note: "valvat, memento et all.",
44+
}
45+
4046
func TestApi_Projects(t *testing.T) {
47+
// given
4148
rec := recorder{}
4249
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
4350
rec.method = r.Method
@@ -47,19 +54,19 @@ func TestApi_Projects(t *testing.T) {
4754

4855
w.Header().Add("Content-Type", "application/json; charset=utf-8")
4956
w.WriteHeader(200)
50-
w.Write([]byte(fmt.Sprintf("[%s]", projectResponse)))
57+
_, _ = w.Write([]byte(fmt.Sprintf("[%s]", projectResponse)))
5158
}))
5259

5360
defer srv.Close()
5461

5562
api := mite.NewApi(srv.URL, testApiKey, testClientVersion)
63+
64+
// when
5665
projects, err := api.Projects()
5766

67+
// then
5868
assert.Nil(t, err)
59-
assert.Equal(t, []*domain.Project{{
60-
Id: domain.NewProjectId(643),
61-
Name: "Open-Source",
62-
Note: "valvat, memento et all."}}, projects)
69+
assert.Equal(t, []*domain.Project{&projectObject}, projects)
6370

6471
assert.Equal(t, http.MethodGet, rec.method)
6572
assert.Equal(t, "/projects.json", rec.url)

mite/service_test.go

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,26 @@ import (
1111
)
1212

1313
const serviceResponse = `{
14-
"service": {
15-
"id": 38672,
16-
"name": "Coding",
17-
"note": "will code for food",
18-
"hourly_rate": 3300,
19-
"archived": false,
20-
"billable": true,
21-
"created_at": "2009-12-13T12:12:00+01:00",
22-
"updated_at": "2015-12-13T07:20:04+01:00"
23-
}
14+
"service": {
15+
"id": 38672,
16+
"name": "Coding",
17+
"note": "will code for food",
18+
"hourly_rate": 3300,
19+
"archived": false,
20+
"billable": true,
21+
"created_at": "2009-12-13T12:12:00+01:00",
22+
"updated_at": "2015-12-13T07:20:04+01:00"
23+
}
2424
}`
2525

26+
var serviceObject = domain.Service{
27+
Id: domain.NewServiceId(38672),
28+
Name: "Coding",
29+
Note: "will code for food",
30+
}
31+
2632
func TestApi_Services(t *testing.T) {
33+
// given
2734
rec := recorder{}
2835
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
2936
rec.method = r.Method
@@ -33,19 +40,19 @@ func TestApi_Services(t *testing.T) {
3340

3441
w.Header().Add("Content-Type", "application/json; charset=utf-8")
3542
w.WriteHeader(200)
36-
w.Write([]byte(fmt.Sprintf("[%s]", serviceResponse)))
43+
_, _ = w.Write([]byte(fmt.Sprintf("[%s]", serviceResponse)))
3744
}))
3845

3946
defer srv.Close()
4047

4148
api := mite.NewApi(srv.URL, testApiKey, testClientVersion)
49+
50+
// when
4251
services, err := api.Services()
4352

53+
// then
4454
assert.Nil(t, err)
45-
assert.Equal(t, []*domain.Service{{
46-
Id: domain.NewServiceId(38672),
47-
Name: "Coding",
48-
Note: "will code for food"}}, services)
55+
assert.Equal(t, []*domain.Service{&serviceObject}, services)
4956

5057
assert.Equal(t, http.MethodGet, rec.method)
5158
assert.Equal(t, "/services.json", rec.url)

mite/time_entry.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ func (r *timeEntryResponse) toTimeEntry() *domain.TimeEntry {
9999
CustomerName: r.TimeEntry.CustomerName,
100100
ServiceId: domain.NewServiceId(r.TimeEntry.ServiceId),
101101
ServiceName: r.TimeEntry.ServiceName,
102-
CreatedAt: r.TimeEntry.CreatedAt,
103-
UpdatedAt: r.TimeEntry.UpdatedAt,
102+
CreatedAt: r.TimeEntry.CreatedAt.UTC(),
103+
UpdatedAt: r.TimeEntry.UpdatedAt.UTC(),
104104
}
105105
}
106106

@@ -121,7 +121,7 @@ func (a *api) TimeEntries(query *domain.TimeEntryQuery) ([]*domain.TimeEntry, er
121121

122122
func (a *api) TimeEntry(id domain.TimeEntryId) (*domain.TimeEntry, error) {
123123
ter := timeEntryResponse{}
124-
err := a.get(fmt.Sprintf("/time_entries/%s.json", id), &ter)
124+
err := a.get(fmt.Sprintf("time_entries/%s.json", id), &ter)
125125
if err != nil {
126126
return nil, err
127127
}
@@ -131,7 +131,7 @@ func (a *api) TimeEntry(id domain.TimeEntryId) (*domain.TimeEntry, error) {
131131

132132
func (a *api) CreateTimeEntry(command *domain.TimeEntryCommand) (*domain.TimeEntry, error) {
133133
ter := timeEntryResponse{}
134-
err := a.post("/time_entries.json", fromCommand(command), &ter)
134+
err := a.post("time_entries.json", fromCommand(command), &ter)
135135
if err != nil {
136136
return nil, err
137137
}
@@ -140,9 +140,9 @@ func (a *api) CreateTimeEntry(command *domain.TimeEntryCommand) (*domain.TimeEnt
140140
}
141141

142142
func (a *api) EditTimeEntry(id domain.TimeEntryId, command *domain.TimeEntryCommand) error {
143-
return a.patch(fmt.Sprintf("/time_entries/%s.json", id), fromCommand(command), nil)
143+
return a.patch(fmt.Sprintf("time_entries/%s.json", id), fromCommand(command), nil)
144144
}
145145

146146
func (a *api) DeleteTimeEntry(id domain.TimeEntryId) error {
147-
return a.delete(fmt.Sprintf("/time_entries/%s.json", id), nil)
147+
return a.delete(fmt.Sprintf("time_entries/%s.json", id), nil)
148148
}

0 commit comments

Comments
 (0)