|
|
|
@@ -24,13 +24,6 @@ func TestImprovedSkillCostAPI(t *testing.T) {
|
|
|
|
|
err := models.MigrateStructure()
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
// Also migrate skills and equipment to avoid preload errors
|
|
|
|
|
/*
|
|
|
|
|
err = skills.MigrateStructure()
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
err = equipment.MigrateStructure()
|
|
|
|
|
assert.NoError(t, err)*/
|
|
|
|
|
|
|
|
|
|
// Create test skill data
|
|
|
|
|
err = createTestSkillData()
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
@@ -350,249 +343,6 @@ func TestGSMasterIntegration(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test the GetSkillAllLevelCosts endpoint (GET /:id/improve/skill)
|
|
|
|
|
/*
|
|
|
|
|
func TestGetSkillAllLevelCostsEndpoint(t *testing.T) {
|
|
|
|
|
// Setup test database
|
|
|
|
|
database.SetupTestDB()
|
|
|
|
|
defer database.ResetTestDB()
|
|
|
|
|
|
|
|
|
|
// Migrate the schema
|
|
|
|
|
err := MigrateStructure()
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
// Also migrate skills and equipment to avoid preload errors
|
|
|
|
|
err = skills.MigrateStructure()
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
err = equipment.MigrateStructure()
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
err = gsmaster.MigrateStructure()
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
// Create test skill data
|
|
|
|
|
err = createTestSkillData()
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
defer cleanupTestSkillData()
|
|
|
|
|
|
|
|
|
|
// Create test character with "Klettern" skill
|
|
|
|
|
testChar := createChar()
|
|
|
|
|
testChar.ID = 20 // Set the ID to match the test requirement
|
|
|
|
|
|
|
|
|
|
// Add Menschenkenntnis skill at level 8 so we can improve to level 10
|
|
|
|
|
skillName := "Menschenkenntnis"
|
|
|
|
|
skill := models.Fertigkeit{
|
|
|
|
|
BamortCharTrait: models.BamortCharTrait{
|
|
|
|
|
BamortBase: models.BamortBase{
|
|
|
|
|
Name: skillName,
|
|
|
|
|
},
|
|
|
|
|
CharacterID: 20,
|
|
|
|
|
},
|
|
|
|
|
Fertigkeitswert: 8,
|
|
|
|
|
}
|
|
|
|
|
testChar.Fertigkeiten = append(testChar.Fertigkeiten, skill)
|
|
|
|
|
|
|
|
|
|
err = testChar.Create()
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
// Setup Gin in test mode
|
|
|
|
|
gin.SetMode(gin.TestMode)
|
|
|
|
|
|
|
|
|
|
t.Run("Get improvement costs for Menschenkenntnis to level 10", func(t *testing.T) {
|
|
|
|
|
// Create request body with skill name
|
|
|
|
|
requestData := LearnRequestStruct{
|
|
|
|
|
Name: "Menschenkenntnis",
|
|
|
|
|
}
|
|
|
|
|
requestBody, _ := json.Marshal(requestData)
|
|
|
|
|
|
|
|
|
|
// Create HTTP request - note this is a GET request but with JSON body (unusual but matches the handler)
|
|
|
|
|
req, _ := http.NewRequest("GET", "/api/characters/20/improve/skill", bytes.NewBuffer(requestBody))
|
|
|
|
|
req.Header.Set("Content-Type", "application/json")
|
|
|
|
|
|
|
|
|
|
// Create response recorder
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
|
|
|
|
|
// Create Gin context
|
|
|
|
|
c, _ := gin.CreateTestContext(w)
|
|
|
|
|
c.Request = req
|
|
|
|
|
c.Params = []gin.Param{{Key: "id", Value: "20"}}
|
|
|
|
|
|
|
|
|
|
fmt.Printf("Test: Get improvement costs for Menschenkenntnis to level 10 for character ID 20\n")
|
|
|
|
|
fmt.Printf("Request: %+v\n", requestData)
|
|
|
|
|
|
|
|
|
|
// Call the actual handler function
|
|
|
|
|
GetSkillAllLevelCosts(c)
|
|
|
|
|
|
|
|
|
|
// Print the actual response to see what we get
|
|
|
|
|
fmt.Printf("Response Status: %d\n", w.Code)
|
|
|
|
|
fmt.Printf("Response Body: %s\n", w.Body.String())
|
|
|
|
|
|
|
|
|
|
// Check if we got an error response first
|
|
|
|
|
if w.Code != http.StatusOK {
|
|
|
|
|
var errorResponse map[string]interface{}
|
|
|
|
|
err := json.Unmarshal(w.Body.Bytes(), &errorResponse)
|
|
|
|
|
if err == nil {
|
|
|
|
|
fmt.Printf("Error Response: %+v\n", errorResponse)
|
|
|
|
|
}
|
|
|
|
|
return // Exit early for error cases
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Parse and validate response for success case
|
|
|
|
|
var response []gsmaster.LearnCost
|
|
|
|
|
err := json.Unmarshal(w.Body.Bytes(), &response)
|
|
|
|
|
assert.NoError(t, err, "Response should be valid JSON")
|
|
|
|
|
|
|
|
|
|
// Should have costs for levels 9, 10 (from current level 8 to level 20)
|
|
|
|
|
assert.Greater(t, len(response), 0, "Should return learning costs")
|
|
|
|
|
|
|
|
|
|
// Find cost for level 10 specifically
|
|
|
|
|
var level10Cost *gsmaster.LearnCost
|
|
|
|
|
for _, cost := range response {
|
|
|
|
|
if cost.Stufe == 10 {
|
|
|
|
|
level10Cost = &cost
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if level10Cost != nil {
|
|
|
|
|
assert.Equal(t, 10, level10Cost.Stufe, "Target level should be 10")
|
|
|
|
|
assert.Greater(t, level10Cost.Ep, 0, "EP cost should be greater than 0")
|
|
|
|
|
|
|
|
|
|
fmt.Printf("Level 10 improvement cost: EP=%d, Money=%d, LE=%d\n",
|
|
|
|
|
level10Cost.Ep, level10Cost.Money, level10Cost.LE)
|
|
|
|
|
} else {
|
|
|
|
|
fmt.Printf("No cost found for level 10. Available levels: ")
|
|
|
|
|
for _, cost := range response {
|
|
|
|
|
fmt.Printf("%d ", cost.Stufe)
|
|
|
|
|
}
|
|
|
|
|
fmt.Println()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
t.Run("Get improvement costs for Klettern to level 10", func(t *testing.T) {
|
|
|
|
|
// Create request body with skill name
|
|
|
|
|
requestData := LearnRequestStruct{
|
|
|
|
|
SkillType: "skill",
|
|
|
|
|
Name: "Klettern",
|
|
|
|
|
Stufe: 13, // Target level
|
|
|
|
|
}
|
|
|
|
|
requestBody, _ := json.Marshal(requestData)
|
|
|
|
|
|
|
|
|
|
// Create HTTP request - note this is a GET request but with JSON body (unusual but matches the handler)
|
|
|
|
|
req, _ := http.NewRequest("GET", "/api/characters/20/improve/skill", bytes.NewBuffer(requestBody))
|
|
|
|
|
req.Header.Set("Content-Type", "application/json")
|
|
|
|
|
|
|
|
|
|
// Create response recorder
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
|
|
|
|
|
// Create Gin context
|
|
|
|
|
c, _ := gin.CreateTestContext(w)
|
|
|
|
|
c.Request = req
|
|
|
|
|
c.Params = []gin.Param{{Key: "id", Value: "20"}}
|
|
|
|
|
|
|
|
|
|
fmt.Printf("Test: Get improvement costs for Klettern to level 13 for character ID 20\n")
|
|
|
|
|
fmt.Printf("Request: %+v\n", requestData)
|
|
|
|
|
|
|
|
|
|
// Call the actual handler function
|
|
|
|
|
GetSkillAllLevelCosts(c)
|
|
|
|
|
|
|
|
|
|
// Print the actual response to see what we get
|
|
|
|
|
fmt.Printf("Response Status: %d\n", w.Code)
|
|
|
|
|
fmt.Printf("Response Body: %s\n", w.Body.String())
|
|
|
|
|
|
|
|
|
|
// Check if we got an error response first
|
|
|
|
|
if w.Code != http.StatusOK {
|
|
|
|
|
var errorResponse map[string]interface{}
|
|
|
|
|
err := json.Unmarshal(w.Body.Bytes(), &errorResponse)
|
|
|
|
|
if err == nil {
|
|
|
|
|
fmt.Printf("Error Response: %+v\n", errorResponse)
|
|
|
|
|
}
|
|
|
|
|
return // Exit early for error cases
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Parse and validate response for success case
|
|
|
|
|
var response []gsmaster.LearnCost
|
|
|
|
|
err := json.Unmarshal(w.Body.Bytes(), &response)
|
|
|
|
|
assert.NoError(t, err, "Response should be valid JSON")
|
|
|
|
|
|
|
|
|
|
// Should have costs for levels 9, 10 (from current level 8 to level 20)
|
|
|
|
|
assert.Greater(t, len(response), 0, "Should return learning costs")
|
|
|
|
|
|
|
|
|
|
// Find cost for level 10 specifically
|
|
|
|
|
var level10Cost *gsmaster.LearnCost
|
|
|
|
|
for _, cost := range response {
|
|
|
|
|
if cost.Stufe == 13 {
|
|
|
|
|
level10Cost = &cost
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if level10Cost != nil {
|
|
|
|
|
assert.Equal(t, 13, level10Cost.Stufe, "Target level should be 13")
|
|
|
|
|
assert.Greater(t, level10Cost.Ep, 0, "EP cost should be greater than 0")
|
|
|
|
|
|
|
|
|
|
fmt.Printf("Level 10 improvement cost: EP=%d, Money=%d, LE=%d\n",
|
|
|
|
|
level10Cost.Ep, level10Cost.Money, level10Cost.LE)
|
|
|
|
|
} else {
|
|
|
|
|
fmt.Printf("No cost found for level 10. Available levels: ")
|
|
|
|
|
for _, cost := range response {
|
|
|
|
|
fmt.Printf("%d ", cost.Stufe)
|
|
|
|
|
}
|
|
|
|
|
fmt.Println()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("Error case - skill not found", func(t *testing.T) {
|
|
|
|
|
// Test with a skill the character doesn't have
|
|
|
|
|
requestData := LearnRequestStruct{
|
|
|
|
|
Name: "NonExistentSkill",
|
|
|
|
|
}
|
|
|
|
|
requestBody, _ := json.Marshal(requestData)
|
|
|
|
|
|
|
|
|
|
req, _ := http.NewRequest("GET", "/api/characters/20/improve/skill", bytes.NewBuffer(requestBody))
|
|
|
|
|
req.Header.Set("Content-Type", "application/json")
|
|
|
|
|
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
c, _ := gin.CreateTestContext(w)
|
|
|
|
|
c.Request = req
|
|
|
|
|
c.Params = []gin.Param{{Key: "id", Value: "20"}}
|
|
|
|
|
|
|
|
|
|
GetSkillAllLevelCosts(c)
|
|
|
|
|
|
|
|
|
|
// Should still return 200 but with empty array (based on the handler logic)
|
|
|
|
|
assert.Equal(t, http.StatusOK, w.Code, "Status code should be 200 OK")
|
|
|
|
|
|
|
|
|
|
var response []gsmaster.LearnCost
|
|
|
|
|
err := json.Unmarshal(w.Body.Bytes(), &response)
|
|
|
|
|
assert.NoError(t, err, "Response should be valid JSON")
|
|
|
|
|
assert.Equal(t, 0, len(response), "Should return empty array for non-existent skill")
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("Error case - missing skill name", func(t *testing.T) {
|
|
|
|
|
// Test with empty skill name
|
|
|
|
|
requestData := LearnRequestStruct{
|
|
|
|
|
Name: "",
|
|
|
|
|
}
|
|
|
|
|
requestBody, _ := json.Marshal(requestData)
|
|
|
|
|
|
|
|
|
|
req, _ := http.NewRequest("GET", "/api/characters/20/improve/skill", bytes.NewBuffer(requestBody))
|
|
|
|
|
req.Header.Set("Content-Type", "application/json")
|
|
|
|
|
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
c, _ := gin.CreateTestContext(w)
|
|
|
|
|
c.Request = req
|
|
|
|
|
c.Params = []gin.Param{{Key: "id", Value: "20"}}
|
|
|
|
|
|
|
|
|
|
GetSkillAllLevelCosts(c)
|
|
|
|
|
|
|
|
|
|
// Should return 400 Bad Request
|
|
|
|
|
assert.Equal(t, http.StatusBadRequest, w.Code, "Status code should be 400 Bad Request")
|
|
|
|
|
|
|
|
|
|
var response map[string]interface{}
|
|
|
|
|
err := json.Unmarshal(w.Body.Bytes(), &response)
|
|
|
|
|
assert.NoError(t, err, "Response should be valid JSON")
|
|
|
|
|
assert.Contains(t, response, "error", "Response should contain error message")
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
// Test GetLernCost endpoint specifically with gsmaster.LernCostRequest structure
|
|
|
|
|
func TestGetLernCostEndpoint(t *testing.T) {
|
|
|
|
|
// Setup test database
|
|
|
|
@@ -603,39 +353,6 @@ func TestGetLernCostEndpoint(t *testing.T) {
|
|
|
|
|
err := models.MigrateStructure()
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
// Also migrate skills and equipment to avoid preload errors
|
|
|
|
|
/*
|
|
|
|
|
err = skills.MigrateStructure()
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
err = equipment.MigrateStructure()
|
|
|
|
|
assert.NoError(t, err)*/
|
|
|
|
|
/*
|
|
|
|
|
// Create test skill data
|
|
|
|
|
err = createTestSkillData()
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
defer cleanupTestSkillData()
|
|
|
|
|
// Create test character with ID 20 and class "Krieger"
|
|
|
|
|
testChar := createChar()
|
|
|
|
|
testChar.ID = 20
|
|
|
|
|
testChar.Typ = "Krieger" // Set character class to "Krieger"
|
|
|
|
|
|
|
|
|
|
// Add Athletik skill at level 9
|
|
|
|
|
skillName := "Athletik"
|
|
|
|
|
skill := models.Fertigkeit{
|
|
|
|
|
BamortCharTrait: models.BamortCharTrait{
|
|
|
|
|
BamortBase: models.BamortBase{
|
|
|
|
|
Name: skillName,
|
|
|
|
|
},
|
|
|
|
|
CharacterID: 20,
|
|
|
|
|
},
|
|
|
|
|
Fertigkeitswert: 9,
|
|
|
|
|
}
|
|
|
|
|
testChar.Fertigkeiten = append(testChar.Fertigkeiten, skill)
|
|
|
|
|
|
|
|
|
|
err = testChar.Create()
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Setup Gin in test mode
|
|
|
|
|
gin.SetMode(gin.TestMode)
|
|
|
|
|
|
|
|
|
|