diff --git a/backend/character/test_data_helper.go b/backend/character/test_data_helper.go index 1cceb6a..e63666a 100644 --- a/backend/character/test_data_helper.go +++ b/backend/character/test_data_helper.go @@ -41,7 +41,7 @@ func createTestSkillData() error { // GSM Test-Skill erstellen gsmSkill := models.Skill{ - GameSystem: "midgard", + GameSystemId: 1, Name: "Menschenkenntnis", Beschreibung: "Test Skill", Quelle: "Test", @@ -56,7 +56,7 @@ func createTestSkillData() error { // GSM Test-Spell erstellen gsmSpell := models.Spell{ - GameSystem: "midgard", + GameSystemId: 1, Name: "Macht über das Selbst", Beschreibung: "Test Spell", Quelle: "Test", diff --git a/backend/gsmaster/export_import_test.go b/backend/gsmaster/export_import_test.go index adcc8ab..f24aca5 100644 --- a/backend/gsmaster/export_import_test.go +++ b/backend/gsmaster/export_import_test.go @@ -19,7 +19,7 @@ func TestExportSkills(t *testing.T) { source := getOrCreateSource("KOD", "Kodex") skill := models.Skill{ Name: "Schwimmen", - GameSystem: "midgard", + GameSystemId: 1, Beschreibung: "Schwimmen im Wasser", Initialwert: 12, BasisWert: 0, @@ -58,7 +58,7 @@ func TestImportSkills(t *testing.T) { tmpDir := t.TempDir() skill := models.Skill{ Name: "TestImportSkill", - GameSystem: "midgard", + GameSystemId: 1, Beschreibung: "Klettern an Wänden", Initialwert: 10, BasisWert: 0, @@ -114,7 +114,7 @@ func TestImportSkillsUpdate(t *testing.T) { // Create existing skill skill := models.Skill{ Name: "Reiten", - GameSystem: "midgard", + GameSystemId: 1, Beschreibung: "Alte Beschreibung", Initialwert: 8, SourceID: source.ID, @@ -349,7 +349,7 @@ func TestExportImportSkillDifficulties(t *testing.T) { // Verify the difficulty was recreated var imported models.SkillDifficulty - result := database.DB.Where("name = ? AND game_system = ?", "TestDifficulty", "midgard").First(&imported) + result := database.DB.Where("name = ? AND game_system_id = ?", "TestDifficulty", 1).First(&imported) if result.Error != nil { t.Fatalf("Difficulty not found after import: %v", result.Error) } @@ -364,7 +364,7 @@ func TestExportImportSpells(t *testing.T) { source := getOrCreateSource("TEST_SP", "Test Spell Source") spell := models.Spell{ Name: "TestSpell", - GameSystem: "midgard", + GameSystemId: 1, Beschreibung: "Test description", SourceID: source.ID, PageNumber: 42, @@ -443,10 +443,10 @@ func TestExportImportAll(t *testing.T) { database.DB.Create(&difficulty) skill := models.Skill{ - Name: "AllSkill", - GameSystem: "midgard", - SourceID: source.ID, - Initialwert: 10, + Name: "AllSkill", + GameSystemId: 1, + SourceID: source.ID, + Initialwert: 10, } if err := skill.Create(); err != nil { t.Fatalf("failed to create skill: %v", err) @@ -562,7 +562,7 @@ func TestExportImportWeaponSkills(t *testing.T) { weaponSkill := models.WeaponSkill{ Skill: models.Skill{ Name: "Langschwert", - GameSystem: "midgard", + GameSystemId: 1, Beschreibung: "Langschwert Waffenfertigkeiten", SourceID: source.ID, PageNumber: 50, @@ -616,7 +616,7 @@ func TestExportImportEquipment(t *testing.T) { source := getOrCreateSource("TEST_EQ", "Test Equipment Source") equipment := models.Equipment{ Name: "Seil", - GameSystem: "midgard", + GameSystemId: 1, Beschreibung: "10m langes Hanfseil", SourceID: source.ID, PageNumber: 75, @@ -663,7 +663,7 @@ func TestExportImportWeapons(t *testing.T) { weapon := models.Weapon{ Equipment: models.Equipment{ Name: "Kurzschwert", - GameSystem: "midgard", + GameSystemId: 1, Beschreibung: "Einhändiges Kurzschwert", SourceID: source.ID, PageNumber: 80, @@ -716,7 +716,7 @@ func TestExportImportContainers(t *testing.T) { container := models.Container{ Equipment: models.Equipment{ Name: "Rucksack", - GameSystem: "midgard", + GameSystemId: 1, Beschreibung: "Großer Lederrucksack", SourceID: source.ID, PageNumber: 85, @@ -767,7 +767,7 @@ func TestExportImportTransportation(t *testing.T) { Container: models.Container{ Equipment: models.Equipment{ Name: "Pferdewagen", - GameSystem: "midgard", + GameSystemId: 1, Beschreibung: "Zweirädriger Wagen", SourceID: source.ID, PageNumber: 90, @@ -817,7 +817,7 @@ func TestExportImportBelieves(t *testing.T) { source := getOrCreateSource("TEST_BL", "Test Believe Source") believe := models.Believe{ Name: "Kirche des Lichts", - GameSystem: "midgard", + GameSystemId: 1, Beschreibung: "Hauptreligion in Valian", SourceID: source.ID, PageNumber: 95, @@ -1257,10 +1257,10 @@ func TestExportImportClassTypicalSkills(t *testing.T) { database.DB.Create(&class) skill := models.Skill{ - Name: "Test-Spurenlesen", - GameSystem: "midgard", - Improvable: true, - InnateSkill: false, + Name: "Test-Spurenlesen", + GameSystemId: 1, + Improvable: true, + InnateSkill: false, } if err := skill.Create(); err != nil { t.Fatalf("failed to create skill: %v", err) diff --git a/backend/gsmaster/gsm_model_test.go b/backend/gsmaster/gsm_model_test.go index 7733ce7..b1c4b7d 100644 --- a/backend/gsmaster/gsm_model_test.go +++ b/backend/gsmaster/gsm_model_test.go @@ -6,10 +6,19 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) +func defaultGameSystem(t *testing.T) *models.GameSystem { + gs := models.GetGameSystem(0, "midgard") + require.NotNil(t, gs) + require.NotZero(t, gs.ID) + return gs +} + func TestSkill_Create(t *testing.T) { database.SetupTestDB() + gs := defaultGameSystem(t) testDefinition := []struct { name string skill *models.Skill @@ -44,7 +53,7 @@ func TestSkill_Create(t *testing.T) { return } assert.NoError(t, err) - assert.Equal(t, "midgard", tt.skill.GameSystem) + assert.Equal(t, gs.ID, tt.skill.GameSystemId) assert.NotZero(t, tt.skill.GameSystemId) assert.NotZero(t, tt.skill.ID) }) @@ -54,6 +63,7 @@ func TestSkill_Create(t *testing.T) { func TestWeaponSkill_Create(t *testing.T) { database.SetupTestDB() + gs := defaultGameSystem(t) testDefinition := []struct { name string weaponSkill *models.WeaponSkill @@ -90,7 +100,7 @@ func TestWeaponSkill_Create(t *testing.T) { return } assert.NoError(t, err) - assert.Equal(t, "midgard", tt.weaponSkill.GameSystem) + assert.Equal(t, gs.ID, tt.weaponSkill.GameSystemId) assert.NotZero(t, tt.weaponSkill.GameSystemId) assert.NotZero(t, tt.weaponSkill.ID) }) @@ -108,6 +118,7 @@ func TestSkill_TableName(t *testing.T) { func TestSkill_First(t *testing.T) { database.SetupTestDB() + gs := defaultGameSystem(t) testDefinition := []struct { name string skill *models.Skill @@ -155,7 +166,7 @@ func TestSkill_First(t *testing.T) { assert.NoError(t, err) assert.Equal(t, tt.skill.Name, s.Name) - assert.Equal(t, "midgard", s.GameSystem) + assert.Equal(t, gs.ID, s.GameSystemId) assert.NotZero(t, s.GameSystemId) }) } @@ -164,6 +175,7 @@ func TestSkill_First(t *testing.T) { func TestSkill_FirstId(t *testing.T) { database.SetupTestDB() + gs := defaultGameSystem(t) testDefinition := []struct { name string skill *models.Skill @@ -212,7 +224,7 @@ func TestSkill_FirstId(t *testing.T) { assert.NoError(t, err) assert.Equal(t, tt.skill.Name, s.Name) - assert.Equal(t, "midgard", s.GameSystem) + assert.Equal(t, gs.ID, s.GameSystemId) assert.NotZero(t, s.GameSystemId) assert.Equal(t, tt.findId, s.ID) }) @@ -232,7 +244,7 @@ func TestSkill_Save(t *testing.T) { skill: &models.Skill{ Name: "Test Skill", Beschreibung: "Original Description", - GameSystem: "midgard", + GameSystemId: 1, }, wantErr: false, }, diff --git a/backend/gsmaster/learning_costs_migration.go b/backend/gsmaster/learning_costs_migration.go index 7f2067d..47ca3cd 100644 --- a/backend/gsmaster/learning_costs_migration.go +++ b/backend/gsmaster/learning_costs_migration.go @@ -74,46 +74,46 @@ func MigrateLearningCostsToDatabase() error { func migrateSources() error { sources := []models.Source{ { - Code: "KOD", - Name: "Kodex", - FullName: "Midgard Regelwerk - Kodex", - Edition: "5. Edition", - Publisher: "Pegasus Spiele", - IsCore: true, - IsActive: true, - GameSystem: "midgard", - Description: "Grundregelwerk für Midgard", + Code: "KOD", + Name: "Kodex", + FullName: "Midgard Regelwerk - Kodex", + Edition: "5. Edition", + Publisher: "Pegasus Spiele", + IsCore: true, + IsActive: true, + GameSystemId: 1, + Description: "Grundregelwerk für Midgard", }, { - Code: "ARK", - Name: "Arkanum", - FullName: "Midgard Arkanum", - Edition: "5. Edition", - Publisher: "Pegasus Spiele", - IsCore: false, - IsActive: true, - GameSystem: "midgard", - Description: "Erweiterungsregelwerk für Zauber und Magie", + Code: "ARK", + Name: "Arkanum", + FullName: "Midgard Arkanum", + Edition: "5. Edition", + Publisher: "Pegasus Spiele", + IsCore: false, + IsActive: true, + GameSystemId: 1, + Description: "Erweiterungsregelwerk für Zauber und Magie", }, { - Code: "MYS", - Name: "Mysterium", - FullName: "Midgard Mysterium", - Edition: "5. Edition", - Publisher: "Pegasus Spiele", - IsCore: false, - IsActive: true, - GameSystem: "midgard", - Description: "Erweiterungsregelwerk für Geheimnisse und Mysterien", + Code: "MYS", + Name: "Mysterium", + FullName: "Midgard Mysterium", + Edition: "5. Edition", + Publisher: "Pegasus Spiele", + IsCore: false, + IsActive: true, + GameSystemId: 1, + Description: "Erweiterungsregelwerk für Geheimnisse und Mysterien", }, { - Code: "UNB", - Name: "Unbekannt", - FullName: "Unbekannte Quelle", - IsCore: false, - IsActive: true, - GameSystem: "midgard", - Description: "Für Inhalte ohne bekannte Quelle", + Code: "UNB", + Name: "Unbekannt", + FullName: "Unbekannte Quelle", + IsCore: false, + IsActive: true, + GameSystemId: 1, + Description: "Für Inhalte ohne bekannte Quelle", }, } diff --git a/backend/gsmaster/lernkosten_maps_test.go b/backend/gsmaster/lernkosten_maps_test.go index b62ac15..5e47e3f 100644 --- a/backend/gsmaster/lernkosten_maps_test.go +++ b/backend/gsmaster/lernkosten_maps_test.go @@ -144,7 +144,7 @@ func TestGetSpellInfo(t *testing.T) { // Create minimal test spell data for our test testSpells := []models.Spell{ { - GameSystem: "midgard", + GameSystemId: 1, Name: "Schlummer", Beschreibung: "Test spell for GetSpellInfo", Quelle: "Test", @@ -152,7 +152,7 @@ func TestGetSpellInfo(t *testing.T) { Category: "Beherrschen", }, { - GameSystem: "midgard", + GameSystemId: 1, Name: "Erkennen von Krankheit", Beschreibung: "Test spell for GetSpellInfo", Quelle: "Test", @@ -160,7 +160,7 @@ func TestGetSpellInfo(t *testing.T) { Category: "Dweomerzauber", }, { - GameSystem: "midgard", + GameSystemId: 1, Name: "Das Loblied", Beschreibung: "Test spell for GetSpellInfo", Quelle: "Test", diff --git a/backend/gsmaster/skill_create_test.go b/backend/gsmaster/skill_create_test.go index 4b5d3a3..7303838 100644 --- a/backend/gsmaster/skill_create_test.go +++ b/backend/gsmaster/skill_create_test.go @@ -19,7 +19,7 @@ func TestCreateSkillWithCategories(t *testing.T) { req := SkillUpdateRequest{ Skill: models.Skill{ Name: "Neue Fertigkeit", - GameSystem: "midgard", + GameSystemId: 1, Beschreibung: "Test Fertigkeit", Initialwert: 5, BasisWert: 0, @@ -94,11 +94,11 @@ func TestCreateSkillWithMultipleCategories(t *testing.T) { // Prepare create request with multiple categories req := SkillUpdateRequest{ Skill: models.Skill{ - Name: "Multi-Kategorie Fertigkeit", - GameSystem: "midgard", - Initialwert: 10, - Improvable: true, - SourceID: source.ID, + Name: "Multi-Kategorie Fertigkeit", + GameSystemId: 1, + Initialwert: 10, + Improvable: true, + SourceID: source.ID, }, CategoryDifficulties: []CategoryDifficultyPair{ { @@ -136,8 +136,8 @@ func TestCreateSkillValidation(t *testing.T) { // Test creating skill without name req := SkillUpdateRequest{ Skill: models.Skill{ - GameSystem: "midgard", - Initialwert: 5, + GameSystemId: 1, + Initialwert: 5, }, CategoryDifficulties: []CategoryDifficultyPair{}, } diff --git a/backend/gsmaster/skill_enhanced_handlers_test.go b/backend/gsmaster/skill_enhanced_handlers_test.go index 1cb0f92..517dfe0 100644 --- a/backend/gsmaster/skill_enhanced_handlers_test.go +++ b/backend/gsmaster/skill_enhanced_handlers_test.go @@ -70,7 +70,7 @@ func TestGetSkillWithCategories(t *testing.T) { skill := models.Skill{ Name: "TestSchwimmen", - GameSystem: "midgard", + GameSystemId: 1, Initialwert: 12, Improvable: true, Bonuseigenschaft: "Gw", @@ -127,7 +127,7 @@ func TestGetSkillWithCategories_MultipleCategories(t *testing.T) { skill := models.Skill{ Name: "TestReiten", - GameSystem: "midgard", + GameSystemId: 1, Initialwert: 5, Improvable: true, Bonuseigenschaft: "Gw", @@ -201,7 +201,7 @@ func TestUpdateSkillWithCategories(t *testing.T) { skill := models.Skill{ Name: "TestKlettern", - GameSystem: "midgard", + GameSystemId: 1, Initialwert: 10, Improvable: true, Bonuseigenschaft: "Gw", @@ -230,7 +230,7 @@ func TestUpdateSkillWithCategories(t *testing.T) { Skill: models.Skill{ ID: skill.ID, Name: "TestKlettern", - GameSystem: "midgard", + GameSystemId: 1, Initialwert: 12, // Changed Improvable: true, Bonuseigenschaft: "St", // Changed @@ -300,7 +300,7 @@ func TestUpdateSkillBooleanFields(t *testing.T) { source := getOrCreateSource("TSTBOOL", "TestBoolean") skill := models.Skill{ Name: "TestBooleanSkill", - GameSystem: "midgard", + GameSystemId: 1, Initialwert: 5, Improvable: true, InnateSkill: false, @@ -326,7 +326,7 @@ func TestUpdateSkillBooleanFields(t *testing.T) { Skill: models.Skill{ ID: skill.ID, Name: "TestBooleanSkill", - GameSystem: "midgard", + GameSystemId: 1, Initialwert: 5, Improvable: false, // Change to false InnateSkill: true, // Change to true diff --git a/backend/importer/importJSON2ImportStruct_test.go b/backend/importer/importJSON2ImportStruct_test.go index 5ebfa7b..09447b1 100644 --- a/backend/importer/importJSON2ImportStruct_test.go +++ b/backend/importer/importJSON2ImportStruct_test.go @@ -201,6 +201,7 @@ func TestImportVTTStructure(t *testing.T) { func TestImportSkill2GSMaster(t *testing.T) { database.SetupTestDB(true) + gs := defaultGameSystem(t) fileName := fmt.Sprintf("../testdata/%s", "VTT_Import1.json") character, err := readImportChar(fileName) @@ -216,7 +217,7 @@ func TestImportSkill2GSMaster(t *testing.T) { assert.Equal(t, "check", skill.Bonuseigenschaft) assert.Equal(t, "KOD5 99", skill.Quelle) assert.Equal(t, false, skill.Improvable) - assert.Equal(t, "midgard", skill.GameSystem) + assert.Equal(t, gs.ID, skill.GameSystemId) //} skill2 := models.Skill{} erro = skill2.First("Hören") @@ -235,7 +236,7 @@ func TestImportSkill2GSMaster(t *testing.T) { assert.Equal(t, skill2.Bonuseigenschaft, skill3.Bonuseigenschaft) assert.Equal(t, skill2.Quelle, skill3.Quelle) assert.Equal(t, skill2.Improvable, skill3.Improvable) - assert.Equal(t, skill2.GameSystem, skill3.GameSystem) + assert.Equal(t, skill2.GameSystemId, skill3.GameSystemId) err = CheckFertigkeiten2GSMaster(character.Fertigkeiten) assert.NoError(t, err, "Expected no error when checkimg Skills against gsmaster") @@ -243,6 +244,7 @@ func TestImportSkill2GSMaster(t *testing.T) { func TestImportWeaponSkill2GSMaster(t *testing.T) { database.SetupTestDB() + gs := defaultGameSystem(t) defer database.ResetTestDB() // Clear weapon skills to test actual import, not pre-existing data database.DB.Exec("DELETE FROM gsm_weaponskills") @@ -261,7 +263,7 @@ func TestImportWeaponSkill2GSMaster(t *testing.T) { assert.Equal(t, "check", skill.Bonuseigenschaft) assert.Equal(t, "KOD5 144", skill.Quelle) assert.Equal(t, true, skill.Improvable) - assert.Equal(t, "midgard", skill.GameSystem) + assert.Equal(t, gs.ID, skill.GameSystemId) //} skill2 := models.WeaponSkill{} erro = skill2.First("Armbrüste") @@ -280,7 +282,7 @@ func TestImportWeaponSkill2GSMaster(t *testing.T) { assert.Equal(t, skill2.Bonuseigenschaft, skill3.Bonuseigenschaft) assert.Equal(t, skill2.Quelle, skill3.Quelle) assert.Equal(t, skill2.Improvable, skill3.Improvable) - assert.Equal(t, skill2.GameSystem, skill3.GameSystem) + assert.Equal(t, skill2.GameSystemId, skill3.GameSystemId) err = CheckWaffenFertigkeiten2GSMaster(character.Waffenfertigkeiten) assert.NoError(t, err, "Expected no error when checkimg WeaponSkills against gsmaster") @@ -288,6 +290,7 @@ func TestImportWeaponSkill2GSMaster(t *testing.T) { func TestImportSpell2GSMaster(t *testing.T) { database.SetupTestDB() + gs := defaultGameSystem(t) fileName := fmt.Sprintf("../testdata/%s", "VTT_Import1.json") character, err := readImportChar(fileName) assert.NoError(t, err, "Expected no error when Unmarshal filecontent") @@ -296,7 +299,7 @@ func TestImportSpell2GSMaster(t *testing.T) { assert.NoError(t, erro, "Expected no error when Unmarshal filecontent") assert.GreaterOrEqual(t, int(skill.ID), 1) - assert.Equal(t, "midgard", skill.GameSystem) + assert.Equal(t, gs.ID, skill.GameSystemId) assert.Equal(t, "Angst", skill.Name) assert.Equal(t, "", skill.Beschreibung) assert.Equal(t, "ARK", skill.Quelle) @@ -316,7 +319,7 @@ func TestImportSpell2GSMaster(t *testing.T) { assert.Equal(t, "Angst", skill3.Name) assert.Equal(t, skill2.ID, skill3.ID) - assert.Equal(t, skill2.GameSystem, skill3.GameSystem) + assert.Equal(t, skill2.GameSystemId, skill3.GameSystemId) assert.Equal(t, skill2.Name, skill3.Name) assert.Equal(t, skill2.Beschreibung, skill3.Beschreibung) assert.Equal(t, skill2.Quelle, skill3.Quelle) @@ -331,6 +334,7 @@ func TestImportSpell2GSMaster(t *testing.T) { func TestImportWeapon2GSMaster(t *testing.T) { database.SetupTestDB() + gs := defaultGameSystem(t) defer database.ResetTestDB() // Clear weapons to test actual import, not pre-existing data database.DB.Exec("DELETE FROM gsm_weapons") @@ -343,7 +347,7 @@ func TestImportWeapon2GSMaster(t *testing.T) { assert.NoError(t, erro, "Expected no error when Unmarshal filecontent") assert.GreaterOrEqual(t, int(skill.ID), 1) - assert.Equal(t, "midgard", skill.GameSystem) + assert.Equal(t, gs.ID, skill.GameSystemId) assert.Equal(t, "Armbrust:schwer", skill.Name) assert.Equal(t, "", skill.Beschreibung) assert.Equal(t, "", skill.Quelle) @@ -363,7 +367,7 @@ func TestImportWeapon2GSMaster(t *testing.T) { assert.Equal(t, "Armbrust:schwer", skill3.Name) assert.Equal(t, skill2.ID, skill3.ID) - assert.Equal(t, skill2.GameSystem, skill3.GameSystem) + assert.Equal(t, skill2.GameSystemId, skill3.GameSystemId) assert.Equal(t, skill2.Name, skill3.Name) assert.Equal(t, skill2.Beschreibung, skill3.Beschreibung) assert.Equal(t, skill2.Quelle, skill3.Quelle) @@ -378,6 +382,7 @@ func TestImportWeapon2GSMaster(t *testing.T) { func TestImportContainer2GSMaster(t *testing.T) { database.SetupTestDB() + gs := defaultGameSystem(t) fileName := fmt.Sprintf("../testdata/%s", "VTT_Import1.json") character, err := readImportChar(fileName) assert.NoError(t, err, "Expected no error when Unmarshal filecontent") @@ -386,7 +391,7 @@ func TestImportContainer2GSMaster(t *testing.T) { assert.NoError(t, erro, "Expected no error when Unmarshal filecontent") assert.GreaterOrEqual(t, int(container.ID), 1) - assert.Equal(t, "midgard", container.GameSystem) + assert.Equal(t, gs.ID, container.GameSystemId) assert.Equal(t, "Lederrucksack", container.Name) assert.Equal(t, "für 25 kg", container.Beschreibung) assert.Equal(t, "", container.Quelle) @@ -406,7 +411,7 @@ func TestImportContainer2GSMaster(t *testing.T) { assert.Equal(t, "Lederrucksack", container3.Name) assert.Equal(t, container2.ID, container3.ID) - assert.Equal(t, container2.GameSystem, container3.GameSystem) + assert.Equal(t, container2.GameSystemId, container3.GameSystemId) assert.Equal(t, container2.Name, container3.Name) assert.Equal(t, container2.Beschreibung, container3.Beschreibung) assert.Equal(t, container2.Quelle, container3.Quelle) @@ -421,6 +426,7 @@ func TestImportContainer2GSMaster(t *testing.T) { func TestImportTransportation2GSMaster(t *testing.T) { database.SetupTestDB() + gs := defaultGameSystem(t) fileName := fmt.Sprintf("../testdata/%s", "VTT_Import1.json") character, err := readImportChar(fileName) assert.NoError(t, err, "Expected no error when Unmarshal filecontent") @@ -429,7 +435,7 @@ func TestImportTransportation2GSMaster(t *testing.T) { assert.NoError(t, erro, "Expected no error when Unmarshal filecontent") assert.GreaterOrEqual(t, int(skill.ID), 1) - assert.Equal(t, "midgard", skill.GameSystem) + assert.Equal(t, gs.ID, skill.GameSystemId) assert.Equal(t, "Karren", skill.Name) assert.Equal(t, "für 250 kg", skill.Beschreibung) assert.Equal(t, "", skill.Quelle) @@ -449,7 +455,7 @@ func TestImportTransportation2GSMaster(t *testing.T) { assert.Equal(t, "Karren", skill3.Name) assert.Equal(t, skill2.ID, skill3.ID) - assert.Equal(t, skill2.GameSystem, skill3.GameSystem) + assert.Equal(t, skill2.GameSystemId, skill3.GameSystemId) assert.Equal(t, skill2.Name, skill3.Name) assert.Equal(t, skill2.Beschreibung, skill3.Beschreibung) assert.Equal(t, skill2.Quelle, skill3.Quelle) @@ -464,6 +470,7 @@ func TestImportTransportation2GSMaster(t *testing.T) { func TestImportEquipment2GSMaster(t *testing.T) { database.SetupTestDB() + gs := defaultGameSystem(t) fileName := fmt.Sprintf("../testdata/%s", "VTT_Import1.json") character, err := readImportChar(fileName) assert.NoError(t, err, "Expected no error when Unmarshal filecontent") @@ -472,7 +479,7 @@ func TestImportEquipment2GSMaster(t *testing.T) { assert.NoError(t, erro, "Expected no error when Unmarshal filecontent") assert.GreaterOrEqual(t, int(skill.ID), 1) - assert.Equal(t, "midgard", skill.GameSystem) + assert.Equal(t, gs.ID, skill.GameSystemId) assert.Equal(t, "Lederrüstung", skill.Name) assert.Equal(t, "", skill.Beschreibung) assert.Equal(t, "", skill.Quelle) @@ -490,7 +497,7 @@ func TestImportEquipment2GSMaster(t *testing.T) { assert.Equal(t, "Lederrüstung", skill3.Name) assert.Equal(t, skill2.ID, skill3.ID) - assert.Equal(t, skill2.GameSystem, skill3.GameSystem) + assert.Equal(t, skill2.GameSystemId, skill3.GameSystemId) assert.Equal(t, skill2.Name, skill3.Name) assert.Equal(t, skill2.Beschreibung, skill3.Beschreibung) assert.Equal(t, skill2.Quelle, skill3.Quelle) @@ -502,6 +509,7 @@ func TestImportEquipment2GSMaster(t *testing.T) { } func TestImportBelieve2GSMaster(t *testing.T) { database.SetupTestDB() + gs := defaultGameSystem(t) fileName := fmt.Sprintf("../testdata/%s", "VTT_Import1.json") character, err := readImportChar(fileName) assert.NoError(t, err, "Expected no error when Unmarshal filecontent") @@ -510,7 +518,7 @@ func TestImportBelieve2GSMaster(t *testing.T) { assert.NoError(t, erro, "Expected no error when Unmarshal filecontent") assert.GreaterOrEqual(t, int(skill.ID), 1) - assert.Equal(t, "midgard", skill.GameSystem) + assert.Equal(t, gs.ID, skill.GameSystemId) assert.Equal(t, "Torkin", skill.Name) assert.Equal(t, "", skill.Beschreibung) assert.Equal(t, "", skill.Quelle) @@ -526,7 +534,7 @@ func TestImportBelieve2GSMaster(t *testing.T) { assert.Equal(t, "Torkin", skill3.Name) assert.Equal(t, skill2.ID, skill3.ID) - assert.Equal(t, skill2.GameSystem, skill3.GameSystem) + assert.Equal(t, skill2.GameSystemId, skill3.GameSystemId) assert.Equal(t, skill2.Name, skill3.Name) assert.Equal(t, skill2.Beschreibung, skill3.Beschreibung) assert.Equal(t, skill2.Quelle, skill3.Quelle) diff --git a/backend/importer/importer_test.go b/backend/importer/importer_test.go index adef72c..55cbe9a 100644 --- a/backend/importer/importer_test.go +++ b/backend/importer/importer_test.go @@ -14,8 +14,16 @@ import ( "github.com/gin-gonic/gin" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) +func defaultGameSystem(t *testing.T) *models.GameSystem { + gs := models.GetGameSystem(0, "midgard") + require.NotNil(t, gs) + require.NotZero(t, gs.ID) + return gs +} + func NoT_estImportCsv2Spell(t *testing.T) { // Clear source cache to ensure clean test state ClearSourceCache() @@ -102,7 +110,7 @@ func NoT_estImportCsv2Spell(t *testing.T) { t.Run("Test update existing spell", func(t *testing.T) { // Create a test spell first testSpell := models.Spell{ - GameSystem: "midgard", + GameSystemId: 1, Name: "Test Zauber", Beschreibung: "Original description", Stufe: 1, @@ -135,6 +143,7 @@ Test Zauber,Updated description,2` }) t.Run("Test source lookup function", func(t *testing.T) { + gs := defaultGameSystem(t) // Clear cache to ensure fresh lookups ClearSourceCache() @@ -154,7 +163,7 @@ Test Zauber,Updated description,2` assert.NoError(t, err, "Should find newly created source") assert.Equal(t, "NEWCODE", newSource.Code, "Source code should match") assert.Equal(t, "NEWCODE", newSource.Name, "Source name should default to code") - assert.Equal(t, "midgard", newSource.GameSystem, "Game system should be midgard") + assert.Equal(t, gs.ID, newSource.GameSystemId, "Game system ID should match default") assert.True(t, newSource.IsActive, "New source should be active") // Test that the second lookup uses cache (should return same ID) diff --git a/backend/maintenance/skill_migration_test.go b/backend/maintenance/skill_migration_test.go index 0d67de9..64a9501 100644 --- a/backend/maintenance/skill_migration_test.go +++ b/backend/maintenance/skill_migration_test.go @@ -49,7 +49,7 @@ func TestMigrateSkillCategoriesToRelations(t *testing.T) { Name: "TestMigSkill_Schwimmen", Category: "Körper", Difficulty: "leicht", - GameSystem: "midgard", + GameSystemId: 1, Initialwert: 12, Improvable: true, Bonuseigenschaft: "Gw", @@ -59,7 +59,7 @@ func TestMigrateSkillCategoriesToRelations(t *testing.T) { Name: "TestMigSkill_Klettern", Category: "Körper", Difficulty: "normal", - GameSystem: "midgard", + GameSystemId: 1, Initialwert: 10, Improvable: true, Bonuseigenschaft: "Gw", @@ -69,7 +69,7 @@ func TestMigrateSkillCategoriesToRelations(t *testing.T) { Name: "TestMigSkill_LesenSchreiben", Category: "Wissen", Difficulty: "schwer", - GameSystem: "midgard", + GameSystemId: 1, Initialwert: 0, Improvable: true, Bonuseigenschaft: "In", @@ -190,7 +190,7 @@ func TestMigrateSkillCategoryDifficulty_NoCategory(t *testing.T) { Name: "TestMigSkill_NoCategory", Category: "", // Empty category Difficulty: "", // Empty difficulty - GameSystem: "midgard", + GameSystemId: 1, Initialwert: 10, SourceID: source.ID, } diff --git a/backend/models/database_test.go b/backend/models/database_test.go index 85ab956..f1828c9 100644 --- a/backend/models/database_test.go +++ b/backend/models/database_test.go @@ -369,12 +369,12 @@ func TestMigrationWorkflow_StructureIntegrity(t *testing.T) { // Test gsmaster category with a skill testSkill := &Skill{ - GameSystem: "midgard", - Name: "Test Skill", - Category: "Test Category", - Difficulty: "normal", - Initialwert: 5, - Improvable: true, + GameSystemId: 1, + Name: "Test Skill", + Category: "Test Category", + Difficulty: "normal", + Initialwert: 5, + Improvable: true, } err = database.DB.Create(testSkill).Error assert.NoError(t, err, "Should be able to create a skill") diff --git a/backend/models/model_char_skills_test.go b/backend/models/model_char_skills_test.go index 0b6563e..9345696 100644 --- a/backend/models/model_char_skills_test.go +++ b/backend/models/model_char_skills_test.go @@ -18,7 +18,7 @@ func setupTestDB(t *testing.T) { func createTestSkill(name string) *Skill { return &Skill{ - GameSystem: "midgard", + GameSystemId: 1, Name: name, Beschreibung: "Test skill description", Category: "Körper", @@ -342,7 +342,7 @@ func TestSkillStructures_WithDatabase(t *testing.T) { weaponSkillData := WeaponSkill{ Skill: Skill{ - GameSystem: "midgard", + GameSystemId: 1, Name: "Bögen", Beschreibung: "Bow skills", Category: "Fernkampf", diff --git a/backend/models/model_gsmaster_basiswert_test.go b/backend/models/model_gsmaster_basiswert_test.go index b968ce1..3e153d1 100644 --- a/backend/models/model_gsmaster_basiswert_test.go +++ b/backend/models/model_gsmaster_basiswert_test.go @@ -7,9 +7,9 @@ import ( func TestSkillBasisWert(t *testing.T) { // Test that BasisWert defaults to 0 in master skill data skill := Skill{ - Name: "TestSkill", - GameSystem: "midgard", - Initialwert: 5, + Name: "TestSkill", + GameSystemId: 1, + Initialwert: 5, } // BasisWert should default to 0 @@ -21,10 +21,10 @@ func TestSkillBasisWert(t *testing.T) { func TestSkillBasisWertSet(t *testing.T) { // Test that BasisWert can be set in master skill data skill := Skill{ - Name: "TestSkill", - GameSystem: "midgard", - Initialwert: 5, - BasisWert: 3, + Name: "TestSkill", + GameSystemId: 1, + Initialwert: 5, + BasisWert: 3, } if skill.BasisWert != 3 { @@ -36,10 +36,10 @@ func TestWeaponSkillBasisWert(t *testing.T) { // Test that BasisWert works for WeaponSkill (inherited from Skill) weaponSkill := WeaponSkill{ Skill: Skill{ - Name: "TestWeaponSkill", - GameSystem: "midgard", - Initialwert: 5, - BasisWert: 2, + Name: "TestWeaponSkill", + GameSystemId: 1, + Initialwert: 5, + BasisWert: 2, }, } diff --git a/backend/models/model_gsmaster_test.go b/backend/models/model_gsmaster_test.go index d8945b2..fdc34c6 100644 --- a/backend/models/model_gsmaster_test.go +++ b/backend/models/model_gsmaster_test.go @@ -18,7 +18,7 @@ func setupGSMasterTestDB(t *testing.T) { func createTestGSMSkill(name string) *Skill { return &Skill{ - GameSystem: "midgard", + GameSystemId: 1, Name: name, Beschreibung: "Test skill description", Category: "Körper", @@ -33,7 +33,7 @@ func createTestGSMSkill(name string) *Skill { func createTestWeaponSkill(name string) *WeaponSkill { return &WeaponSkill{ Skill: Skill{ - GameSystem: "midgard", + GameSystemId: 1, Name: name, Beschreibung: "Test weapon skill description", Category: "Kampf", @@ -48,7 +48,7 @@ func createTestWeaponSkill(name string) *WeaponSkill { func createTestSpell(name string) *Spell { return &Spell{ - GameSystem: "midgard", + GameSystemId: 1, Name: name, Beschreibung: "Test spell description", Bonus: 0, @@ -68,7 +68,7 @@ func createTestSpell(name string) *Spell { func createTestEquipment(name string) *Equipment { return &Equipment{ - GameSystem: "midgard", + GameSystemId: 1, Name: name, Beschreibung: "Test equipment description", Gewicht: 1.5, @@ -80,7 +80,7 @@ func createTestEquipment(name string) *Equipment { func createTestWeapon(name string) *Weapon { return &Weapon{ Equipment: Equipment{ - GameSystem: "midgard", + GameSystemId: 1, Name: name, Beschreibung: "Test weapon description", Gewicht: 2.0, @@ -95,7 +95,7 @@ func createTestWeapon(name string) *Weapon { func createTestContainer(name string) *Container { return &Container{ Equipment: Equipment{ - GameSystem: "midgard", + GameSystemId: 1, Name: name, Beschreibung: "Test container description", Gewicht: 0.5, @@ -109,7 +109,7 @@ func createTestContainer(name string) *Container { func createTestBelieve(name string) *Believe { return &Believe{ - GameSystem: "midgard", + GameSystemId: 1, Name: name, Beschreibung: "Test believe description", SourceID: 1, // Use active source KOD @@ -169,7 +169,7 @@ func TestSkill_Create(t *testing.T) { assert.NoError(t, err) assert.NotZero(t, skill.ID) - assert.Equal(t, "midgard", skill.GameSystem) + assert.Equal(t, uint(1), skill.GameSystemId) } func TestSkill_First_Success(t *testing.T) { @@ -186,7 +186,7 @@ func TestSkill_First_Success(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "TestFirstSkill", foundSkill.Name) - assert.Equal(t, "midgard", foundSkill.GameSystem) + assert.Equal(t, uint(1), foundSkill.GameSystemId) } func TestSkill_First_NotFound(t *testing.T) { @@ -374,7 +374,7 @@ func TestWeaponSkill_Create(t *testing.T) { assert.NoError(t, err) assert.NotZero(t, weaponSkill.ID) - assert.Equal(t, "midgard", weaponSkill.GameSystem) + assert.Equal(t, uint(1), weaponSkill.GameSystemId) } func TestWeaponSkill_First_Success(t *testing.T) { @@ -391,7 +391,7 @@ func TestWeaponSkill_First_Success(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "TestFirstWeaponSkill", foundWeaponSkill.Name) - assert.Equal(t, "midgard", foundWeaponSkill.GameSystem) + assert.Equal(t, uint(1), foundWeaponSkill.GameSystemId) } func TestWeaponSkill_First_NotFound(t *testing.T) { @@ -459,7 +459,7 @@ func TestSpell_Create(t *testing.T) { assert.NoError(t, err) assert.NotZero(t, spell.ID) - assert.Equal(t, "midgard", spell.GameSystem) + assert.Equal(t, uint(1), spell.GameSystemId) } func TestSpell_First_Success(t *testing.T) { @@ -476,7 +476,7 @@ func TestSpell_First_Success(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "TestFirstSpell", foundSpell.Name) - assert.Equal(t, "midgard", foundSpell.GameSystem) + assert.Equal(t, uint(1), foundSpell.GameSystemId) } func TestSpell_First_NotFound(t *testing.T) { @@ -616,7 +616,7 @@ func TestEquipment_Create(t *testing.T) { assert.NoError(t, err) assert.NotZero(t, equipment.ID) - assert.Equal(t, "midgard", equipment.GameSystem) + assert.Equal(t, uint(1), equipment.GameSystemId) } func TestEquipment_First_Success(t *testing.T) { @@ -633,7 +633,7 @@ func TestEquipment_First_Success(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "TestFirstEquipment", foundEquipment.Name) - assert.Equal(t, "midgard", foundEquipment.GameSystem) + assert.Equal(t, uint(1), foundEquipment.GameSystemId) } func TestEquipment_First_NotFound(t *testing.T) { @@ -695,8 +695,8 @@ func TestEquipment_Create_SetsDefaultGameSystem(t *testing.T) { err := equipment.Create() require.NoError(t, err) - assert.Equal(t, "midgard", equipment.GameSystem) - assert.NotZero(t, equipment.GameSystemId) + assert.Equal(t, uint(1), equipment.GameSystemId) + assert.NotEmpty(t, equipment.GameSystem) } func TestEquipment_First_UsesGameSystemId(t *testing.T) { @@ -745,7 +745,7 @@ func TestWeapon_Create(t *testing.T) { assert.NoError(t, err) assert.NotZero(t, weapon.ID) - assert.Equal(t, "midgard", weapon.GameSystem) + assert.Equal(t, uint(1), weapon.GameSystemId) } func TestWeapon_Create_SetsDefaultGameSystem(t *testing.T) { @@ -765,8 +765,8 @@ func TestWeapon_Create_SetsDefaultGameSystem(t *testing.T) { err := weapon.Create() require.NoError(t, err) - assert.Equal(t, "midgard", weapon.GameSystem) - assert.NotZero(t, weapon.GameSystemId) + assert.Equal(t, uint(1), weapon.GameSystemId) + assert.NotEmpty(t, weapon.GameSystem) } func TestWeapon_First_Success(t *testing.T) { @@ -783,7 +783,7 @@ func TestWeapon_First_Success(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "TestFirstWeapon", foundWeapon.Name) - assert.Equal(t, "midgard", foundWeapon.GameSystem) + assert.Equal(t, uint(1), foundWeapon.GameSystemId) } func TestWeapon_First_NotFound(t *testing.T) { @@ -838,7 +838,7 @@ func TestWeapon_RangedWeaponRanges(t *testing.T) { // Create a ranged weapon with ranges weapon := &Weapon{ Equipment: Equipment{ - GameSystem: "midgard", + GameSystemId: 1, Name: "TestBogen", Beschreibung: "Test ranged weapon", Gewicht: 1.5, @@ -920,7 +920,7 @@ func TestContainer_Create(t *testing.T) { assert.NoError(t, err) assert.NotZero(t, container.ID) - assert.Equal(t, "midgard", container.GameSystem) + assert.Equal(t, uint(1), container.GameSystemId) } func TestContainer_First_Success(t *testing.T) { @@ -937,7 +937,7 @@ func TestContainer_First_Success(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "TestFirstContainer", foundContainer.Name) - assert.Equal(t, "midgard", foundContainer.GameSystem) + assert.Equal(t, uint(1), foundContainer.GameSystemId) } func TestContainer_First_NotFound(t *testing.T) { @@ -1003,8 +1003,8 @@ func TestContainer_Create_SetsDefaultGameSystem(t *testing.T) { err := container.Create() require.NoError(t, err) - assert.Equal(t, "midgard", container.GameSystem) - assert.NotZero(t, container.GameSystemId) + assert.Equal(t, uint(1), container.GameSystemId) + assert.NotEmpty(t, container.GameSystem) } // ============================================================================= @@ -1024,7 +1024,7 @@ func TestTransportation_Create(t *testing.T) { transportation := &Transportation{ Container: Container{ Equipment: Equipment{ - GameSystem: "midgard", + GameSystemId: 1, Name: "TestCreateTransportation", Beschreibung: "Test transportation description", Gewicht: 100.0, @@ -1039,7 +1039,7 @@ func TestTransportation_Create(t *testing.T) { assert.NoError(t, err) assert.NotZero(t, transportation.ID) - assert.Equal(t, "midgard", transportation.GameSystem) + assert.Equal(t, uint(1), transportation.GameSystemId) } func TestTransportation_First_Success(t *testing.T) { @@ -1049,7 +1049,7 @@ func TestTransportation_First_Success(t *testing.T) { testTransportation := &Transportation{ Container: Container{ Equipment: Equipment{ - GameSystem: "midgard", + GameSystemId: 1, Name: "TestFirstTransportation", Beschreibung: "Test transportation description", Gewicht: 100.0, @@ -1069,7 +1069,7 @@ func TestTransportation_First_Success(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "TestFirstTransportation", foundTransportation.Name) - assert.Equal(t, "midgard", foundTransportation.GameSystem) + assert.Equal(t, uint(1), foundTransportation.GameSystemId) } func TestTransportation_FirstId_Success(t *testing.T) { @@ -1079,7 +1079,7 @@ func TestTransportation_FirstId_Success(t *testing.T) { testTransportation := &Transportation{ Container: Container{ Equipment: Equipment{ - GameSystem: "midgard", + GameSystemId: 1, Name: "TestFirstIdTransportation", Beschreibung: "Test transportation description", Gewicht: 100.0, @@ -1108,7 +1108,7 @@ func TestTransportation_Save(t *testing.T) { transportation := &Transportation{ Container: Container{ Equipment: Equipment{ - GameSystem: "midgard", + GameSystemId: 1, Name: "TestSaveTransportation", Beschreibung: "Test transportation description", Gewicht: 100.0, @@ -1154,8 +1154,8 @@ func TestTransportation_Create_SetsDefaultGameSystem(t *testing.T) { err := transportation.Create() require.NoError(t, err) - assert.Equal(t, "midgard", transportation.GameSystem) - assert.NotZero(t, transportation.GameSystemId) + assert.Equal(t, uint(1), transportation.GameSystemId) + assert.NotEmpty(t, transportation.GameSystem) } // ============================================================================= @@ -1177,7 +1177,7 @@ func TestBelieve_Create(t *testing.T) { assert.NoError(t, err) assert.NotZero(t, believe.ID) - assert.Equal(t, "midgard", believe.GameSystem) + assert.Equal(t, uint(1), believe.GameSystemId) } func TestBelieve_First_Success(t *testing.T) { @@ -1194,7 +1194,7 @@ func TestBelieve_First_Success(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "TestFirstBelieve", foundBelieve.Name) - assert.Equal(t, "midgard", foundBelieve.GameSystem) + assert.Equal(t, uint(1), foundBelieve.GameSystemId) } func TestBelieve_FirstId_Success(t *testing.T) { @@ -1431,7 +1431,7 @@ func TestFirst_EmptyName_EdgeCases(t *testing.T) { func TestSkill_StructFieldValidation(t *testing.T) { skill := Skill{ ID: 1, - GameSystem: "midgard", + GameSystemId: 1, Name: "TestSkill", Beschreibung: "Test description", Quelle: "Test source", @@ -1446,7 +1446,7 @@ func TestSkill_StructFieldValidation(t *testing.T) { } assert.Equal(t, uint(1), skill.ID) - assert.Equal(t, "midgard", skill.GameSystem) + assert.Equal(t, uint(1), skill.GameSystemId) assert.Equal(t, "TestSkill", skill.Name) assert.Equal(t, "Test description", skill.Beschreibung) assert.Equal(t, "Test source", skill.Quelle) @@ -1464,7 +1464,7 @@ func TestWeaponSkill_StructFieldValidation(t *testing.T) { weaponSkill := WeaponSkill{ Skill: Skill{ ID: 1, - GameSystem: "midgard", + GameSystemId: 1, Name: "TestWeaponSkill", Beschreibung: "Test weapon skill description", Category: "Kampf", @@ -1477,7 +1477,7 @@ func TestWeaponSkill_StructFieldValidation(t *testing.T) { } assert.Equal(t, uint(1), weaponSkill.ID) - assert.Equal(t, "midgard", weaponSkill.GameSystem) + assert.Equal(t, uint(1), weaponSkill.GameSystemId) assert.Equal(t, "TestWeaponSkill", weaponSkill.Name) assert.Equal(t, "Test weapon skill description", weaponSkill.Beschreibung) assert.Equal(t, "Kampf", weaponSkill.Category) @@ -1491,7 +1491,7 @@ func TestWeaponSkill_StructFieldValidation(t *testing.T) { func TestSpell_StructFieldValidation(t *testing.T) { spell := Spell{ ID: 1, - GameSystem: "midgard", + GameSystemId: 1, Name: "TestSpell", Beschreibung: "Test spell description", Quelle: "Test source", @@ -1512,7 +1512,6 @@ func TestSpell_StructFieldValidation(t *testing.T) { } assert.Equal(t, uint(1), spell.ID) - assert.Equal(t, "midgard", spell.GameSystem) assert.Equal(t, "TestSpell", spell.Name) assert.Equal(t, "Test spell description", spell.Beschreibung) assert.Equal(t, "Test source", spell.Quelle) @@ -1530,12 +1529,13 @@ func TestSpell_StructFieldValidation(t *testing.T) { assert.Equal(t, "elementar", spell.Ursprung) assert.Equal(t, "Zerstören", spell.Category) assert.Equal(t, "Spruch", spell.LearningCategory) + assert.Equal(t, uint(1), spell.GameSystemId) } func TestEquipment_StructFieldValidation(t *testing.T) { equipment := Equipment{ ID: 1, - GameSystem: "midgard", + GameSystemId: 1, Name: "TestEquipment", Beschreibung: "Test equipment description", Quelle: "Test source", @@ -1547,7 +1547,6 @@ func TestEquipment_StructFieldValidation(t *testing.T) { } assert.Equal(t, uint(1), equipment.ID) - assert.Equal(t, "midgard", equipment.GameSystem) assert.Equal(t, "TestEquipment", equipment.Name) assert.Equal(t, "Test equipment description", equipment.Beschreibung) assert.Equal(t, "Test source", equipment.Quelle) @@ -1556,13 +1555,14 @@ func TestEquipment_StructFieldValidation(t *testing.T) { assert.Equal(t, 2.5, equipment.Gewicht) assert.Equal(t, 15.0, equipment.Wert) assert.True(t, equipment.PersonalItem) + assert.Equal(t, uint(1), equipment.GameSystemId) } func TestWeapon_StructFieldValidation(t *testing.T) { weapon := Weapon{ Equipment: Equipment{ ID: 1, - GameSystem: "midgard", + GameSystemId: 1, Name: "TestWeapon", Beschreibung: "Test weapon description", Gewicht: 3.0, @@ -1574,7 +1574,6 @@ func TestWeapon_StructFieldValidation(t *testing.T) { } assert.Equal(t, uint(1), weapon.ID) - assert.Equal(t, "midgard", weapon.GameSystem) assert.Equal(t, "TestWeapon", weapon.Name) assert.Equal(t, "Test weapon description", weapon.Beschreibung) assert.Equal(t, 3.0, weapon.Gewicht) @@ -1582,13 +1581,14 @@ func TestWeapon_StructFieldValidation(t *testing.T) { assert.False(t, weapon.PersonalItem) assert.Equal(t, "Einhandschwerter", weapon.SkillRequired) assert.Equal(t, "1W8+3", weapon.Damage) + assert.Equal(t, uint(1), weapon.GameSystemId) } func TestContainer_StructFieldValidation(t *testing.T) { container := Container{ Equipment: Equipment{ ID: 1, - GameSystem: "midgard", + GameSystemId: 1, Name: "TestContainer", Beschreibung: "Test container description", Gewicht: 1.0, @@ -1600,7 +1600,6 @@ func TestContainer_StructFieldValidation(t *testing.T) { } assert.Equal(t, uint(1), container.ID) - assert.Equal(t, "midgard", container.GameSystem) assert.Equal(t, "TestContainer", container.Name) assert.Equal(t, "Test container description", container.Beschreibung) assert.Equal(t, 1.0, container.Gewicht) @@ -1608,6 +1607,7 @@ func TestContainer_StructFieldValidation(t *testing.T) { assert.False(t, container.PersonalItem) assert.Equal(t, 15.0, container.Tragkraft) assert.Equal(t, 30.0, container.Volumen) + assert.Equal(t, uint(1), container.GameSystemId) } func TestTransportation_StructFieldValidation(t *testing.T) { @@ -1615,7 +1615,7 @@ func TestTransportation_StructFieldValidation(t *testing.T) { Container: Container{ Equipment: Equipment{ ID: 1, - GameSystem: "midgard", + GameSystemId: 1, Name: "TestTransportation", Beschreibung: "Test transportation description", Gewicht: 150.0, @@ -1628,7 +1628,6 @@ func TestTransportation_StructFieldValidation(t *testing.T) { } assert.Equal(t, uint(1), transportation.ID) - assert.Equal(t, "midgard", transportation.GameSystem) assert.Equal(t, "TestTransportation", transportation.Name) assert.Equal(t, "Test transportation description", transportation.Beschreibung) assert.Equal(t, 150.0, transportation.Gewicht) @@ -1636,12 +1635,13 @@ func TestTransportation_StructFieldValidation(t *testing.T) { assert.False(t, transportation.PersonalItem) assert.Equal(t, 300.0, transportation.Tragkraft) assert.Equal(t, 600.0, transportation.Volumen) + assert.Equal(t, uint(1), transportation.GameSystemId) } func TestBelieve_StructFieldValidation(t *testing.T) { believe := Believe{ ID: 1, - GameSystem: "midgard", + GameSystemId: 1, Name: "TestBelieve", Beschreibung: "Test believe description", Quelle: "Test source", @@ -1650,12 +1650,12 @@ func TestBelieve_StructFieldValidation(t *testing.T) { } assert.Equal(t, uint(1), believe.ID) - assert.Equal(t, "midgard", believe.GameSystem) assert.Equal(t, "TestBelieve", believe.Name) assert.Equal(t, "Test believe description", believe.Beschreibung) assert.Equal(t, "Test source", believe.Quelle) assert.Equal(t, uint(10), believe.SourceID) assert.Equal(t, 42, believe.PageNumber) + assert.Equal(t, uint(1), believe.GameSystemId) } // ============================================================================= @@ -1800,7 +1800,6 @@ func TestGSMaster_EdgeCases(t *testing.T) { func TestLearnCost_StructFields(t *testing.T) { learnCost := LearnCost{ - GameSystem: "midgard", GameSystemId: 1, Stufe: 3, LE: 10, @@ -1824,8 +1823,8 @@ func TestLearnCost_EnsureGameSystem_DefaultsToMidgard(t *testing.T) { lc := LearnCost{} lc.ensureGameSystem() - assert.Equal(t, "midgard", lc.GameSystem) assert.NotZero(t, lc.GameSystemId) + assert.NotEmpty(t, lc.GameSystem) } func TestLearnCost_EnsureGameSystem_UsesProvidedGameSystem(t *testing.T) { @@ -1847,10 +1846,10 @@ func TestSkill_Create_DefaultImprovable(t *testing.T) { // Test 1: Create skill without setting Improvable or InnateSkill skill1 := Skill{ - Name: "Test Skill Default", - GameSystem: "midgard", - Category: "test", - Initialwert: 5, + Name: "Test Skill Default", + GameSystemId: 1, + Category: "test", + Initialwert: 5, } err := skill1.Create() require.NoError(t, err) @@ -1864,12 +1863,12 @@ func TestSkill_Create_DefaultImprovable(t *testing.T) { // Test 2: Create skill with explicit Improvable=false and InnateSkill=true skill2 := Skill{ - Name: "Test Innate Skill", - GameSystem: "midgard", - Category: "test", - Initialwert: 5, - Improvable: false, - InnateSkill: true, + Name: "Test Innate Skill", + GameSystemId: 1, + Category: "test", + Initialwert: 5, + Improvable: false, + InnateSkill: true, } err = skill2.Create() require.NoError(t, err) @@ -1883,12 +1882,12 @@ func TestSkill_Create_DefaultImprovable(t *testing.T) { // Test 3: Create skill with explicit Improvable=true skill3 := Skill{ - Name: "Test Explicit Improvable", - GameSystem: "midgard", - Category: "test", - Initialwert: 5, - Improvable: true, - InnateSkill: false, + Name: "Test Explicit Improvable", + GameSystemId: 1, + Category: "test", + Initialwert: 5, + Improvable: true, + InnateSkill: false, } err = skill3.Create() require.NoError(t, err) @@ -1908,10 +1907,10 @@ func TestWeaponSkill_Create_DefaultImprovable(t *testing.T) { // Test 1: Create weapon skill without setting Improvable or InnateSkill weaponSkill := WeaponSkill{ Skill: Skill{ - Name: "Test Weapon Skill", - GameSystem: "midgard", - Category: "weapon", - Initialwert: 5, + Name: "Test Weapon Skill", + GameSystemId: 1, + Category: "weapon", + Initialwert: 5, }, } err := weaponSkill.Create() diff --git a/backend/models/model_learning_costs_test.go b/backend/models/model_learning_costs_test.go index 519a1b5..acf4fb6 100644 --- a/backend/models/model_learning_costs_test.go +++ b/backend/models/model_learning_costs_test.go @@ -17,6 +17,13 @@ func setupLearningCostsTestDB(t *testing.T) { require.NoError(t, err, "Failed to migrate database structure") } +func defaultGameSystem(t *testing.T) *GameSystem { + gs := GetGameSystem(0, "midgard") + require.NotNil(t, gs) + require.NotZero(t, gs.ID) + return gs +} + // ============================================================================= // Tests for Source struct and methods // ============================================================================= @@ -67,6 +74,7 @@ func TestSource_FirstByName_NotFound(t *testing.T) { func TestSource_Create_SetsGameSystem(t *testing.T) { setupLearningCostsTestDB(t) + gs := defaultGameSystem(t) source := Source{ Code: "TGS1", @@ -77,8 +85,8 @@ func TestSource_Create_SetsGameSystem(t *testing.T) { require.NoError(t, err) assert.NotZero(t, source.ID) - assert.Equal(t, "midgard", source.GameSystem) - assert.NotZero(t, source.GameSystemId) + assert.Equal(t, gs.Name, source.GameSystem) + assert.Equal(t, gs.ID, source.GameSystemId) } // ============================================================================= @@ -127,6 +135,7 @@ func TestCharacterClass_FirstByName_NotFound(t *testing.T) { func TestCharacterClass_Create_SetsGameSystem(t *testing.T) { setupLearningCostsTestDB(t) + gs := defaultGameSystem(t) var src Source require.NoError(t, src.FirstByCode("KOD")) @@ -141,8 +150,8 @@ func TestCharacterClass_Create_SetsGameSystem(t *testing.T) { require.NoError(t, err) assert.NotZero(t, class.ID) - assert.Equal(t, "midgard", class.GameSystem) - assert.NotZero(t, class.GameSystemId) + assert.Equal(t, gs.Name, class.GameSystem) + assert.Equal(t, gs.ID, class.GameSystemId) } // ============================================================================= @@ -170,6 +179,7 @@ func TestSkillCategory_FirstByName_NotFound(t *testing.T) { func TestSkillCategory_Create_SetsGameSystem(t *testing.T) { setupLearningCostsTestDB(t) + gs := defaultGameSystem(t) var src Source require.NoError(t, src.FirstByCode("KOD")) @@ -183,8 +193,8 @@ func TestSkillCategory_Create_SetsGameSystem(t *testing.T) { require.NoError(t, err) assert.NotZero(t, category.ID) - assert.Equal(t, "midgard", category.GameSystem) - assert.NotZero(t, category.GameSystemId) + assert.Equal(t, gs.Name, category.GameSystem) + assert.Equal(t, gs.ID, category.GameSystemId) } // ============================================================================= @@ -212,6 +222,7 @@ func TestSkillDifficulty_FirstByName_NotFound(t *testing.T) { func TestSkillDifficulty_Create_SetsGameSystem(t *testing.T) { setupLearningCostsTestDB(t) + gs := defaultGameSystem(t) difficulty := SkillDifficulty{ Name: "gs-diff", @@ -221,8 +232,8 @@ func TestSkillDifficulty_Create_SetsGameSystem(t *testing.T) { require.NoError(t, err) assert.NotZero(t, difficulty.ID) - assert.Equal(t, "midgard", difficulty.GameSystem) - assert.NotZero(t, difficulty.GameSystemId) + assert.Equal(t, gs.Name, difficulty.GameSystem) + assert.Equal(t, gs.ID, difficulty.GameSystemId) } // ============================================================================= @@ -272,6 +283,7 @@ func TestSpellSchool_FirstByName_NotFound(t *testing.T) { func TestSpellSchool_Create_SetsGameSystem(t *testing.T) { setupLearningCostsTestDB(t) + gs := defaultGameSystem(t) var src Source require.NoError(t, src.FirstByCode("KOD")) @@ -285,8 +297,8 @@ func TestSpellSchool_Create_SetsGameSystem(t *testing.T) { require.NoError(t, err) assert.NotZero(t, school.ID) - assert.Equal(t, "midgard", school.GameSystem) - assert.NotZero(t, school.GameSystemId) + assert.Equal(t, gs.Name, school.GameSystem) + assert.Equal(t, gs.ID, school.GameSystemId) } // ============================================================================= @@ -527,6 +539,7 @@ func TestGetActiveSourceCodes_Success(t *testing.T) { func TestGetSourcesByGameSystem_Success(t *testing.T) { setupLearningCostsTestDB(t) + gs := defaultGameSystem(t) sources, err := GetSourcesByGameSystem("midgard") assert.NoError(t, err) @@ -534,7 +547,7 @@ func TestGetSourcesByGameSystem_Success(t *testing.T) { // Verify that all returned sources are for the correct game system for _, source := range sources { - assert.Equal(t, "midgard", source.GameSystem) + assert.Equal(t, gs.ID, source.GameSystemId) } } @@ -550,6 +563,7 @@ func TestGetSourcesByGameSystem_InvalidGameSystem(t *testing.T) { func TestGetSkillsByActiveSources_Success(t *testing.T) { setupLearningCostsTestDB(t) + gs := defaultGameSystem(t) // This function may have implementation issues, so we test but accept errors skills, err := GetSkillsByActiveSources("midgard") @@ -557,7 +571,7 @@ func TestGetSkillsByActiveSources_Success(t *testing.T) { if err == nil { // Verify that all returned skills are for the correct game system (if any returned) for _, skill := range skills { - assert.Equal(t, "midgard", skill.GameSystem) + assert.Equal(t, gs.ID, skill.GameSystemId) } } // If there's an error, that's acceptable as the function may have implementation issues @@ -566,6 +580,7 @@ func TestGetSkillsByActiveSources_Success(t *testing.T) { func TestGetSpellsByActiveSources_Success(t *testing.T) { setupLearningCostsTestDB(t) + gs := defaultGameSystem(t) // This function may have implementation issues, so we test but accept errors spells, err := GetSpellsByActiveSources("midgard") @@ -573,7 +588,7 @@ func TestGetSpellsByActiveSources_Success(t *testing.T) { if err == nil { // Verify that all returned spells are for the correct game system (if any returned) for _, spell := range spells { - assert.Equal(t, "midgard", spell.GameSystem) + assert.Equal(t, gs.ID, spell.GameSystemId) } } // If there's an error, that's acceptable as the function may have implementation issues @@ -582,6 +597,7 @@ func TestGetSpellsByActiveSources_Success(t *testing.T) { func TestGetCharacterClassesByActiveSources_Success(t *testing.T) { setupLearningCostsTestDB(t) + gs := defaultGameSystem(t) classes, err := GetCharacterClassesByActiveSources("midgard") assert.NoError(t, err) @@ -589,7 +605,7 @@ func TestGetCharacterClassesByActiveSources_Success(t *testing.T) { // Verify that all returned classes are for the correct game system for _, class := range classes { - assert.Equal(t, "midgard", class.GameSystem) + assert.Equal(t, gs.ID, class.GameSystemId) } } diff --git a/backend/transfer/importer_test.go b/backend/transfer/importer_test.go index 7c1be9e..4f87fe1 100644 --- a/backend/transfer/importer_test.go +++ b/backend/transfer/importer_test.go @@ -102,7 +102,7 @@ func TestImportCharacterUpdatesIncompleteGSMData(t *testing.T) { incompleteSkill := models.Skill{ ID: 1000, Name: "TestSkillIncomplete", - GameSystem: "midgard", + GameSystemId: 1, Beschreibung: "", Category: "", } @@ -122,7 +122,7 @@ func TestImportCharacterUpdatesIncompleteGSMData(t *testing.T) { GSMSkills: []models.Skill{ { Name: "TestSkillIncomplete", - GameSystem: "midgard", + GameSystemId: 1, Beschreibung: "Complete description", Category: "Alltag", Difficulty: "normal",