server/browser_stack_family_test.go (2201B)
1 package main 2 3 import ( 4 "context" 5 "crypto/sha256" 6 "fmt" 7 "net/http/httptest" 8 "os" 9 "os/exec" 10 "path/filepath" 11 "runtime" 12 "slices" 13 "testing" 14 "time" 15 ) 16 17 func TestBrowserStackJoinReviewedAnchors(t *testing.T) { 18 if os.Getenv("AO_GAME_TEST") != "1" { 19 t.Skip("set AO_GAME_TEST=1 for reviewed stack anchors") 20 } 21 22 _, source, _, _ := runtime.Caller(0) 23 root := filepath.Dir(filepath.Dir(source)) 24 output := filepath.Join(root, "local/stack-family", time.Now().Format("20060102-150405")) 25 world := newTestServer(t) 26 player := world.newCharacter() 27 player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("stack-family"))) 28 if err := world.saveUser(player); err != nil { 29 t.Fatal(err) 30 } 31 for _, item := range []struct { 32 template, quality uint32 33 count uint16 34 }{{25812, 2, 3}, {25811, 2, 5}, {25812, 101, 3}, {25811, 101, 5}} { 35 if granted, err := world.grantItem(player, item.template); err != nil || !granted { 36 t.Fatal(granted, err) 37 } 38 player.inventory.Items[len(player.inventory.Items)-1].Quality = item.quality 39 player.inventory.Items[len(player.inventory.Items)-1].Count = item.count 40 } 41 if err := world.saveInventory(player, player.inventory); err != nil { 42 t.Fatal(err) 43 } 44 shutdown := startTestService(t, world) 45 host := httptest.NewServer(world.httpHandler()) 46 t.Cleanup(host.Close) 47 ctx, cancel := context.WithTimeout(context.Background(), time.Minute) 48 defer cancel() 49 50 command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_stack_family.mjs"), host.URL, output) 51 command.Dir, command.Stdout, command.Stderr = root, os.Stdout, os.Stderr 52 err := command.Run() 53 host.Close() 54 if err := shutdown(); err != nil { 55 t.Fatal(err) 56 } 57 t.Logf("Browser artifacts: %s", output) 58 59 if err != nil { 60 t.Fatal(err) 61 } 62 cold := newTestInventoryServer(t) 63 expected := []ownedItem{{ID: 2, Type: 51005, Template: 25811, Quality: 2, Slot: 65, Count: 8}, 64 {ID: 3, Type: 51005, Template: 25812, Quality: 101, Slot: 66, Count: 8}} 65 if !slices.Equal(player.inventory.Items, expected) || !slices.Equal(cold.characters[1].inventory.Items, expected) || 66 cold.nextItem != 4 { 67 t.Fatal("reviewed-anchor join lost quantities, identity or placement") 68 } 69 }