status-go/geth/notification/fcm/notifier_test.go

74 lines
1.8 KiB
Go
Raw Normal View History

2017-10-11 13:51:43 +00:00
package fcm
import (
2017-10-10 15:33:12 +00:00
"errors"
"testing"
2017-10-10 15:33:12 +00:00
"github.com/NaySoftware/go-fcm"
"github.com/golang/mock/gomock"
t "github.com/status-im/status-go/geth/testing"
"github.com/stretchr/testify/suite"
)
func TestFCMClientTestSuite(t *testing.T) {
2017-10-10 15:33:12 +00:00
suite.Run(t, new(FCMProviderTestSuite))
}
2017-10-10 15:33:12 +00:00
type FCMProviderTestSuite struct {
t.BaseTestSuite
2017-10-10 15:33:12 +00:00
2017-10-11 13:51:43 +00:00
fcmClientMock *MockFirebaseClient
2017-10-10 15:33:12 +00:00
fcmClientMockCtrl *gomock.Controller
}
func (s *FCMProviderTestSuite) SetupTest() {
s.fcmClientMockCtrl = gomock.NewController(s.T())
2017-10-11 13:51:43 +00:00
s.fcmClientMock = NewMockFirebaseClient(s.fcmClientMockCtrl)
}
2017-10-10 15:33:12 +00:00
func (s *FCMProviderTestSuite) TearDownTest() {
s.fcmClientMockCtrl.Finish()
}
func (s *FCMProviderTestSuite) TestNewFCMClient() {
2017-10-11 13:51:43 +00:00
fcmClient := Notifier{s.fcmClientMock}
2017-10-10 11:18:15 +00:00
s.Require().NotNil(fcmClient)
2017-10-10 15:33:12 +00:00
}
2017-10-11 13:51:43 +00:00
func (s *FCMProviderTestSuite) TestNotifySuccess() {
fcmPayload := getPayload()
2017-10-10 15:33:12 +00:00
ids := []string{"1"}
body := interface{}("body")
s.fcmClientMock.EXPECT().SetNotificationPayload(fcmPayload).Times(1)
2017-10-11 13:51:43 +00:00
s.fcmClientMock.EXPECT().NewFcmRegIdsMsg(ids, body).Times(1)
2017-10-10 15:33:12 +00:00
s.fcmClientMock.EXPECT().Send().Return(nil, nil).Times(1)
2017-10-11 13:51:43 +00:00
fcmClient := Notifier{s.fcmClientMock}
2017-10-10 15:33:12 +00:00
2017-10-11 13:51:43 +00:00
err := fcmClient.Notify(body, ids...)
2017-10-10 15:33:12 +00:00
s.Require().NoError(err)
}
2017-10-11 13:51:43 +00:00
func (s *FCMProviderTestSuite) TestNotifyError() {
2017-10-10 15:33:12 +00:00
expectedError := errors.New("error")
2017-10-11 13:51:43 +00:00
fcmPayload := getPayload()
ids := []string{"1"}
body := interface{}("body")
s.fcmClientMock.EXPECT().SetNotificationPayload(fcmPayload).Times(1)
s.fcmClientMock.EXPECT().NewFcmRegIdsMsg(ids, body).Times(1)
2017-10-10 15:33:12 +00:00
s.fcmClientMock.EXPECT().Send().Return(nil, expectedError).Times(1)
2017-10-11 13:51:43 +00:00
fcmClient := Notifier{s.fcmClientMock}
2017-10-10 15:33:12 +00:00
2017-10-11 13:51:43 +00:00
err := fcmClient.Notify(body, ids...)
2017-10-10 15:33:12 +00:00
s.Require().Equal(expectedError, err)
}
2017-10-11 13:51:43 +00:00
func getPayload() *fcm.NotificationPayload {
return &fcm.NotificationPayload{Title: "Status - new message", Body: "ping"}
}