Fix tests and rename field in Notifier
This commit is contained in:
parent
390495342c
commit
4f9788a158
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue