feat: announce material revisions on materials:{id}
- every revision bump (API writes and /bmadmin saves) enqueues
updated.jz.bm.material with {material_id, revision} in a savepoint
- the materials namespace authorizer allows a subscribe only to a
visible material the user may manage
- api.ManagesMaterials and api.CanWatchMaterial
This commit is contained in:
48
classes/material_revision_test.go
Normal file
48
classes/material_revision_test.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package classes
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"git.golem15.com/golem15/summercms/modules/lighthouse"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func TestMaterialChannel(t *testing.T) {
|
||||
for _, id := range []uint{1, 5, 42, 1234567890} {
|
||||
ch := MaterialChannel(id)
|
||||
got, ok := MaterialChannelID(ch)
|
||||
if !ok || got != id {
|
||||
t.Errorf("MaterialChannelID(%q) = %d, %v, want %d, true", ch, got, ok, id)
|
||||
}
|
||||
}
|
||||
if got := MaterialChannel(5); got != "materials:5" {
|
||||
t.Errorf("MaterialChannel(5) = %q", got)
|
||||
}
|
||||
for _, ch := range []string{
|
||||
"materials:5abc",
|
||||
"materials:05",
|
||||
"materials:0",
|
||||
"materials:5:x",
|
||||
"presence:materials:5",
|
||||
"materials:",
|
||||
"materials",
|
||||
"materials:-5",
|
||||
"materials: 5",
|
||||
"materials:99999999999999999999",
|
||||
"user:5",
|
||||
"",
|
||||
} {
|
||||
if id, ok := MaterialChannelID(ch); ok {
|
||||
t.Errorf("MaterialChannelID(%q) = %d, true, want a refusal", ch, id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMaterialRevisionNotifierNil(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
var nilNotifier *MaterialRevisionNotifier
|
||||
nilNotifier.Revised(ctx, &gorm.DB{}, 5, 2)
|
||||
(&MaterialRevisionNotifier{}).Revised(ctx, &gorm.DB{}, 5, 2)
|
||||
(&MaterialRevisionNotifier{Realtime: &lighthouse.Service{}}).Revised(ctx, nil, 5, 2)
|
||||
}
|
||||
Reference in New Issue
Block a user