Fix tests and rename field in Notifier

This commit is contained in:
Eugene 2017-10-12 17:31:14 +03:00 committed by Evgeny Danienko
parent 390495342c
commit 4f9788a158
No known key found for this signature in database
GPG Key ID: BC8C34D8B45BECBF
2 changed files with 17 additions and 15 deletions

View File

@ -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(&notification.Payload{
func (n *Notifier) Notify(body interface{}, tokens ...string) error {
n.setPayload(&notification.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,

View File

@ -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