Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
saromanov committed Jan 14, 2019
1 parent fd7327e commit e58839b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
3 changes: 1 addition & 2 deletions fcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ func (a *App) Send(s *SendBody) (*Response, error) {

url := fcmURL
if s.TestURL != "" {
url = s.TestURL + "/fcm/send"
fmt.Println(url)
url = s.TestURL
}
resp, err := a.sendRequest(url, marshalled)
if err != nil {
Expand Down
30 changes: 27 additions & 3 deletions fcm_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fcm

import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
Expand All @@ -21,13 +20,30 @@ func TestSend(t *testing.T) {
a := New("testKey")
assert.NotNil(t, a, "unable to create object")
_, err := a.Send(&SendBody{
TestURL: s.URL,
TestURL: s.URL + "/fcm/send",
To: "test",
Data: map[string]string{
"foo": "bar",
},
})
assert.NoError(t, err, "unable to send data")
_, err = a.Send(&SendBody{
TestURL: s.URL + "/badjson",
To: "test",
Data: map[string]string{
"foo": "bar",
},
})
assert.Error(t, err, "unable to decode response: json: cannot unmarshal string into Go value of type fcm.Response")

_, err = a.Send(&SendBody{
TestURL: "127.0.2.2",
To: "test",
Data: map[string]string{
"foo": "bar",
},
})
assert.Error(t, err)

}

Expand All @@ -40,7 +56,15 @@ func mockFCMServer() *httptest.Server {
"failure":0,
"results":[]
}`
fmt.Println("CATCH")
_, _ = w.Write([]byte(s))
})
router.Post("/badjson", func(w http.ResponseWriter, r *http.Request) {
s := `
"multicast_id":1,
"success":1,
"failure":0,
"results":[]
}`
_, _ = w.Write([]byte(s))
})
return httptest.NewServer(router)
Expand Down

0 comments on commit e58839b

Please sign in to comment.