veza/veza-backend-api/internal/websocket/chat/presence_service_test.go

35 lines
885 B
Go
Raw Normal View History

package chat
import (
"context"
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"go.uber.org/zap/zaptest"
)
func TestPresenceService_NilRedis_NoErrors(t *testing.T) {
logger := zaptest.NewLogger(t)
svc := NewChatPresenceService(nil, logger)
ctx := context.Background()
userID := uuid.New()
assert.NoError(t, svc.SetOnline(ctx, userID))
assert.NoError(t, svc.SetOffline(ctx, userID))
assert.NoError(t, svc.Heartbeat(ctx, userID))
info, err := svc.GetPresence(ctx, userID)
assert.NoError(t, err)
assert.False(t, info.Online)
assert.Equal(t, userID, info.UserID)
}
func TestPresenceService_PresenceKeyFormat(t *testing.T) {
svc := NewChatPresenceService(nil, nil)
userID := uuid.MustParse("550e8400-e29b-41d4-a716-446655440000")
key := svc.presenceKey(userID)
assert.Equal(t, "chat:presence:550e8400-e29b-41d4-a716-446655440000", key)
}