From aef584c9fa2af8448d016eae72648f5b1517d19d Mon Sep 17 00:00:00 2001 From: kolaente Date: Mon, 8 Jun 2026 15:11:07 +0200 Subject: [PATCH] feat(time-tracking): let clients subscribe to timer events --- pkg/websocket/connection.go | 3 +++ pkg/websocket/connection_test.go | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/pkg/websocket/connection.go b/pkg/websocket/connection.go index 0438b6fef..a2fb54d47 100644 --- a/pkg/websocket/connection.go +++ b/pkg/websocket/connection.go @@ -264,6 +264,9 @@ func (c *Connection) WriteLoop(ctx context.Context, cancel context.CancelFunc) { // validEvents is the set of event names clients are allowed to subscribe to. var validEvents = map[string]bool{ "notification.created": true, + "timer.created": true, + "timer.updated": true, + "timer.deleted": true, } func isValidEvent(event string) bool { diff --git a/pkg/websocket/connection_test.go b/pkg/websocket/connection_test.go index f5bccdac2..d05ab5c1e 100644 --- a/pkg/websocket/connection_test.go +++ b/pkg/websocket/connection_test.go @@ -80,6 +80,20 @@ func TestConnectionRejectsInvalidEvent(t *testing.T) { assert.False(t, conn.IsSubscribed("notifications")) } +func TestConnectionAllowsTimerEvents(t *testing.T) { + conn := &Connection{ + userID: 1, + authenticated: true, + subscriptions: make(map[string]bool), + send: make(chan OutgoingMessage, 16), + } + + for _, event := range []string{"timer.created", "timer.updated"} { + conn.handleMessage(context.Background(), IncomingMessage{Action: ActionSubscribe, Event: event}) + assert.True(t, conn.IsSubscribed(event), "client must be able to subscribe to %s", event) + } +} + func TestConnectionRejectsActionsBeforeAuth(t *testing.T) { conn := &Connection{ userID: 0, // not authenticated