Files
im_server/server/push/fcm/payload_test.go
T

56 lines
1.3 KiB
Go

package fcm
import (
"testing"
"time"
"github.com/tinode/chat/server/push"
"github.com/tinode/chat/server/store/types"
)
func TestPayloadToDataIncludesCallExpiresAt(t *testing.T) {
expiresAt := time.Date(2026, 9, 4, 10, 0, 30, 0, time.UTC)
data, err := payloadToData(&push.Payload{
What: push.ActMsg,
Topic: "p2pTopic",
From: "usrCaller",
SeqId: 30,
Webrtc: "started",
ExpiresAt: &expiresAt,
Content: map[string]any{
"txt": "call",
},
Timestamp: time.Date(2026, 9, 4, 10, 0, 0, 0, time.UTC),
})
if err != nil {
t.Fatalf("payload data: %v", err)
}
if data["expires_at"] != expiresAt.Format(time.RFC3339Nano) {
t.Fatalf("unexpected expires_at: %#v", data)
}
}
func TestPrepareV1NotificationsDropsExpiredCallInvite(t *testing.T) {
expiresAt := time.Now().Add(-time.Second)
messages, uids := PrepareV1Notifications(&push.Receipt{
TenantID: 7,
To: map[types.Uid]push.Recipient{
42: {},
},
Payload: push.Payload{
What: push.ActMsg,
Topic: "p2pTopic",
SeqId: 30,
Webrtc: "started",
ExpiresAt: &expiresAt,
Content: map[string]any{
"txt": "call",
},
Timestamp: time.Now().Add(-time.Minute),
},
}, &configType{})
if len(messages) != 0 || len(uids) != 0 {
t.Fatalf("expired call invite should be dropped: messages=%d uids=%#v", len(messages), uids)
}
}