server/control_equipment_slots_test.go (1993B)
1 package main 2 3 import ( 4 "encoding/binary" 5 "fmt" 6 "net/http/httptest" 7 "net/url" 8 "strings" 9 "testing" 10 ) 11 12 func TestControlClothingNamesMatchNativeArmorSlots(t *testing.T) { 13 for _, scenario := range []struct { 14 name string 15 template, slot uint32 16 }{ 17 {"clothes_left_shoulder", 168658, 22}, 18 {"clothes_right_arm", 85742, 23}, 19 {"clothes_hands", 85596, 24}, 20 {"clothes_left_arm", 85742, 25}, 21 } { 22 t.Run(scenario.name, func(t *testing.T) { 23 useNPCData(t, testNPCData()) 24 world := newTestServer(t) 25 postControlForm(world, "/admin/players", url.Values{"name": {"Explorer"}}) 26 created := postControlForm(world, "/admin/items", url.Values{"template": {fmt.Sprint(scenario.template)}}) 27 if created.Code != 303 { 28 t.Fatal(created.Code, created.Body.String()) 29 } 30 data := fmt.Sprintf("equipment: {%s: 1}\n", scenario.name) 31 32 response := postControlForm(world, "/admin/players/1", playerFixtureForm(data)) 33 restarted := newTestInventoryServer(t) 34 page := httptest.NewRecorder() 35 adminTestHandler(world).ServeHTTP(page, httptest.NewRequest("GET", "/admin/players/1", nil)) 36 37 if response.Code != 303 || len(restarted.characters[1].inventory.Items) != 1 { 38 t.Fatal("named clothing placement rejected compatible equipment", response.Code, response.Body.String()) 39 } 40 item := restarted.characters[1].inventory.Items[0] 41 packet := targetPacket(fullCharacterPacket(restarted.characters[1])) 42 if item.ID != 1 || item.Template != scenario.template || item.Slot != scenario.slot || binary.BigEndian.Uint32(packet[37:41]) != scenario.slot { 43 t.Fatal("named clothing placement changed the native identity or slot", item) 44 } 45 if !strings.Contains(withoutItemIcons(page.Body.String()), "<tr><td>"+scenario.name+"</td><td></td><td><a href='admin/items/1'>") || 46 !strings.Contains(withoutItemIcons(page.Body.String()), "name='equipment."+scenario.name+"' value='1'") { 47 t.Fatal("equipment table or form uses a different clothing name") 48 } 49 }) 50 } 51 }