feat(time-tracking): let clients subscribe to timer events

This commit is contained in:
kolaente 2026-06-08 15:11:07 +02:00 committed by kolaente
parent cf22f08974
commit aef584c9fa
2 changed files with 17 additions and 0 deletions

View File

@ -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 {

View File

@ -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