Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(service): Apns2 integration #715

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test(service): added tests
  • Loading branch information
saisumith770 committed Oct 8, 2023
commit 34479982ce22b342a88c32d59f25bc52a5de2319
58 changes: 58 additions & 0 deletions service/apns2/apns2_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package apns2

import (
"context"
"testing"

apnsSvc "github.com/sideshow/apns2"
"github.com/stretchr/testify/require"
)

func TestAPNS2_AddReceivers(t *testing.T) {
t.Parallel()

assert := require.New(t)

svc := &Service{
deviceTokens: []string{},
}
deviceTokens := []string{"Token1", "Token2", "Token3"}
svc.AddReceivers(deviceTokens...)

assert.Equal(svc.deviceTokens, deviceTokens)
}

func TestBuildNotification(t *testing.T) {
t.Parallel()

assert := require.New(t)
notification := buildNotification("<token>", "<topic>", "test notification")
assert.IsType(new(apnsSvc.Notification), notification)

assert.Equal(notification.Topic, "<topic>")
assert.Equal(notification.DeviceToken, "<token>")
}

func TestSend(t *testing.T) {
t.Parallel()

assert := require.New(t)

client := &mockApns2Client{}
notification := buildNotification("<token>", "<topic>", "subject message")
client.On("Push", notification).Return(&apnsSvc.Response{
StatusCode: 200,
Reason: "",
ApnsID: "<apns-id>",
Timestamp: apnsSvc.Time{},
}, nil)

svc := &Service{
client: client,
topic: "<topic>",
deviceTokens: []string{"<token>"},
}
err := svc.Send(context.Background(), "subject", "message")

assert.Nil(err)
}
53 changes: 53 additions & 0 deletions service/apns2/mock_apns2_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.