2026-06-11 18:33:30 +08:00

50 lines
1.3 KiB
Go

package app
import (
"testing"
"google.golang.org/protobuf/proto"
roomeventsv1 "hyapp.local/api/proto/events/room/v1"
"hyapp/pkg/roommq"
)
func TestRoomGiftCPEventFromRoomMessageIncludesNormalGift(t *testing.T) {
body, err := proto.Marshal(&roomeventsv1.RoomGiftSent{
SenderUserId: 1001,
TargetUserId: 1002,
GiftId: "rose",
GiftCount: 1,
GiftValue: 100,
BillingReceiptId: "receipt-normal",
CommandId: "cmd-normal",
GiftTypeCode: "normal",
GiftName: "Rose",
})
if err != nil {
t.Fatalf("marshal room gift sent failed: %v", err)
}
encoded, err := roommq.EncodeRoomOutboxMessage(&roomeventsv1.EventEnvelope{
AppCode: "lalu",
EventId: "room_evt_normal_gift",
EventType: "RoomGiftSent",
RoomId: "room-1",
RoomVersion: 7,
OccurredAtMs: 1700000000000,
Body: body,
})
if err != nil {
t.Fatalf("encode room outbox message failed: %v", err)
}
event, ok, err := roomGiftCPEventFromRoomMessage(encoded)
if err != nil {
t.Fatalf("convert room gift event failed: %v", err)
}
if !ok {
t.Fatal("normal gifts must reach CP consumer so active relationships can gain intimacy")
}
if event.CPRelationType != "" || event.GiftTypeCode != "normal" || event.GiftValue != 100 || event.TargetUserID != 1002 {
t.Fatalf("normal gift event mismatch: %+v", event)
}
}