mirror of
https://github.com/nikoksr/notify.git
synced 2025-03-29 21:46:58 +02:00
test: apply test conventions for fcm service
This commit is contained in:
parent
6ad3b2e4d5
commit
6ec42ebdc4
@ -23,6 +23,8 @@ type (
|
||||
)
|
||||
|
||||
// fcmClient abstracts go-fcm for writing unit tests
|
||||
//
|
||||
//go:generate mockery --name=fcmClient --output=. --case=underscore --inpackage
|
||||
type fcmClient interface {
|
||||
SendWithRetry(*fcm.Message, int) (*fcm.Response, error)
|
||||
}
|
||||
|
@ -9,7 +9,17 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestAddReceivers(t *testing.T) {
|
||||
func TestFCM_New(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
assert := require.New(t)
|
||||
|
||||
service, err := New("server-api-key")
|
||||
assert.NotNil(service)
|
||||
assert.Nil(err)
|
||||
}
|
||||
|
||||
func TestFCM_AddReceivers(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
assert := require.New(t)
|
||||
@ -23,7 +33,7 @@ func TestAddReceivers(t *testing.T) {
|
||||
assert.Equal(svc.deviceTokens, deviceTokens)
|
||||
}
|
||||
|
||||
func TestSend(t *testing.T) {
|
||||
func TestFCM_Send(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
assert := require.New(t)
|
||||
@ -38,7 +48,7 @@ func TestSend(t *testing.T) {
|
||||
}
|
||||
|
||||
// test fcm client send
|
||||
mockClient := newMockFCMClient(t)
|
||||
mockClient := newMockFcmClient(t)
|
||||
mockClient.On("SendWithRetry", &fcm.Message{
|
||||
To: mockToken,
|
||||
Notification: &fcm.Notification{
|
||||
@ -54,7 +64,7 @@ func TestSend(t *testing.T) {
|
||||
mockClient.AssertExpectations(t)
|
||||
|
||||
// test fcm client send with data
|
||||
mockClient = newMockFCMClient(t)
|
||||
mockClient = newMockFcmClient(t)
|
||||
mockClient.On("SendWithRetry", &fcm.Message{
|
||||
To: mockToken,
|
||||
Data: mockData,
|
||||
@ -72,7 +82,7 @@ func TestSend(t *testing.T) {
|
||||
mockClient.AssertExpectations(t)
|
||||
|
||||
// test fcm client send with data and retries
|
||||
mockClient = newMockFCMClient(t)
|
||||
mockClient = newMockFcmClient(t)
|
||||
mockClient.On("SendWithRetry", &fcm.Message{
|
||||
To: mockToken,
|
||||
Data: mockData,
|
||||
@ -91,7 +101,7 @@ func TestSend(t *testing.T) {
|
||||
mockClient.AssertExpectations(t)
|
||||
|
||||
// test fcm client returning error
|
||||
mockClient = newMockFCMClient(t)
|
||||
mockClient = newMockFcmClient(t)
|
||||
mockClient.On("SendWithRetry", &fcm.Message{
|
||||
To: mockToken,
|
||||
Data: mockData,
|
||||
@ -111,7 +121,7 @@ func TestSend(t *testing.T) {
|
||||
|
||||
// test fcm client multiple receivers
|
||||
anotherMockToken := "another_device_token"
|
||||
mockClient = newMockFCMClient(t)
|
||||
mockClient = newMockFcmClient(t)
|
||||
mockClient.On("SendWithRetry", &fcm.Message{
|
||||
To: mockToken,
|
||||
Data: mockData,
|
||||
@ -138,7 +148,7 @@ func TestSend(t *testing.T) {
|
||||
mockClient.AssertExpectations(t)
|
||||
}
|
||||
|
||||
func TestGetMessageData(t *testing.T) {
|
||||
func TestFCM_GetMessageData(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
assert := require.New(t)
|
||||
@ -179,7 +189,7 @@ func TestGetMessageData(t *testing.T) {
|
||||
assert.True(ok)
|
||||
}
|
||||
|
||||
func TestGetMessageRetryAttempts(t *testing.T) {
|
||||
func TestFCM_GetMessageRetryAttempts(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
assert := require.New(t)
|
||||
|
@ -1,48 +0,0 @@
|
||||
// Code generated by mockery v2.12.2. DO NOT EDIT.
|
||||
|
||||
package fcm
|
||||
|
||||
import (
|
||||
testing "testing"
|
||||
|
||||
fcm "github.com/appleboy/go-fcm"
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
// mockFCMClient is an autogenerated mock type for the mockFCMClient type
|
||||
type mockFCMClient struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
// SendWithRetry provides a mock function with given fields: _a0, _a1
|
||||
func (_m *mockFCMClient) SendWithRetry(_a0 *fcm.Message, _a1 int) (*fcm.Response, error) {
|
||||
ret := _m.Called(_a0, _a1)
|
||||
|
||||
var r0 *fcm.Response
|
||||
if rf, ok := ret.Get(0).(func(*fcm.Message, int) *fcm.Response); ok {
|
||||
r0 = rf(_a0, _a1)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*fcm.Response)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(*fcm.Message, int) error); ok {
|
||||
r1 = rf(_a0, _a1)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// newMockFCMClient creates a new instance of mockFCMClient. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
func newMockFCMClient(t testing.TB) *mockFCMClient {
|
||||
mock := &mockFCMClient{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
t.Cleanup(func() { mock.AssertExpectations(t) })
|
||||
|
||||
return mock
|
||||
}
|
51
service/fcm/mock_fcm_client.go
Normal file
51
service/fcm/mock_fcm_client.go
Normal file
@ -0,0 +1,51 @@
|
||||
// Code generated by mockery v2.14.0. DO NOT EDIT.
|
||||
|
||||
package fcm
|
||||
|
||||
import (
|
||||
go_fcm "github.com/appleboy/go-fcm"
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
// mockFcmClient is an autogenerated mock type for the fcmClient type
|
||||
type mockFcmClient struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
// SendWithRetry provides a mock function with given fields: _a0, _a1
|
||||
func (_m *mockFcmClient) SendWithRetry(_a0 *go_fcm.Message, _a1 int) (*go_fcm.Response, error) {
|
||||
ret := _m.Called(_a0, _a1)
|
||||
|
||||
var r0 *go_fcm.Response
|
||||
if rf, ok := ret.Get(0).(func(*go_fcm.Message, int) *go_fcm.Response); ok {
|
||||
r0 = rf(_a0, _a1)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*go_fcm.Response)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(*go_fcm.Message, int) error); ok {
|
||||
r1 = rf(_a0, _a1)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
type mockConstructorTestingTnewMockFcmClient interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
}
|
||||
|
||||
// newMockFcmClient creates a new instance of mockFcmClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
func newMockFcmClient(t mockConstructorTestingTnewMockFcmClient) *mockFcmClient {
|
||||
mock := &mockFcmClient{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
t.Cleanup(func() { mock.AssertExpectations(t) })
|
||||
|
||||
return mock
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user