package fun import ( "testing" "git.nakama.town/fmartingr/butterrobot/internal/model" "git.nakama.town/fmartingr/butterrobot/internal/testutil" ) func TestHLTBPlugin_OnMessage(t *testing.T) { plugin := NewHLTB() tests := []struct { name string messageText string shouldRespond bool }{ { name: "responds to !hltb command", messageText: "!hltb The Witcher 3", shouldRespond: true, }, { name: "ignores non-hltb messages", messageText: "hello world", shouldRespond: false, }, { name: "ignores !hltb without game name", messageText: "!hltb", shouldRespond: false, }, { name: "ignores !hltb with only spaces", messageText: "!hltb ", shouldRespond: false, }, { name: "ignores similar but incorrect commands", messageText: "hltb The Witcher 3", shouldRespond: false, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { msg := &model.Message{ Text: tt.messageText, Chat: "test-chat", Channel: &model.Channel{ID: 1}, Author: "test-user", } mockCache := &testutil.MockCache{} actions := plugin.OnMessage(msg, make(map[string]interface{}), mockCache) if tt.shouldRespond && len(actions) == 0 { t.Errorf("Expected plugin to respond to '%s', but it didn't", tt.messageText) } if !tt.shouldRespond && len(actions) > 0 { t.Errorf("Expected plugin to not respond to '%s', but it did", tt.messageText) } // For messages that should respond, verify the response structure if tt.shouldRespond && len(actions) > 0 { action := actions[0] if action.Type != model.ActionSendMessage { t.Errorf("Expected ActionSendMessage, got %s", action.Type) } if action.Message == nil { t.Error("Expected action to have a message") } if action.Message != nil && action.Message.ReplyTo != msg.ID { t.Error("Expected response to reply to original message") } } }) } } func TestHLTBPlugin_formatTime(t *testing.T) { plugin := NewHLTB() tests := []struct { seconds int expected string }{ {0, "N/A"}, {-1, "N/A"}, {1800, "30 minutes"}, // 30 minutes {3600, "1.0 hour"}, // 1 hour {7200, "2.0 hours"}, // 2 hours {10800, "3.0 hours"}, // 3 hours {36000, "10.0 hours"}, // 10 hours } for _, tt := range tests { t.Run(tt.expected, func(t *testing.T) { result := plugin.formatTime(tt.seconds) if result != tt.expected { t.Errorf("formatTime(%d) = %s, want %s", tt.seconds, result, tt.expected) } }) } } func TestHLTBPlugin_getFullImageURL(t *testing.T) { plugin := NewHLTB() tests := []struct { imagePath string expected string }{ {"", ""}, {"game.jpg", "https://howlongtobeat.com/games/game.jpg"}, {"/game.jpg", "https://howlongtobeat.com/games/game.jpg"}, {"folder/game.png", "https://howlongtobeat.com/games/folder/game.png"}, } for _, tt := range tests { t.Run(tt.imagePath, func(t *testing.T) { result := plugin.getFullImageURL(tt.imagePath) if result != tt.expected { t.Errorf("getFullImageURL(%s) = %s, want %s", tt.imagePath, result, tt.expected) } }) } }