feat(time-tracking): let clients subscribe to timer events
This commit is contained in:
parent
cf22f08974
commit
aef584c9fa
|
|
@ -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.
|
// validEvents is the set of event names clients are allowed to subscribe to.
|
||||||
var validEvents = map[string]bool{
|
var validEvents = map[string]bool{
|
||||||
"notification.created": true,
|
"notification.created": true,
|
||||||
|
"timer.created": true,
|
||||||
|
"timer.updated": true,
|
||||||
|
"timer.deleted": true,
|
||||||
}
|
}
|
||||||
|
|
||||||
func isValidEvent(event string) bool {
|
func isValidEvent(event string) bool {
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,20 @@ func TestConnectionRejectsInvalidEvent(t *testing.T) {
|
||||||
assert.False(t, conn.IsSubscribed("notifications"))
|
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) {
|
func TestConnectionRejectsActionsBeforeAuth(t *testing.T) {
|
||||||
conn := &Connection{
|
conn := &Connection{
|
||||||
userID: 0, // not authenticated
|
userID: 0, // not authenticated
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue