Only send events to clients who need it
- User events (star, rating, plays) only sent to same user - Don't send to the client (browser window) that originated the event
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package events
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/navidrome/navidrome/model/request"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("Broker", func() {
|
||||
var b broker
|
||||
|
||||
BeforeEach(func() {
|
||||
b = broker{}
|
||||
})
|
||||
|
||||
Describe("shouldSend", func() {
|
||||
var c client
|
||||
var ctx context.Context
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
c = client{
|
||||
clientUniqueId: "1111",
|
||||
username: "janedoe",
|
||||
}
|
||||
})
|
||||
Context("request has clientUniqueId", func() {
|
||||
It("sends message for same username, different clientUniqueId", func() {
|
||||
ctx = request.WithClientUniqueId(ctx, "2222")
|
||||
ctx = request.WithUsername(ctx, "janedoe")
|
||||
m := message{senderCtx: ctx}
|
||||
Expect(b.shouldSend(m, c)).To(BeTrue())
|
||||
})
|
||||
It("does not send message for same username, same clientUniqueId", func() {
|
||||
ctx = request.WithClientUniqueId(ctx, "1111")
|
||||
ctx = request.WithUsername(ctx, "janedoe")
|
||||
m := message{senderCtx: ctx}
|
||||
Expect(b.shouldSend(m, c)).To(BeFalse())
|
||||
})
|
||||
It("does not send message for different username", func() {
|
||||
ctx = request.WithClientUniqueId(ctx, "3333")
|
||||
ctx = request.WithUsername(ctx, "johndoe")
|
||||
m := message{senderCtx: ctx}
|
||||
Expect(b.shouldSend(m, c)).To(BeFalse())
|
||||
})
|
||||
})
|
||||
Context("request does not have clientUniqueId", func() {
|
||||
It("sends message for same username", func() {
|
||||
ctx = request.WithUsername(ctx, "janedoe")
|
||||
m := message{senderCtx: ctx}
|
||||
Expect(b.shouldSend(m, c)).To(BeTrue())
|
||||
})
|
||||
It("sends message for different username", func() {
|
||||
ctx = request.WithUsername(ctx, "johndoe")
|
||||
m := message{senderCtx: ctx}
|
||||
Expect(b.shouldSend(m, c)).To(BeTrue())
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user