package reminder import ( "testing" "time" "git.nakama.town/fmartingr/butterrobot/internal/model" ) // MockCreator is a mock implementation of ReminderCreator for testing type MockCreator struct { reminders []*model.Reminder } func (m *MockCreator) CreateReminder(platform, channelID, messageID, replyToID, userID, username, content string, triggerAt time.Time) (*model.Reminder, error) { reminder := &model.Reminder{ ID: int64(len(m.reminders) + 1), Platform: platform, ChannelID: channelID, MessageID: messageID, ReplyToID: replyToID, UserID: userID, Username: username, Content: content, TriggerAt: triggerAt, } m.reminders = append(m.reminders, reminder) return reminder, nil } func TestReminderOnMessage(t *testing.T) { creator := &MockCreator{reminders: make([]*model.Reminder, 0)} plugin := New(creator) tests := []struct { name string message *model.Message expectResponse bool expectReminder bool }{ { name: "Valid reminder command - years", message: &model.Message{ Text: "!remindme 1y", ReplyTo: "original-message-id", Author: "testuser", Channel: &model.Channel{Platform: "test"}, }, expectResponse: true, expectReminder: true, }, { name: "Valid reminder command - months", message: &model.Message{ Text: "!remindme 3mo", ReplyTo: "original-message-id", Author: "testuser", Channel: &model.Channel{Platform: "test"}, }, expectResponse: true, expectReminder: true, }, { name: "Valid reminder command - days", message: &model.Message{ Text: "!remindme 2d", ReplyTo: "original-message-id", Author: "testuser", Channel: &model.Channel{Platform: "test"}, }, expectResponse: true, expectReminder: true, }, { name: "Valid reminder command - hours", message: &model.Message{ Text: "!remindme 5h", ReplyTo: "original-message-id", Author: "testuser", Channel: &model.Channel{Platform: "test"}, }, expectResponse: true, expectReminder: true, }, { name: "Valid reminder command - minutes", message: &model.Message{ Text: "!remindme 30m", ReplyTo: "original-message-id", Author: "testuser", Channel: &model.Channel{Platform: "test"}, }, expectResponse: true, expectReminder: true, }, { name: "Valid reminder command - seconds", message: &model.Message{ Text: "!remindme 60s", ReplyTo: "original-message-id", Author: "testuser", Channel: &model.Channel{Platform: "test"}, }, expectResponse: true, expectReminder: true, }, { name: "Not a reply", message: &model.Message{ Text: "!remindme 2d", ReplyTo: "", Author: "testuser", Channel: &model.Channel{Platform: "test"}, }, expectResponse: false, expectReminder: false, }, { name: "Not a reminder command", message: &model.Message{ Text: "hello world", ReplyTo: "original-message-id", Author: "testuser", Channel: &model.Channel{Platform: "test"}, }, expectResponse: false, expectReminder: false, }, { name: "Invalid duration format", message: &model.Message{ Text: "!remindme abc", ReplyTo: "original-message-id", Author: "testuser", Channel: &model.Channel{Platform: "test"}, }, expectResponse: false, expectReminder: false, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { initialCount := len(creator.reminders) actions := plugin.OnMessage(tt.message, nil) if tt.expectResponse && len(actions) == 0 { t.Errorf("Expected response action, but got none") } if !tt.expectResponse && len(actions) > 0 { t.Errorf("Expected no actions, but got %d", len(actions)) } // Verify action type is correct when actions are returned if len(actions) > 0 { if actions[0].Type != model.ActionSendMessage { t.Errorf("Expected action type to be %s, but got %s", model.ActionSendMessage, actions[0].Type) } if actions[0].Message == nil { t.Errorf("Expected message in action to not be nil") } } if tt.expectReminder && len(creator.reminders) != initialCount+1 { t.Errorf("Expected reminder to be created, but it wasn't") } if !tt.expectReminder && len(creator.reminders) != initialCount { t.Errorf("Expected no reminder to be created, but got %d", len(creator.reminders)-initialCount) } }) } }