Skip to content

Commit

Permalink
[CH-5425] Fix apns-expiration request header logic (#9) (#237)
Browse files Browse the repository at this point in the history
Co-authored-by: Zijin Li <zijin.li@braze.com>
  • Loading branch information
sideshow and zijinlibraze authored Oct 23, 2024
1 parent 83ca0a4 commit b1e286b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func setHeaders(r *http.Request, n *Notification) {
if n.Priority > 0 {
r.Header.Set("apns-priority", strconv.Itoa(n.Priority))
}
if !n.Expiration.IsZero() {
if n.Expiration.After(time.Unix(0, 0)) {
r.Header.Set("apns-expiration", strconv.FormatInt(n.Expiration.Unix(), 10))
}
if n.PushType != "" {
Expand Down
19 changes: 19 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,25 @@ func TestHeaders(t *testing.T) {
assert.NoError(t, err)
}

func TestExpirationHeader(t *testing.T) {
n := mockNotification()
n.ApnsID = "84DB694F-464F-49BD-960A-D6DB028335C9"
n.CollapseID = "game1.start.identifier"
n.Topic = "com.testapp"
n.Priority = 10
n.Expiration = time.Unix(0, 0)
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, n.ApnsID, r.Header.Get("apns-id"))
assert.Equal(t, n.CollapseID, r.Header.Get("apns-collapse-id"))
assert.Equal(t, "10", r.Header.Get("apns-priority"))
assert.Equal(t, n.Topic, r.Header.Get("apns-topic"))
assert.Equal(t, "", r.Header.Get("apns-expiration"))
}))
defer server.Close()
_, err := mockClient(server.URL).Push(n)
assert.NoError(t, err)
}

func TestPushTypeAlertHeader(t *testing.T) {
n := mockNotification()
n.PushType = apns.PushTypeAlert
Expand Down

0 comments on commit b1e286b

Please sign in to comment.