From 4f9788a1585acac387cedb1fbf5ba10c4a0e22a7 Mon Sep 17 00:00:00 2001 From: Eugene <6655321@bk.ru> Date: Thu, 12 Oct 2017 17:31:14 +0300 Subject: [PATCH] Fix tests and rename field in Notifier --- geth/notification/fcm/notifier.go | 29 ++++++++++++++------------ geth/notification/fcm/notifier_test.go | 3 +-- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/geth/notification/fcm/notifier.go b/geth/notification/fcm/notifier.go index 2f94e6dac..f43e2d59e 100644 --- a/geth/notification/fcm/notifier.go +++ b/geth/notification/fcm/notifier.go @@ -2,44 +2,47 @@ package fcm import ( "github.com/NaySoftware/go-fcm" + "github.com/status-im/status-go/geth/common" "github.com/status-im/status-go/geth/notification" ) // Notifier represents messaging provider for notifications. type Notifier struct { - firebaseClient + client firebaseClient } // NewNotifier Firebase Cloud Messaging client constructor. -func NewNotifier(key string) *Notifier { - return &Notifier{fcm.NewFcmClient(key)} +func NewNotifier(key string) func() common.Notifier { + return func() common.Notifier { + return &Notifier{fcm.NewFcmClient(key)} + } } // Notify preparation and send to the tokens list. -func (p *Notifier) Notify(body interface{}, tokens ...string) error { - p.setPayload(¬ification.Payload{ +func (n *Notifier) Notify(body interface{}, tokens ...string) error { + n.setPayload(¬ification.Payload{ Title: "Status - new message", Body: "ping", }) - p.setMessage(body, tokens...) - _, err := p.firebaseClient.Send() + n.setMessage(body, tokens...) + _, err := n.client.Send() return err } // SetMessage to send for given the tokens list. -func (p *Notifier) setMessage(body interface{}, tokens ...string) { - p.NewFcmRegIdsMsg(tokens, body) +func (n *Notifier) setMessage(body interface{}, tokens ...string) { + n.client.NewFcmRegIdsMsg(tokens, body) } // SetPayload sets payload message information. -func (p *Notifier) setPayload(payload *notification.Payload) { - fcmPayload := p.toFCMPayload(payload) - p.SetNotificationPayload(fcmPayload) +func (n *Notifier) setPayload(payload *notification.Payload) { + fcmPayload := n.toFCMPayload(payload) + n.client.SetNotificationPayload(fcmPayload) } -func (p *Notifier) toFCMPayload(payload *notification.Payload) *fcm.NotificationPayload { +func (n *Notifier) toFCMPayload(payload *notification.Payload) *fcm.NotificationPayload { return &fcm.NotificationPayload{ Title: payload.Title, Body: payload.Body, diff --git a/geth/notification/fcm/notifier_test.go b/geth/notification/fcm/notifier_test.go index 38fa2fe0c..320fd6798 100644 --- a/geth/notification/fcm/notifier_test.go +++ b/geth/notification/fcm/notifier_test.go @@ -6,7 +6,6 @@ import ( "github.com/NaySoftware/go-fcm" "github.com/golang/mock/gomock" - t "github.com/status-im/status-go/geth/testing" "github.com/stretchr/testify/suite" ) @@ -15,7 +14,7 @@ func TestFCMClientTestSuite(t *testing.T) { } type NotifierTestSuite struct { - t.BaseTestSuite + suite.Suite fcmClientMock *MockfirebaseClient fcmClientMockCtrl *gomock.Controller