alle stammdaten getestet für create und find
This commit is contained in:
@@ -171,9 +171,9 @@ type Behaeltniss struct {
|
||||
//BeinhaltetIn any `json:"beinhaltet_in"`
|
||||
Gewicht float64 `json:"gewicht"`
|
||||
Magisch MagischBehaelter `gorm:"foreignKey:BehaeltnissID" json:"magisch"`
|
||||
Wert float64 `json:"wert"`
|
||||
Tragkraft float64 `json:"tragkraft"`
|
||||
Volumen float64 `json:"volumen"`
|
||||
Wert float64 `json:"wert"`
|
||||
}
|
||||
|
||||
type Ap struct {
|
||||
|
||||
@@ -31,6 +31,7 @@ type ImStammFertigkeit struct {
|
||||
Initialkeitswert int `json:"initialwert"`
|
||||
Bonuseigenschaft string `json:"bonuseigenschaft,omitempty"`
|
||||
}
|
||||
|
||||
type ImStammWaffenFertigkeit struct {
|
||||
ImStammFertigkeit
|
||||
}
|
||||
@@ -44,6 +45,22 @@ type ImStammZauber struct {
|
||||
Wirkungsziel string
|
||||
}
|
||||
|
||||
type ImStammAusruestung struct {
|
||||
ImStamm
|
||||
Gewicht float64 `json:"gewicht"`
|
||||
Wert float64 `json:"wert"`
|
||||
}
|
||||
|
||||
type ImStammBehaeltniss struct {
|
||||
ImStammAusruestung
|
||||
Tragkraft float64 `json:"tragkraft"`
|
||||
Volumen float64 `json:"volumen"`
|
||||
}
|
||||
|
||||
type ImStammTransportation struct {
|
||||
ImStammBehaeltniss
|
||||
}
|
||||
|
||||
func (stamm *ImStamm) First(name string) error {
|
||||
gameSystem := "midgard"
|
||||
err := database.DB.First(&stamm, "system=? AND name = ?", gameSystem, name).Error
|
||||
@@ -139,3 +156,74 @@ func (stamm *ImStammZauber) Create() error {
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (stamm *ImStammAusruestung) First(name string) error {
|
||||
gameSystem := "midgard"
|
||||
err := database.DB.First(&stamm, "system=? AND name = ?", gameSystem, name).Error
|
||||
if err != nil {
|
||||
// zauber found
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (stamm *ImStammAusruestung) Create() error {
|
||||
gameSystem := "midgard"
|
||||
stamm.System = gameSystem
|
||||
err := database.DB.Transaction(func(tx *gorm.DB) error {
|
||||
// Save the main character record
|
||||
if err := tx.Create(&stamm).Error; err != nil {
|
||||
return fmt.Errorf("failed to save Stammdaten: %w", err)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (stamm *ImStammBehaeltniss) First(name string) error {
|
||||
gameSystem := "midgard"
|
||||
err := database.DB.First(&stamm, "system=? AND name = ?", gameSystem, name).Error
|
||||
if err != nil {
|
||||
// zauber found
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (stamm *ImStammBehaeltniss) Create() error {
|
||||
gameSystem := "midgard"
|
||||
stamm.System = gameSystem
|
||||
err := database.DB.Transaction(func(tx *gorm.DB) error {
|
||||
// Save the main character record
|
||||
if err := tx.Create(&stamm).Error; err != nil {
|
||||
return fmt.Errorf("failed to save Stammdaten: %w", err)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
func (stamm *ImStammTransportation) First(name string) error {
|
||||
gameSystem := "midgard"
|
||||
err := database.DB.First(&stamm, "system=? AND name = ?", gameSystem, name).Error
|
||||
if err != nil {
|
||||
// zauber found
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (stamm *ImStammTransportation) Create() error {
|
||||
gameSystem := "midgard"
|
||||
stamm.System = gameSystem
|
||||
err := database.DB.Transaction(func(tx *gorm.DB) error {
|
||||
// Save the main character record
|
||||
if err := tx.Create(&stamm).Error; err != nil {
|
||||
return fmt.Errorf("failed to save Stammdaten: %w", err)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -15,6 +15,9 @@ func initTestDB4Stammdaten() *gorm.DB {
|
||||
&models.ImStammFertigkeit{}, //needed for stammdaten.CheckFertigkeit
|
||||
&models.ImStammZauber{}, //needed for stammdaten.CheckZauber
|
||||
&models.ImStammWaffenFertigkeit{}, //needed for stammdaten.CheckWaffenFertigkeit
|
||||
&models.ImStammAusruestung{}, //needed for stammdaten.Check...
|
||||
&models.ImStammBehaeltniss{}, //needed for stammdaten.Check...
|
||||
&models.ImStammTransportation{}, //needed for stammdaten.Check...
|
||||
)
|
||||
return db
|
||||
}
|
||||
@@ -121,3 +124,97 @@ func TestFindStammdatenZauber(t *testing.T) {
|
||||
assert.Equal(t, "Zauberer", stamm.Wirkungsziel)
|
||||
assert.Equal(t, 0, stamm.Bonus)
|
||||
}
|
||||
|
||||
func TestCreateStammdatenAusruestung(t *testing.T) {
|
||||
// Setup test database
|
||||
testDB := initTestDB4Stammdaten()
|
||||
database.DB = testDB // Assign test DB to global DB
|
||||
stamm := models.ImStammAusruestung{}
|
||||
stamm.System = "Midgard"
|
||||
stamm.Name = "Decke"
|
||||
stamm.Beschreibung = "zum zudecken"
|
||||
stamm.Quelle = "kod-4713"
|
||||
stamm.Gewicht = 0.2
|
||||
stamm.Wert = 300
|
||||
err := stamm.Create()
|
||||
assert.NoError(t, err, "expexted Error does not exist in Fertigkeit Stammdaten")
|
||||
assert.GreaterOrEqual(t, 1, int(stamm.ID), "exepets an ID to be present")
|
||||
assert.Equal(t, "midgard", stamm.System)
|
||||
}
|
||||
|
||||
func TestFindStammdatenAusruestung(t *testing.T) {
|
||||
// Setup test database
|
||||
TestCreateStammdatenAusruestung(t)
|
||||
stamm := models.ImStammAusruestung{}
|
||||
stamm.Name = "Lesen"
|
||||
|
||||
err := stamm.First("Decke")
|
||||
assert.NoError(t, err, "expexted Error does not exist in Fertigkeit Stammdaten")
|
||||
assert.GreaterOrEqual(t, 1, int(stamm.ID), "exepets an ID to be present")
|
||||
assert.Equal(t, "midgard", stamm.System)
|
||||
assert.Equal(t, 0.2, stamm.Gewicht)
|
||||
}
|
||||
|
||||
func TestCreateStammdatenBehaeltniss(t *testing.T) {
|
||||
// Setup test database
|
||||
testDB := initTestDB4Stammdaten()
|
||||
database.DB = testDB // Assign test DB to global DB
|
||||
stamm := models.ImStammBehaeltniss{}
|
||||
stamm.System = "Midgard"
|
||||
stamm.Name = "Topf"
|
||||
stamm.Beschreibung = "zum kochen"
|
||||
stamm.Quelle = "kod-4714"
|
||||
stamm.Gewicht = 0.6
|
||||
stamm.Wert = 300
|
||||
stamm.Volumen = 12.2
|
||||
err := stamm.Create()
|
||||
assert.NoError(t, err, "expexted Error does not exist in Fertigkeit Stammdaten")
|
||||
assert.GreaterOrEqual(t, 1, int(stamm.ID), "exepets an ID to be present")
|
||||
assert.Equal(t, "midgard", stamm.System)
|
||||
}
|
||||
|
||||
func TestFindStammdatenBehaeltniss(t *testing.T) {
|
||||
// Setup test database
|
||||
TestCreateStammdatenBehaeltniss(t)
|
||||
stamm := models.ImStammBehaeltniss{}
|
||||
stamm.Name = "Lesen"
|
||||
|
||||
err := stamm.First("Topf")
|
||||
assert.NoError(t, err, "expexted Error does not exist in Fertigkeit Stammdaten")
|
||||
assert.GreaterOrEqual(t, 1, int(stamm.ID), "exepets an ID to be present")
|
||||
assert.Equal(t, "midgard", stamm.System)
|
||||
assert.Equal(t, 0.6, stamm.Gewicht)
|
||||
assert.Equal(t, 12.2, stamm.Volumen)
|
||||
}
|
||||
|
||||
func TestCreateStammdatenTransportation(t *testing.T) {
|
||||
// Setup test database
|
||||
testDB := initTestDB4Stammdaten()
|
||||
database.DB = testDB // Assign test DB to global DB
|
||||
stamm := models.ImStammTransportation{}
|
||||
stamm.System = "Midgard"
|
||||
stamm.Name = "Topf"
|
||||
stamm.Beschreibung = "zum kochen"
|
||||
stamm.Quelle = "kod-4714"
|
||||
stamm.Gewicht = 0.6
|
||||
stamm.Wert = 300
|
||||
stamm.Volumen = 12.5
|
||||
err := stamm.Create()
|
||||
assert.NoError(t, err, "expexted Error does not exist in Fertigkeit Stammdaten")
|
||||
assert.GreaterOrEqual(t, 1, int(stamm.ID), "exepets an ID to be present")
|
||||
assert.Equal(t, "midgard", stamm.System)
|
||||
}
|
||||
|
||||
func TestFindStammdatenTransportation(t *testing.T) {
|
||||
// Setup test database
|
||||
TestCreateStammdatenTransportation(t)
|
||||
stamm := models.ImStammTransportation{}
|
||||
stamm.Name = "Lesen"
|
||||
|
||||
err := stamm.First("Topf")
|
||||
assert.NoError(t, err, "expexted Error does not exist in Fertigkeit Stammdaten")
|
||||
assert.GreaterOrEqual(t, 1, int(stamm.ID), "exepets an ID to be present")
|
||||
assert.Equal(t, "midgard", stamm.System)
|
||||
assert.Equal(t, 0.6, stamm.Gewicht)
|
||||
assert.Equal(t, 12.5, stamm.Volumen)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user