package handlers import ( "context" "testing" "time" "git.threesix.ai/jordan/sp4-verify-1770325799/pkg/logging" "git.threesix.ai/jordan/sp4-verify-1770325799/pkg/queue" ) func TestTaskHandlers_ProcessChatMessage(t *testing.T) { logger := logging.New(logging.Config{Level: logging.LevelDebug}) h := NewTaskHandlers(logger) tests := []struct { name string payload map[string]any wantErr bool }{ { name: "valid message", payload: map[string]any{ "message_id": "msg-123", "user_id": "user-456", "content": "Hello world", }, wantErr: false, }, { name: "missing message_id", payload: map[string]any{ "user_id": "user-456", "content": "Hello world", }, wantErr: true, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { now := time.Now() job := &queue.Job{ ID: "job-123", Type: "process_chat_message", Payload: tt.payload, Status: queue.StatusRunning, CreatedAt: now, StartedAt: &now, } err := h.ProcessChatMessage(context.Background(), job) if (err != nil) != tt.wantErr { t.Errorf("ProcessChatMessage() error = %v, wantErr %v", err, tt.wantErr) } }) } } func TestTaskHandlers_SendNotification(t *testing.T) { logger := logging.New(logging.Config{Level: logging.LevelDebug}) h := NewTaskHandlers(logger) tests := []struct { name string payload map[string]any wantErr bool }{ { name: "valid notification", payload: map[string]any{ "user_id": "user-456", "type": "email", "message": "You have a new message", }, wantErr: false, }, { name: "missing user_id", payload: map[string]any{ "type": "email", "message": "You have a new message", }, wantErr: true, }, { name: "missing type", payload: map[string]any{ "user_id": "user-456", "message": "You have a new message", }, wantErr: true, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { now := time.Now() job := &queue.Job{ ID: "job-123", Type: "send_notification", Payload: tt.payload, Status: queue.StatusRunning, CreatedAt: now, StartedAt: &now, } err := h.SendNotification(context.Background(), job) if (err != nil) != tt.wantErr { t.Errorf("SendNotification() error = %v, wantErr %v", err, tt.wantErr) } }) } } func TestTaskHandlers_SyncData(t *testing.T) { logger := logging.New(logging.Config{Level: logging.LevelDebug}) h := NewTaskHandlers(logger) tests := []struct { name string payload map[string]any wantErr bool }{ { name: "valid sync", payload: map[string]any{ "source": "database-a", "destination": "database-b", }, wantErr: false, }, { name: "missing source", payload: map[string]any{ "destination": "database-b", }, wantErr: true, }, { name: "missing destination", payload: map[string]any{ "source": "database-a", }, wantErr: true, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { now := time.Now() job := &queue.Job{ ID: "job-123", Type: "sync_data", Payload: tt.payload, Status: queue.StatusRunning, CreatedAt: now, StartedAt: &now, } err := h.SyncData(context.Background(), job) if (err != nil) != tt.wantErr { t.Errorf("SyncData() error = %v, wantErr %v", err, tt.wantErr) } }) } } func TestTaskHandlers_ProcessWebhook(t *testing.T) { logger := logging.New(logging.Config{Level: logging.LevelDebug}) h := NewTaskHandlers(logger) tests := []struct { name string payload map[string]any wantErr bool }{ { name: "valid webhook", payload: map[string]any{ "webhook_id": "wh-123", "event_type": "user.created", }, wantErr: false, }, { name: "missing webhook_id", payload: map[string]any{ "event_type": "user.created", }, wantErr: true, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { now := time.Now() job := &queue.Job{ ID: "job-123", Type: "process_webhook", Payload: tt.payload, Status: queue.StatusRunning, CreatedAt: now, StartedAt: &now, } err := h.ProcessWebhook(context.Background(), job) if (err != nil) != tt.wantErr { t.Errorf("ProcessWebhook() error = %v, wantErr %v", err, tt.wantErr) } }) } }