added more data to test

This commit is contained in:
2024-12-24 19:05:01 +01:00
parent b011054cb0
commit 412e5c44da
2 changed files with 184 additions and 96 deletions
+104 -76
View File
@@ -8,35 +8,35 @@ type User struct {
}
type Character struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `json:"name"`
Rasse string `json:"rasse"`
Typ string `json:"typ"`
Alter int `json:"alter"`
Anrede string `json:"anrede"`
Grad int `json:"grad"`
Groesse int `json:"groesse"`
Gewicht int `json:"gewicht"`
Glaube string `json:"glaube"`
Hand string `json:"hand"`
Fertigkeiten []Fertigkeit `gorm:"foreignKey:CharacterID" json:"fertigkeiten"`
Zauber []Zauber `gorm:"foreignKey:CharacterID" json:"zauber"`
Lp Lp `gorm:"foreignKey:CharacterID" json:"lp"`
Eigenschaften []Eigenschaft `gorm:"foreignKey:CharacterID" json:"eigenschaften"`
Merkmale Merkmale `gorm:"foreignKey:CharacterID" json:"merkmale"`
ID uint `gorm:"primaryKey" json:"id"`
Name string `json:"name"`
Rasse string `json:"rasse"`
Typ string `json:"typ"`
Alter int `json:"alter"`
Anrede string `json:"anrede"`
Grad int `json:"grad"`
Groesse int `json:"groesse"`
Gewicht int `json:"gewicht"`
Glaube string `json:"glaube"`
Hand string `json:"hand"`
Fertigkeiten []Fertigkeit `gorm:"foreignKey:CharacterID" json:"fertigkeiten"`
Zauber []Zauber `gorm:"foreignKey:CharacterID" json:"zauber"`
Lp Lp `gorm:"foreignKey:CharacterID" json:"lp"`
Eigenschaften []Eigenschaft `gorm:"foreignKey:CharacterID" json:"eigenschaften"`
Merkmale Merkmale `gorm:"foreignKey:CharacterID" json:"merkmale"`
Bennies Bennies `gorm:"foreignKey:CharacterID" json:"bennies"`
Gestalt Gestalt `gorm:"foreignKey:CharacterID" json:"gestalt"`
Ap Ap `gorm:"foreignKey:CharacterID" json:"ap"`
B B `gorm:"foreignKey:CharacterID" json:"b"`
Erfahrungsschatz Erfahrungsschatz `gorm:"foreignKey:CharacterID" json:"erfahrungsschatz"`
Transportmittel []Transportation `gorm:"foreignKey:CharacterID" json:"transportmittel"`
Ausruestung []Ausruestung `gorm:"foreignKey:CharacterID" json:"ausruestung"`
Behaeltnisse []Behaeltniss `gorm:"foreignKey:CharacterID" json:"behaeltnisse"`
Waffen []Waffe `gorm:"foreignKey:CharacterID" json:"waffen"`
/*
Ausruestung []Ausruestung `gorm:"foreignKey:CharacterID" json:"ausruestung"`
Behaeltnisse []Behaeltniss `gorm:"foreignKey:CharacterID" json:"behaeltnisse"`
Waffenfertigkeiten []Waffenfertigkeit `gorm:"foreignKey:CharacterID" json:"waffenfertigkeiten"`
Waffen []Waffe `gorm:"foreignKey:CharacterID" json:"waffen"`
Bennies Bennies `gorm:"foreignKey:CharacterID" json:"bennies"`
Gestalt Gestalt `gorm:"foreignKey:CharacterID" json:"gestalt"`
Ap Ap `gorm:"foreignKey:CharacterID" json:"ap"`
B B `gorm:"foreignKey:CharacterID" json:"b"`
Spezialisierung []string `json:"spezialisierung"`
Image string `json:"image,omitempty"`
Transportmittel []Transportmittel `gorm:"foreignKey:CharacterID" json:"transportmittel"`
Erfahrungsschatz Erfahrungsschatz `gorm:"foreignKey:CharacterID" json:"erfahrungsschatz"`
*/
}
@@ -48,16 +48,16 @@ type Eigenschaft struct {
}
type Ausruestung struct {
ID uint `gorm:"primaryKey"`
CharacterID uint `gorm:"index" json:"character_id"`
Name string `json:"name"`
Beschreibung string `json:"beschreibung"`
Anzahl int `json:"anzahl"`
BeinhaltetIn *string `json:"beinhaltet_in"`
Bonus int `json:"bonus,omitempty"`
Gewicht float64 `json:"gewicht"`
Magisch Magisch `gorm:"polymorphic:Item;polymorphicValue:Ausruestung" json:"magisch"`
Wert float64 `json:"wert"`
ID uint `gorm:"primaryKey"`
CharacterID uint `gorm:"index" json:"character_id"`
Name string `json:"name"`
Beschreibung string `json:"beschreibung"`
Anzahl int `json:"anzahl"`
BeinhaltetIn *string `json:"beinhaltet_in"`
Bonus int `json:"bonus,omitempty"`
Gewicht float64 `json:"gewicht"`
Magisch MagischAusruestung `gorm:"foreignKey:AusruestungID" json:"magisch"`
Wert float64 `json:"wert"`
}
type Fertigkeit struct {
@@ -92,19 +92,19 @@ type Waffenfertigkeit struct {
}
type Waffe struct {
ID uint `gorm:"primaryKey"`
CharacterID uint `gorm:"index" json:"character_id"`
Name string `json:"name"`
Beschreibung string `json:"beschreibung"`
Abwb int `json:"abwb"`
Anb int `json:"anb"`
Anzahl int `json:"anzahl"`
BeinhaltetIn *string `json:"beinhaltet_in"`
Gewicht float64 `json:"gewicht"`
Magisch Magisch `gorm:"polymorphic:Item;polymorphicValue:Ausruestung" json:"magisch"`
NameFuerSpezialisierung string `json:"nameFuerSpezialisierung"`
Schb int `json:"schb"`
Wert float64 `json:"wert"`
ID uint `gorm:"primaryKey"`
CharacterID uint `gorm:"index" json:"character_id"`
Name string `json:"name"`
Beschreibung string `json:"beschreibung"`
Abwb int `json:"abwb"`
Anb int `json:"anb"`
Anzahl int `json:"anzahl"`
BeinhaltetIn *string `json:"beinhaltet_in"`
Gewicht float64 `json:"gewicht"`
Magisch MagischWaffe `gorm:"foreignKey:WaffenID" json:"magisch"`
NameFuerSpezialisierung string `json:"nameFuerSpezialisierung"`
Schb int `json:"schb"`
Wert float64 `json:"wert"`
}
type Merkmale struct {
@@ -160,16 +160,16 @@ type Bennies struct {
}
type Behaeltniss struct {
ID uint `gorm:"primaryKey"`
CharacterID uint `gorm:"index" json:"character_id"`
Name string `json:"name"`
Beschreibung string `json:"beschreibung"`
BeinhaltetIn any `json:"beinhaltet_in"`
Gewicht float64 `json:"gewicht"`
Magisch Magisch `gorm:"polymorphic:Item;polymorphicValue:Ausruestung" json:"magisch"`
Tragkraft float64 `json:"tragkraft"`
Volumen float64 `json:"volumen"`
Wert float64 `json:"wert"`
ID uint `gorm:"primaryKey"`
CharacterID uint `gorm:"index" json:"character_id"`
Name string `json:"name"`
Beschreibung string `json:"beschreibung"`
//BeinhaltetIn any `json:"beinhaltet_in"`
Gewicht float64 `json:"gewicht"`
Magisch MagischBehaelter `gorm:"foreignKey:BehaeltnissID" json:"magisch"`
Tragkraft float64 `json:"tragkraft"`
Volumen float64 `json:"volumen"`
Wert float64 `json:"wert"`
}
type Ap struct {
@@ -186,25 +186,53 @@ type B struct {
Value int `json:"value"`
}
type Transportmittel struct {
ID uint `gorm:"primaryKey"`
CharacterID uint `gorm:"index" json:"character_id"`
Name string `json:"name"`
Beschreibung string `json:"beschreibung"`
BeinhaltetIn any `json:"beinhaltet_in"`
Gewicht int `json:"gewicht"`
Tragkraft float64 `json:"tragkraft"`
Wert float64 `json:"wert"`
Magisch Magisch `gorm:"polymorphic:Item;polymorphicValue:Ausruestung" json:"magisch"`
type Transportation struct {
ID uint `gorm:"primaryKey"`
CharacterID uint `gorm:"index" json:"character_id"`
Name string `json:"name"`
Beschreibung string `json:"beschreibung"`
//BeinhaltetIn any `json:"beinhaltet_in"`
Gewicht int `json:"gewicht"`
Tragkraft float64 `json:"tragkraft"`
Wert float64 `json:"wert"`
Magisch MagischTransport `gorm:"foreignKey:TransportationID" json:"magisch"`
//Magisch Magisch `gorm:"polymorphic:Item;polymorphicValue:Transportmittel" json:"magisch"`
}
type Magisch struct {
ID uint `gorm:"primaryKey" json:"id"`
ItemType string `gorm:"index" json:"item_type"` // Type of the referenced item (e.g., "Ausruestung")
ItemID uint `gorm:"index" json:"item_id"` // ID of the referenced item
Abw int `json:"abw"`
Ausgebrannt bool `json:"ausgebrannt"`
IstMagisch bool `json:"ist_magisch"`
type MagischAusruestung struct {
ID uint `gorm:"primaryKey" json:"id"`
//ItemType string `gorm:"index" json:"item_type"` // Type of the referenced item (e.g., "Ausruestung")
//ItemID uint `gorm:"index" json:"item_id"` // ID of the referenced item
AusruestungID int `gorm:"index" json:"ausruestung_id"`
Abw int `json:"abw"`
Ausgebrannt bool `json:"ausgebrannt"`
IstMagisch bool `json:"ist_magisch"`
}
type MagischWaffe struct {
ID uint `gorm:"primaryKey" json:"id"`
//ItemType string `gorm:"index" json:"item_type"` // Type of the referenced item (e.g., "Ausruestung")
//ItemID uint `gorm:"index" json:"item_id"` // ID of the referenced item
WaffenID int `gorm:"index" json:"waffen_id"`
Abw int `json:"abw"`
Ausgebrannt bool `json:"ausgebrannt"`
IstMagisch bool `json:"ist_magisch"`
}
type MagischBehaelter struct {
ID uint `gorm:"primaryKey" json:"id"`
//ItemType string `gorm:"index" json:"item_type"` // Type of the referenced item (e.g., "Ausruestung")
//ItemID uint `gorm:"index" json:"item_id"` // ID of the referenced item
BehaeltnissID int `gorm:"index" json:"behaeltniss_id"`
Abw int `json:"abw"`
Ausgebrannt bool `json:"ausgebrannt"`
IstMagisch bool `json:"ist_magisch"`
}
type MagischTransport struct {
ID uint `gorm:"primaryKey" json:"id"`
//ItemType string `gorm:"index" json:"item_type"` // Type of the referenced item (e.g., "Ausruestung")
//ItemID uint `gorm:"index" json:"item_id"` // ID of the referenced item
TransportationID int `gorm:"index" json:"transportation_id"`
Abw int `json:"abw"`
Ausgebrannt bool `json:"ausgebrannt"`
IstMagisch bool `json:"ist_magisch"`
}
/*
+80 -20
View File
@@ -17,8 +17,23 @@ func SetupTestDB() *gorm.DB {
}
// Auto-migrate the schemas for all related models
db.AutoMigrate(&Character{}, &Fertigkeit{}, &Zauber{}, &Lp{}, &Eigenschaft{}, &Merkmale{}) //, &Ausruestung{}, &Behaeltniss{}, &Waffenfertigkeit{},
// &Waffe{}, &Ap{}, &B{}, &Transportmittel{}, &Erfahrungsschatz{}, &Magisch{})
db.AutoMigrate(&Character{},
&Fertigkeit{}, &Zauber{}, &Lp{},
&Eigenschaft{}, &Merkmale{},
&Bennies{},
&Gestalt{},
&Ap{}, &B{},
&Erfahrungsschatz{},
&MagischTransport{},
&Transportation{},
&MagischAusruestung{},
&Ausruestung{},
&MagischBehaelter{},
&Behaeltniss{},
&MagischWaffe{},
&Waffe{},
// &Waffenfertigkeit{},
)
return db
}
@@ -44,14 +59,6 @@ func TestSaveCharacterToDB(t *testing.T) {
{Name: "St", Value: 80},
{Name: "Zt", Value: 100},
},
/*
Ausruestung: []Ausruestung{
{Name: "Staff", Beschreibung: "Magic Staff", Anzahl: 1, Gewicht: 2.5, Wert: 500},
},
Behaeltnisse: []Behaeltniss{
{Name: "Backpack", Beschreibung: "Leather backpack", Gewicht: 1.5, Tragkraft: 10, Volumen: 20, Wert: 50},
},
*/
Fertigkeiten: []Fertigkeit{
{Name: "Stehlen", Beschreibung: "jemandem etwas wegnehmen ohne das der es merkt", Fertigkeitswert: 6},
{Name: "Geländelauf", Beschreibung: "Lauf um Hindernisse herum", Fertigkeitswert: 12},
@@ -68,12 +75,49 @@ func TestSaveCharacterToDB(t *testing.T) {
Haarfarbe: "Blonde",
Sonstige: "Scar on the left cheek",
},
/*
Ap: Ap{
Max: 50,
Value: 40,
Bennies: Bennies{
Gg: 1,
Gp: 0,
Sg: 2,
},
Gestalt: Gestalt{
Breite: "schmal",
Groesse: "klein",
},
Ap: Ap{
Max: 50,
Value: 40,
},
B: B{
Max: 25,
Value: 20,
},
Erfahrungsschatz: Erfahrungsschatz{
Value: 2768,
},
Transportmittel: []Transportation{
{Name: "Karren",
Beschreibung: "ein Karren",
Gewicht: 100, Tragkraft: 300, Wert: 55,
Magisch: MagischTransport{IstMagisch: true, Abw: 30, Ausgebrannt: false},
},
*/
},
Ausruestung: []Ausruestung{
{Name: "Staff", Beschreibung: "Magic Staff", Anzahl: 1, Gewicht: 2.5, Wert: 500,
Magisch: MagischAusruestung{IstMagisch: true, Abw: 10, Ausgebrannt: false},
},
},
Behaeltnisse: []Behaeltniss{
{Name: "Backpack", Beschreibung: "Leather backpack",
Gewicht: 1.5, Tragkraft: 10, Volumen: 20, Wert: 50,
//Magisch: MagischBehaelter{IstMagisch: false},
},
},
Waffen: []Waffe{
{Name: "Schwert", Beschreibung: "Ein schwert", Abwb: 0, Anb: 0, Gewicht: 1.5, NameFuerSpezialisierung: "Schwert", Schb: 0, Wert: 3,
Magisch: MagischWaffe{IstMagisch: false}},
},
}
fmt.Println(character)
@@ -87,8 +131,22 @@ func TestSaveCharacterToDB(t *testing.T) {
var savedCharacter Character
//err = DB.Preload("Eigenschaften").Preload("Ausruestung").Preload("Behaeltnisse").
// Preload("Fertigkeiten").Preload("Merkmale").Preload("Lp").Preload("Ap").
err = DB.Preload("Fertigkeiten").Preload("Zauber").Preload("Lp").
Preload("Eigenschaften").Preload("Merkmale").
err = DB.
Preload("Eigenschaften").
Preload("Fertigkeiten").
Preload("Zauber").
Preload("Lp").
Preload("Merkmale").
Preload("Bennies").
Preload("Gestalt").
Preload("Ap").
Preload("B").
Preload("Erfahrungsschatz").
//Preload("Magisch").
Preload("Transportmittel").
Preload("Ausruestung").
Preload("Behaeltnisse").
Preload("Waffen").
First(&savedCharacter, "name = ?", "Test Character").Error
assert.NoError(t, err, "Expected to find the character in the database")
assert.Equal(t, "Test Character", savedCharacter.Name)
@@ -100,10 +158,12 @@ func TestSaveCharacterToDB(t *testing.T) {
assert.Equal(t, "Au", savedCharacter.Eigenschaften[0].Name)
assert.Equal(t, 50, savedCharacter.Eigenschaften[0].Value)
assert.Equal(t, "Blau", savedCharacter.Merkmale.Augenfarbe)
assert.Equal(t, 1, len(savedCharacter.Ausruestung))
assert.Equal(t, "Staff", savedCharacter.Ausruestung[0].Name)
assert.Equal(t, "Blau", savedCharacter.Merkmale.Augenfarbe)
assert.Equal(t, "Backpack", savedCharacter.Behaeltnisse[0].Name)
assert.Equal(t, "Schwert", savedCharacter.Waffen[0].Name)
/*
assert.Equal(t, 1, len(savedCharacter.Ausruestung))
assert.Equal(t, "Staff", savedCharacter.Ausruestung[0].Name)
assert.Equal(t, "Blue", savedCharacter.Merkmale.Augenfarbe)
assert.Equal(t, 40, savedCharacter.Ap.Value)
*/
}