Firebase provider tests
This commit is contained in:
parent
7195fe3f92
commit
c36a51d0cf
|
@ -7,6 +7,7 @@ package common
|
||||||
import (
|
import (
|
||||||
go_fcm "github.com/NaySoftware/go-fcm"
|
go_fcm "github.com/NaySoftware/go-fcm"
|
||||||
gomock "github.com/golang/mock/gomock"
|
gomock "github.com/golang/mock/gomock"
|
||||||
|
message "github.com/status-im/status-go/geth/notification/message"
|
||||||
reflect "reflect"
|
reflect "reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -34,66 +35,110 @@ func (m *MockNotification) EXPECT() *MockNotificationMockRecorder {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify mocks base method
|
// Notify mocks base method
|
||||||
func (m *MockNotification) Notify(token string) string {
|
func (m *MockNotification) Notify(token string, msg *message.Message) (string, error) {
|
||||||
ret := m.ctrl.Call(m, "Notify", token)
|
ret := m.ctrl.Call(m, "Notify", token, msg)
|
||||||
ret0, _ := ret[0].(string)
|
ret0, _ := ret[0].(string)
|
||||||
return ret0
|
ret1, _ := ret[1].(error)
|
||||||
|
return ret0, ret1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify indicates an expected call of Notify
|
// Notify indicates an expected call of Notify
|
||||||
func (mr *MockNotificationMockRecorder) Notify(token interface{}) *gomock.Call {
|
func (mr *MockNotificationMockRecorder) Notify(token, msg interface{}) *gomock.Call {
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Notify", reflect.TypeOf((*MockNotification)(nil).Notify), token)
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Notify", reflect.TypeOf((*MockNotification)(nil).Notify), token, msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MockMessagingProvider is a mock of MessagingProvider interface
|
||||||
|
type MockMessagingProvider struct {
|
||||||
|
ctrl *gomock.Controller
|
||||||
|
recorder *MockMessagingProviderMockRecorder
|
||||||
|
}
|
||||||
|
|
||||||
|
// MockMessagingProviderMockRecorder is the mock recorder for MockMessagingProvider
|
||||||
|
type MockMessagingProviderMockRecorder struct {
|
||||||
|
mock *MockMessagingProvider
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMockMessagingProvider creates a new mock instance
|
||||||
|
func NewMockMessagingProvider(ctrl *gomock.Controller) *MockMessagingProvider {
|
||||||
|
mock := &MockMessagingProvider{ctrl: ctrl}
|
||||||
|
mock.recorder = &MockMessagingProviderMockRecorder{mock}
|
||||||
|
return mock
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXPECT returns an object that allows the caller to indicate expected use
|
||||||
|
func (m *MockMessagingProvider) EXPECT() *MockMessagingProviderMockRecorder {
|
||||||
|
return m.recorder
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetMessage mocks base method
|
||||||
|
func (m *MockMessagingProvider) SetMessage(ids []string, body interface{}) {
|
||||||
|
m.ctrl.Call(m, "SetMessage", ids, body)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetMessage indicates an expected call of SetMessage
|
||||||
|
func (mr *MockMessagingProviderMockRecorder) SetMessage(ids, body interface{}) *gomock.Call {
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetMessage", reflect.TypeOf((*MockMessagingProvider)(nil).SetMessage), ids, body)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPayload mocks base method
|
||||||
|
func (m *MockMessagingProvider) SetPayload(payload *message.Payload) {
|
||||||
|
m.ctrl.Call(m, "SetPayload", payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPayload indicates an expected call of SetPayload
|
||||||
|
func (mr *MockMessagingProviderMockRecorder) SetPayload(payload interface{}) *gomock.Call {
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetPayload", reflect.TypeOf((*MockMessagingProvider)(nil).SetPayload), payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send mocks base method
|
// Send mocks base method
|
||||||
func (m *MockNotification) Send() error {
|
func (m *MockMessagingProvider) Send() error {
|
||||||
ret := m.ctrl.Call(m, "Send")
|
ret := m.ctrl.Call(m, "Send")
|
||||||
ret0, _ := ret[0].(error)
|
ret0, _ := ret[0].(error)
|
||||||
return ret0
|
return ret0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send indicates an expected call of Send
|
// Send indicates an expected call of Send
|
||||||
func (mr *MockNotificationMockRecorder) Send() *gomock.Call {
|
func (mr *MockMessagingProviderMockRecorder) Send() *gomock.Call {
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Send", reflect.TypeOf((*MockNotification)(nil).Send))
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Send", reflect.TypeOf((*MockMessagingProvider)(nil).Send))
|
||||||
}
|
}
|
||||||
|
|
||||||
// MockMessaging is a mock of Messaging interface
|
// MockFirebaseClient is a mock of FirebaseClient interface
|
||||||
type MockMessaging struct {
|
type MockFirebaseClient struct {
|
||||||
ctrl *gomock.Controller
|
ctrl *gomock.Controller
|
||||||
recorder *MockMessagingMockRecorder
|
recorder *MockFirebaseClientMockRecorder
|
||||||
}
|
}
|
||||||
|
|
||||||
// MockMessagingMockRecorder is the mock recorder for MockMessaging
|
// MockFirebaseClientMockRecorder is the mock recorder for MockFirebaseClient
|
||||||
type MockMessagingMockRecorder struct {
|
type MockFirebaseClientMockRecorder struct {
|
||||||
mock *MockMessaging
|
mock *MockFirebaseClient
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMockMessaging creates a new mock instance
|
// NewMockFirebaseClient creates a new mock instance
|
||||||
func NewMockMessaging(ctrl *gomock.Controller) *MockMessaging {
|
func NewMockFirebaseClient(ctrl *gomock.Controller) *MockFirebaseClient {
|
||||||
mock := &MockMessaging{ctrl: ctrl}
|
mock := &MockFirebaseClient{ctrl: ctrl}
|
||||||
mock.recorder = &MockMessagingMockRecorder{mock}
|
mock.recorder = &MockFirebaseClientMockRecorder{mock}
|
||||||
return mock
|
return mock
|
||||||
}
|
}
|
||||||
|
|
||||||
// EXPECT returns an object that allows the caller to indicate expected use
|
// EXPECT returns an object that allows the caller to indicate expected use
|
||||||
func (m *MockMessaging) EXPECT() *MockMessagingMockRecorder {
|
func (m *MockFirebaseClient) EXPECT() *MockFirebaseClientMockRecorder {
|
||||||
return m.recorder
|
return m.recorder
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFcmRegIdsMsg mocks base method
|
// NewFcmRegIdsMsg mocks base method
|
||||||
func (m *MockMessaging) NewFcmRegIdsMsg(list []string, body interface{}) *go_fcm.FcmClient {
|
func (m *MockFirebaseClient) NewFcmRegIdsMsg(list []string, body interface{}) *go_fcm.FcmClient {
|
||||||
ret := m.ctrl.Call(m, "NewFcmRegIdsMsg", list, body)
|
ret := m.ctrl.Call(m, "NewFcmRegIdsMsg", list, body)
|
||||||
ret0, _ := ret[0].(*go_fcm.FcmClient)
|
ret0, _ := ret[0].(*go_fcm.FcmClient)
|
||||||
return ret0
|
return ret0
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFcmRegIdsMsg indicates an expected call of NewFcmRegIdsMsg
|
// NewFcmRegIdsMsg indicates an expected call of NewFcmRegIdsMsg
|
||||||
func (mr *MockMessagingMockRecorder) NewFcmRegIdsMsg(list, body interface{}) *gomock.Call {
|
func (mr *MockFirebaseClientMockRecorder) NewFcmRegIdsMsg(list, body interface{}) *gomock.Call {
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewFcmRegIdsMsg", reflect.TypeOf((*MockMessaging)(nil).NewFcmRegIdsMsg), list, body)
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewFcmRegIdsMsg", reflect.TypeOf((*MockFirebaseClient)(nil).NewFcmRegIdsMsg), list, body)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send mocks base method
|
// Send mocks base method
|
||||||
func (m *MockMessaging) Send() (*go_fcm.FcmResponseStatus, error) {
|
func (m *MockFirebaseClient) Send() (*go_fcm.FcmResponseStatus, error) {
|
||||||
ret := m.ctrl.Call(m, "Send")
|
ret := m.ctrl.Call(m, "Send")
|
||||||
ret0, _ := ret[0].(*go_fcm.FcmResponseStatus)
|
ret0, _ := ret[0].(*go_fcm.FcmResponseStatus)
|
||||||
ret1, _ := ret[1].(error)
|
ret1, _ := ret[1].(error)
|
||||||
|
@ -101,18 +146,18 @@ func (m *MockMessaging) Send() (*go_fcm.FcmResponseStatus, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send indicates an expected call of Send
|
// Send indicates an expected call of Send
|
||||||
func (mr *MockMessagingMockRecorder) Send() *gomock.Call {
|
func (mr *MockFirebaseClientMockRecorder) Send() *gomock.Call {
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Send", reflect.TypeOf((*MockMessaging)(nil).Send))
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Send", reflect.TypeOf((*MockFirebaseClient)(nil).Send))
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetNotificationPayload mocks base method
|
// SetNotificationPayload mocks base method
|
||||||
func (m *MockMessaging) SetNotificationPayload(payload *go_fcm.NotificationPayload) *go_fcm.FcmClient {
|
func (m *MockFirebaseClient) SetNotificationPayload(payload *go_fcm.NotificationPayload) *go_fcm.FcmClient {
|
||||||
ret := m.ctrl.Call(m, "SetNotificationPayload", payload)
|
ret := m.ctrl.Call(m, "SetNotificationPayload", payload)
|
||||||
ret0, _ := ret[0].(*go_fcm.FcmClient)
|
ret0, _ := ret[0].(*go_fcm.FcmClient)
|
||||||
return ret0
|
return ret0
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetNotificationPayload indicates an expected call of SetNotificationPayload
|
// SetNotificationPayload indicates an expected call of SetNotificationPayload
|
||||||
func (mr *MockMessagingMockRecorder) SetNotificationPayload(payload interface{}) *gomock.Call {
|
func (mr *MockFirebaseClientMockRecorder) SetNotificationPayload(payload interface{}) *gomock.Call {
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetNotificationPayload", reflect.TypeOf((*MockMessaging)(nil).SetNotificationPayload), payload)
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetNotificationPayload", reflect.TypeOf((*MockFirebaseClient)(nil).SetNotificationPayload), payload)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,81 @@
|
||||||
package notification
|
package notification
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/NaySoftware/go-fcm"
|
||||||
|
"github.com/golang/mock/gomock"
|
||||||
|
"github.com/status-im/status-go/geth/common"
|
||||||
|
"github.com/status-im/status-go/geth/notification/message"
|
||||||
t "github.com/status-im/status-go/geth/testing"
|
t "github.com/status-im/status-go/geth/testing"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFCMClientTestSuite(t *testing.T) {
|
func TestFCMClientTestSuite(t *testing.T) {
|
||||||
suite.Run(t, new(FCMClientTestSuite))
|
suite.Run(t, new(FCMProviderTestSuite))
|
||||||
}
|
}
|
||||||
|
|
||||||
type FCMClientTestSuite struct {
|
type FCMProviderTestSuite struct {
|
||||||
t.BaseTestSuite
|
t.BaseTestSuite
|
||||||
|
|
||||||
|
fcmClientMock *common.MockFirebaseClient
|
||||||
|
fcmClientMockCtrl *gomock.Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *FCMClientTestSuite) TestNewFCMClient() {
|
func (s *FCMProviderTestSuite) SetupTest() {
|
||||||
fcmClient := NewFCMClient()
|
s.fcmClientMockCtrl = gomock.NewController(s.T())
|
||||||
|
s.fcmClientMock = common.NewMockFirebaseClient(s.fcmClientMockCtrl)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *FCMProviderTestSuite) TearDownTest() {
|
||||||
|
s.fcmClientMockCtrl.Finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *FCMProviderTestSuite) TestNewFCMClient() {
|
||||||
|
fcmClient := NewFCMProvider(s.fcmClientMock)
|
||||||
|
|
||||||
s.Require().NotNil(fcmClient)
|
s.Require().NotNil(fcmClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *FCMProviderTestSuite) TestSetMessage() {
|
||||||
|
ids := []string{"1"}
|
||||||
|
body := interface{}("body")
|
||||||
|
|
||||||
|
s.fcmClientMock.EXPECT().NewFcmRegIdsMsg(ids, body).Times(1)
|
||||||
|
fcmClient := NewFCMProvider(s.fcmClientMock)
|
||||||
|
|
||||||
|
fcmClient.SetMessage(ids, body)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *FCMProviderTestSuite) TestSetPayload() {
|
||||||
|
title := "title"
|
||||||
|
body := "body"
|
||||||
|
payload := &message.Payload{Title: title, Body: body}
|
||||||
|
fcmPayload := &fcm.NotificationPayload{Title: title, Body: body}
|
||||||
|
|
||||||
|
s.fcmClientMock.EXPECT().SetNotificationPayload(fcmPayload).Times(1)
|
||||||
|
fcmClient := NewFCMProvider(s.fcmClientMock)
|
||||||
|
|
||||||
|
fcmClient.SetPayload(payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *FCMProviderTestSuite) TestSendSuccess() {
|
||||||
|
s.fcmClientMock.EXPECT().Send().Return(nil, nil).Times(1)
|
||||||
|
fcmClient := NewFCMProvider(s.fcmClientMock)
|
||||||
|
|
||||||
|
err := fcmClient.Send()
|
||||||
|
|
||||||
|
s.Require().NoError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *FCMProviderTestSuite) TestSendError() {
|
||||||
|
expectedError := errors.New("error")
|
||||||
|
|
||||||
|
s.fcmClientMock.EXPECT().Send().Return(nil, expectedError).Times(1)
|
||||||
|
fcmClient := NewFCMProvider(s.fcmClientMock)
|
||||||
|
|
||||||
|
err := fcmClient.Send()
|
||||||
|
|
||||||
|
s.Require().Equal(expectedError, err)
|
||||||
|
}
|
||||||
|
|
|
@ -3,8 +3,10 @@ package notification
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"errors"
|
||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
"github.com/status-im/status-go/geth/common"
|
"github.com/status-im/status-go/geth/common"
|
||||||
|
"github.com/status-im/status-go/geth/notification/message"
|
||||||
t "github.com/status-im/status-go/geth/testing"
|
t "github.com/status-im/status-go/geth/testing"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
)
|
)
|
||||||
|
@ -15,13 +17,13 @@ func TestNotificationTestSuite(t *testing.T) {
|
||||||
|
|
||||||
type NotificationTestSuite struct {
|
type NotificationTestSuite struct {
|
||||||
t.BaseTestSuite
|
t.BaseTestSuite
|
||||||
messagingMock *common.MockMessaging
|
messagingMock *common.MockMessagingProvider
|
||||||
messagingMockCtrl *gomock.Controller
|
messagingMockCtrl *gomock.Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *NotificationTestSuite) SetupTest() {
|
func (s *NotificationTestSuite) SetupTest() {
|
||||||
s.messagingMockCtrl = gomock.NewController(s.T())
|
s.messagingMockCtrl = gomock.NewController(s.T())
|
||||||
s.messagingMock = common.NewMockMessaging(s.messagingMockCtrl)
|
s.messagingMock = common.NewMockMessagingProvider(s.messagingMockCtrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *NotificationTestSuite) TearDownTest() {
|
func (s *NotificationTestSuite) TearDownTest() {
|
||||||
|
@ -33,24 +35,44 @@ func (s *NotificationTestSuite) TestNewNotification() {
|
||||||
s.Require().NotNil(manager)
|
s.Require().NotNil(manager)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *NotificationTestSuite) TestNotify() {
|
func (s *NotificationTestSuite) TestNotifySuccess() {
|
||||||
token := "test"
|
token := "test"
|
||||||
s.messagingMock.EXPECT().NewFcmRegIdsMsg([]string{token}, map[string]string{
|
msg := getMessage()
|
||||||
"msg": "Hello World1",
|
|
||||||
"sum": "Happy Day",
|
s.messagingMock.EXPECT().SetMessage([]string{token}, msg.Body).Times(1)
|
||||||
})
|
s.messagingMock.EXPECT().SetPayload(msg.Payload).Times(1)
|
||||||
|
s.messagingMock.EXPECT().Send().Return(nil).Times(1)
|
||||||
|
|
||||||
manager := New(s.messagingMock)
|
manager := New(s.messagingMock)
|
||||||
res := manager.Notify(token)
|
res, err := manager.Notify(token, msg)
|
||||||
|
|
||||||
s.Require().Equal(token, res)
|
s.Require().Equal(token, res)
|
||||||
}
|
|
||||||
|
|
||||||
func (s *NotificationTestSuite) TestSend() {
|
|
||||||
s.messagingMock.EXPECT().Send().Times(1).Return(nil)
|
|
||||||
|
|
||||||
manager := New(s.messagingMock)
|
|
||||||
err := manager.Send()
|
|
||||||
|
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *NotificationTestSuite) TestNotifyError() {
|
||||||
|
token := "test"
|
||||||
|
msg := getMessage()
|
||||||
|
expectedError := errors.New("error")
|
||||||
|
|
||||||
|
s.messagingMock.EXPECT().SetMessage([]string{token}, msg.Body).Times(1)
|
||||||
|
s.messagingMock.EXPECT().SetPayload(msg.Payload).Times(1)
|
||||||
|
s.messagingMock.EXPECT().Send().Return(expectedError).Times(1)
|
||||||
|
|
||||||
|
manager := New(s.messagingMock)
|
||||||
|
_, err := manager.Notify(token, msg)
|
||||||
|
|
||||||
|
s.Require().Equal(expectedError, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getMessage() *message.Message {
|
||||||
|
return &message.Message{
|
||||||
|
Body: map[string]string{
|
||||||
|
"msg": "Hello World1",
|
||||||
|
"sum": "Happy Day",
|
||||||
|
},
|
||||||
|
Payload: &message.Payload{
|
||||||
|
Title: "test notification",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue