Skip to content

Commit

Permalink
Add Services() test
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulrich Lissé committed Apr 9, 2019
1 parent 8c23d8e commit ea8ebf8
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions mite/service_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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 serviceResponse = `{
"service": {
"id": 38672,
"name": "Coding",
"note": "will code for food",
"hourly_rate": 3300,
"archived": false,
"billable": true,
"created_at": "2009-12-13T12:12:00+01:00",
"updated_at": "2015-12-13T07:20:04+01:00"
}
}`

func TestApi_Services(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]", serviceResponse)))
}))

defer srv.Close()

api := mite.NewApi(srv.URL, testApiKey, testClientVersion)
services, err := api.Services()

assert.Nil(t, err)
assert.Equal(t, []*domain.Service{{
Id: domain.NewServiceId(38672),
Name: "Coding",
Note: "will code for food"}}, services)

assert.Equal(t, http.MethodGet, rec.method)
assert.Equal(t, "/services.json", rec.url)
assert.Equal(t, testApiKey, rec.miteKey)
assert.Equal(t, testUserAgent, rec.userAgent)
}

0 comments on commit ea8ebf8

Please sign in to comment.