46 lines
1.7 KiB
Go
46 lines
1.7 KiB
Go
package command
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
)
|
|
|
|
func TestSendGiftIdempotencyIgnoresGatewayResolvedSnapshots(t *testing.T) {
|
|
base := SendGift{
|
|
Base: Base{CommandID: "combo-1_b1", Room: "room-1", ActorID: 42},
|
|
TargetType: "user", TargetUserIDs: []int64{43}, TargetUserID: 43,
|
|
GiftID: "rose", GiftCount: 9, ComboSessionID: "combo-1", BatchSeq: 1,
|
|
SenderRegionID: 1001, SenderCountryID: 840,
|
|
TargetHostScopes: []GiftTargetHostScope{{TargetUserID: 43, TargetIsHost: true, TargetHostRegionID: 1001}},
|
|
SenderDisplayProfile: GiftDisplayProfile{UserID: 42, Username: "before"},
|
|
}
|
|
retry := base
|
|
retry.SenderRegionID = 2002
|
|
retry.SenderCountryID = 356
|
|
retry.TargetHostScopes = []GiftTargetHostScope{{TargetUserID: 43, TargetIsHost: false}}
|
|
retry.SenderDisplayProfile = GiftDisplayProfile{UserID: 42, Username: "after"}
|
|
|
|
left, err := IdempotencyPayloadForCommand(base)
|
|
if err != nil {
|
|
t.Fatalf("base payload: %v", err)
|
|
}
|
|
right, err := IdempotencyPayloadForCommand(retry)
|
|
if err != nil {
|
|
t.Fatalf("retry payload: %v", err)
|
|
}
|
|
if !bytes.Equal(left, right) {
|
|
t.Fatalf("gateway snapshot drift changed client idempotency semantics:\nleft=%s\nright=%s", left, right)
|
|
}
|
|
}
|
|
|
|
func TestSendGiftIdempotencyKeepsComboBatchIdentity(t *testing.T) {
|
|
base := SendGift{Base: Base{CommandID: "combo-1_b1", Room: "room-1", ActorID: 42}, TargetType: "user", TargetUserIDs: []int64{43}, TargetUserID: 43, GiftID: "rose", GiftCount: 1, ComboSessionID: "combo-1", BatchSeq: 1}
|
|
reused := base
|
|
reused.BatchSeq = 2
|
|
left, _ := IdempotencyPayloadForCommand(base)
|
|
right, _ := IdempotencyPayloadForCommand(reused)
|
|
if bytes.Equal(left, right) {
|
|
t.Fatal("same command_id reused for another combo batch was not detected")
|
|
}
|
|
}
|