feat: deduplicate ship name on transfer

This commit is contained in:
Ilia Denisov
2026-02-17 22:02:17 +02:00
parent f394c105b0
commit de91d575d0
7 changed files with 100 additions and 30 deletions
+13 -3
View File
@@ -3,6 +3,7 @@ package controller_test
import (
"fmt"
"slices"
"strings"
"testing"
"github.com/google/uuid"
@@ -226,9 +227,6 @@ func TestShipGroupTransfer(t *testing.T) {
assert.ErrorContains(t,
g.ShipGroupTransfer(Race_0.Name, Race_1.Name, uuid.New()),
e.GenericErrorText(e.ErrInputEntityNotExists))
assert.ErrorContains(t,
g.ShipGroupTransfer(Race_0.Name, Race_1.Name, c.ShipGroup(0).ID),
e.GenericErrorText(e.ErrGiveawayGroupShipsTypeNotEqual))
orig := *c.ShipGroup(2)
assert.NoError(t, g.ShipGroupTransfer(Race_0.Name, Race_1.Name, c.ShipGroup(2).ID)) // group #2 (3)
@@ -275,6 +273,18 @@ func TestShipGroupTransfer(t *testing.T) {
assert.ErrorContains(t,
g.ShipGroupTransfer(Race_1.Name, Race_0.Name, sg.ID),
e.GenericErrorText(e.ErrShipsBusy))
// transfer ship class with existing name
originalName := c.MustShipClass(Race_0_idx, ShipType_Cruiser).Name
assert.NoError(t, g.ShipGroupTransfer(Race_0.Name, Race_1.Name, c.ShipGroup(0).ID))
var s *game.ShipType
for st := range c.ListShipTypes(Race_1_idx) {
if strings.HasPrefix(st.Name, originalName) && st.Name != originalName {
s = st
}
}
assert.NotNil(t, s)
assert.Greater(t, len(s.Name), len(originalName))
}
func TestShipGroupLoad(t *testing.T) {