Skip to content

Commit 86ae270

Browse files
author
Ulrich Lissé
committed
Refactor project and services tests
1 parent 7418522 commit 86ae270

File tree

2 files changed

+58
-44
lines changed

2 files changed

+58
-44
lines changed

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)

0 commit comments

Comments
 (0)