-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ulrich Lissé
committed
Apr 9, 2019
1 parent
3315050
commit 8c23d8e
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package mite_test | ||
|
||
const testApiKey = "f00bar" | ||
const testClientVersion = "vX" | ||
const testUserAgent = "mite-go/" + testClientVersion + " (+github.com/leanovate/mite-go)" | ||
|
||
type recorder struct { | ||
method string | ||
url string | ||
contentType string | ||
userAgent string | ||
miteKey string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package mite_test | ||
|
||
import ( | ||
"fmt" | ||
"github.com/leanovate/mite-go/domain" | ||
"github.com/leanovate/mite-go/mite" | ||
"github.com/stretchr/testify/assert" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
) | ||
|
||
const projectResponse = `{ | ||
"project": { | ||
"id": 643, | ||
"name": "Open-Source", | ||
"note": "valvat, memento et all.", | ||
"customer_id": 291, | ||
"customer_name": "Yolk", | ||
"budget": 0, | ||
"budget_type": "minutes", | ||
"hourly_rate": 6000, | ||
"archived": false, | ||
"active_hourly_rate": "hourly_rate", | ||
"hourly_rates_per_service": [ | ||
{ | ||
"service_id": 31272, | ||
"hourly_rate": 4500 | ||
}, | ||
{ | ||
"service_id": 149228, | ||
"hourly_rate": 5500 | ||
} | ||
], | ||
"created_at": "2011-08-17T12:06:57+02:00", | ||
"updated_at": "2015-02-19T10:53:10+01:00" | ||
} | ||
}` | ||
|
||
func TestApi_Projects(t *testing.T) { | ||
rec := recorder{} | ||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
rec.method = r.Method | ||
rec.url = r.RequestURI | ||
rec.miteKey = r.Header.Get("X-MiteApiKey") | ||
rec.userAgent = r.Header.Get("User-Agent") | ||
|
||
w.Header().Add("Content-Type", "application/json; charset=utf-8") | ||
w.WriteHeader(200) | ||
w.Write([]byte(fmt.Sprintf("[%s]", projectResponse))) | ||
})) | ||
|
||
defer srv.Close() | ||
|
||
api := mite.NewApi(srv.URL, testApiKey, testClientVersion) | ||
projects, err := api.Projects() | ||
|
||
assert.Nil(t, err) | ||
assert.Equal(t, []*domain.Project{{ | ||
Id: domain.NewProjectId(643), | ||
Name: "Open-Source", | ||
Note: "valvat, memento et all."}}, projects) | ||
|
||
assert.Equal(t, http.MethodGet, rec.method) | ||
assert.Equal(t, "/projects.json", rec.url) | ||
assert.Equal(t, testApiKey, rec.miteKey) | ||
assert.Equal(t, testUserAgent, rec.userAgent) | ||
} |