Sync telesrv 4c0e2d9 (feat: complete official star gift lifecycle and admin tooling). Public adjustments: skipped private docs/deploy-nginx/README source changes, kept iamxvbaba/td public dependency, replaced local/private sample IP and orange seed label.
95 lines
3.7 KiB
Go
95 lines
3.7 KiB
Go
package domain
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestSavedStarGiftRefRequiresOneOfficialIdentity(t *testing.T) {
|
|
user := Peer{Type: PeerTypeUser, ID: 42}
|
|
channel := Peer{Type: PeerTypeChannel, ID: 84}
|
|
tests := []struct {
|
|
name string
|
|
ref SavedStarGiftRef
|
|
want bool
|
|
}{
|
|
{name: "user message", ref: SavedStarGiftRef{Owner: user, MsgID: 10}, want: true},
|
|
{name: "channel saved id", ref: SavedStarGiftRef{Owner: channel, SavedID: 20}, want: true},
|
|
{name: "user collectible slug", ref: SavedStarGiftRef{Owner: user, Slug: "official-42-1"}, want: true},
|
|
{name: "channel collectible slug", ref: SavedStarGiftRef{Owner: channel, Slug: "official-84-1"}, want: true},
|
|
{name: "message and slug", ref: SavedStarGiftRef{Owner: user, MsgID: 10, Slug: "official-42-1"}},
|
|
{name: "saved id and slug", ref: SavedStarGiftRef{Owner: channel, SavedID: 20, Slug: "official-84-1"}},
|
|
{name: "whitespace slug", ref: SavedStarGiftRef{Owner: user, Slug: " official-42-1"}},
|
|
{name: "oversized slug", ref: SavedStarGiftRef{Owner: user, Slug: strings.Repeat("x", MaxStarGiftSlugBytes+1)}},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := tt.ref.Valid(); got != tt.want {
|
|
t.Fatalf("Valid() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestStarGiftLifecycleStatusRequiresExplicitActive(t *testing.T) {
|
|
if StarGiftLifecycleStatus("").Live() {
|
|
t.Fatal("empty lifecycle status must not be treated as active")
|
|
}
|
|
if !StarGiftLifecycleActive.Live() {
|
|
t.Fatal("active lifecycle status must be live")
|
|
}
|
|
}
|
|
|
|
func validCollectibleDraft() StarGiftCollectibleWrite {
|
|
animation := &StarGiftAnimation{JSON: []byte(`{}`), TGS: []byte{1}, SHA256: make([]byte, sha256.Size)}
|
|
return StarGiftCollectibleWrite{
|
|
GiftID: 1, UpgradeStars: 25, SupplyTotal: 100, SlugPrefix: "official-1", CommandID: "test",
|
|
Models: []StarGiftCollectibleAttribute{
|
|
{Kind: StarGiftCollectibleModel, Name: "Regular", RarityKind: StarGiftRarityPermille, RarityPermille: 922, Animation: animation},
|
|
{Kind: StarGiftCollectibleModel, Name: "Crafted", RarityKind: StarGiftRarityLegendary, Crafted: true, Animation: animation},
|
|
},
|
|
Patterns: []StarGiftCollectibleAttribute{
|
|
{Kind: StarGiftCollectiblePattern, Name: "Pattern", RarityKind: StarGiftRarityPermille, RarityPermille: 989, Animation: animation},
|
|
},
|
|
Backdrops: []StarGiftCollectibleAttribute{
|
|
{Kind: StarGiftCollectibleBackdrop, Name: "Backdrop", BackdropID: 0, RarityKind: StarGiftRarityPermille, RarityPermille: 999},
|
|
},
|
|
}
|
|
}
|
|
|
|
func TestValidateStarGiftCollectibleDraftOfficialProvenance(t *testing.T) {
|
|
write := validCollectibleDraft()
|
|
write.OfficialGiftID = 10
|
|
write.SourceManifestSHA256 = make([]byte, sha256.Size)
|
|
if err := ValidateStarGiftCollectibleDraft(write); err != nil {
|
|
t.Fatalf("valid official draft: %v", err)
|
|
}
|
|
|
|
tests := map[string]StarGiftCollectibleWrite{}
|
|
withoutHash := write
|
|
withoutHash.SourceManifestSHA256 = nil
|
|
tests["official ID without hash"] = withoutHash
|
|
withoutID := write
|
|
withoutID.OfficialGiftID = 0
|
|
tests["hash without official ID"] = withoutID
|
|
negativeID := write
|
|
negativeID.OfficialGiftID = -1
|
|
tests["negative official ID"] = negativeID
|
|
for name, invalid := range tests {
|
|
t.Run(name, func(t *testing.T) {
|
|
if err := ValidateStarGiftCollectibleDraft(invalid); !errors.Is(err, ErrStarGiftCollectibleInvalid) {
|
|
t.Fatalf("err=%v, want ErrStarGiftCollectibleInvalid", err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestValidateStarGiftCollectibleDraftRejectsImplicitRarity(t *testing.T) {
|
|
write := validCollectibleDraft()
|
|
write.Models[0].RarityKind = ""
|
|
if err := ValidateStarGiftCollectibleDraft(write); !errors.Is(err, ErrStarGiftCollectibleInvalid) {
|
|
t.Fatalf("err=%v, want ErrStarGiftCollectibleInvalid", err)
|
|
}
|
|
}
|