29 lines
1.2 KiB
Go
29 lines
1.2 KiB
Go
package ws
|
|
|
|
import (
|
|
"Rezina-Backend/internal/domain"
|
|
"testing"
|
|
)
|
|
|
|
func TestNotificationRecipientIsolation(t *testing.T) {
|
|
customer := &Client{RecipientID: 42, ReceiverType: domain.ReceiverTypeUser}
|
|
staff := &Client{RecipientID: 42, ReceiverType: domain.ReceiverTypeTeamMember}
|
|
for _, tc := range []struct {
|
|
name string
|
|
payload map[string]interface{}
|
|
customer, staff bool
|
|
}{
|
|
{"customer event", map[string]interface{}{"recipient_id": int64(42), "receiver_type": domain.ReceiverTypeUser}, true, false},
|
|
{"staff event", map[string]interface{}{"recipient_id": int64(42), "receiver_type": domain.ReceiverTypeTeamMember}, false, true},
|
|
{"serialized type", map[string]interface{}{"recipient_id": int64(42), "receiver_type": "team_member"}, false, true},
|
|
{"another recipient", map[string]interface{}{"recipient_id": int64(99), "receiver_type": domain.ReceiverTypeUser}, false, false},
|
|
{"unscoped event", map[string]interface{}{"recipient_id": int64(42)}, false, false},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
if customer.receives(tc.payload) != tc.customer || staff.receives(tc.payload) != tc.staff {
|
|
t.Fatal("notification crossed account boundary")
|
|
}
|
|
})
|
|
}
|
|
}
|