109 lines
2.7 KiB
Go
109 lines
2.7 KiB
Go
package achievements
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"eq2emu/internal/database"
|
|
)
|
|
|
|
// TestSimpleAchievement tests the basic new Achievement functionality
|
|
func TestSimpleAchievement(t *testing.T) {
|
|
db, err := database.NewSQLite("file::memory:?mode=memory&cache=shared")
|
|
if err != nil {
|
|
t.Fatalf("Failed to create test database: %v", err)
|
|
}
|
|
defer db.Close()
|
|
|
|
// Test creating a new achievement
|
|
achievement := New(db)
|
|
if achievement == nil {
|
|
t.Fatal("New returned nil")
|
|
}
|
|
|
|
if !achievement.IsNew() {
|
|
t.Error("New achievement should be marked as new")
|
|
}
|
|
|
|
// Test setting values
|
|
achievement.AchievementID = 1001
|
|
achievement.Title = "Test Achievement"
|
|
achievement.Category = "Testing"
|
|
|
|
if achievement.GetID() != 1001 {
|
|
t.Errorf("Expected GetID() to return 1001, got %d", achievement.GetID())
|
|
}
|
|
|
|
// Test adding requirements and rewards
|
|
achievement.AddRequirement("kill_monsters", 10)
|
|
achievement.AddReward("experience:1000")
|
|
|
|
if len(achievement.Requirements) != 1 {
|
|
t.Errorf("Expected 1 requirement, got %d", len(achievement.Requirements))
|
|
}
|
|
|
|
if len(achievement.Rewards) != 1 {
|
|
t.Errorf("Expected 1 reward, got %d", len(achievement.Rewards))
|
|
}
|
|
|
|
// Test Clone
|
|
clone := achievement.Clone()
|
|
if clone == nil {
|
|
t.Fatal("Clone returned nil")
|
|
}
|
|
|
|
if clone.AchievementID != achievement.AchievementID {
|
|
t.Errorf("Expected clone ID %d, got %d", achievement.AchievementID, clone.AchievementID)
|
|
}
|
|
|
|
if clone.Title != achievement.Title {
|
|
t.Errorf("Expected clone title %s, got %s", achievement.Title, clone.Title)
|
|
}
|
|
}
|
|
|
|
// TestMasterListWithGeneric tests the master list with generic base
|
|
func TestMasterListWithGeneric(t *testing.T) {
|
|
masterList := NewMasterList()
|
|
|
|
if masterList == nil {
|
|
t.Fatal("NewMasterList returned nil")
|
|
}
|
|
|
|
if masterList.Size() != 0 {
|
|
t.Errorf("Expected size 0, got %d", masterList.Size())
|
|
}
|
|
|
|
// Create an achievement (need database for new pattern)
|
|
db, _ := database.NewSQLite("file::memory:?mode=memory&cache=shared")
|
|
defer db.Close()
|
|
|
|
achievement := New(db)
|
|
achievement.AchievementID = 1001
|
|
achievement.Title = "Test Achievement"
|
|
achievement.Category = "Testing"
|
|
|
|
// Test adding
|
|
if !masterList.AddAchievement(achievement) {
|
|
t.Error("Should successfully add achievement")
|
|
}
|
|
|
|
if masterList.Size() != 1 {
|
|
t.Errorf("Expected size 1, got %d", masterList.Size())
|
|
}
|
|
|
|
// Test retrieving
|
|
retrieved := masterList.GetAchievement(1001)
|
|
if retrieved == nil {
|
|
t.Error("Should retrieve added achievement")
|
|
}
|
|
|
|
if retrieved.Title != "Test Achievement" {
|
|
t.Errorf("Expected title 'Test Achievement', got '%s'", retrieved.Title)
|
|
}
|
|
|
|
// Test filtering
|
|
achievements := masterList.GetAchievementsByCategory("Testing")
|
|
if len(achievements) != 1 {
|
|
t.Errorf("Expected 1 achievement in Testing category, got %d", len(achievements))
|
|
}
|
|
}
|