fix: fire RecordSaved for tags the post API creates by name
journal-tag is a content type, but tags created on the fly from names in a post write fired no event, so SEO and sitemap subscribers only heard of them from a later bulk job. Each created tag now fires a RecordSaved with Created inside the post write's transaction.
This commit is contained in:
@@ -258,6 +258,33 @@ func TestAPIRecordEvents(t *testing.T) {
|
||||
t.Fatalf("pl content_html change = %+v (found %v); changes %+v", html, ok, got[0].ev.Changes)
|
||||
}
|
||||
|
||||
// A tag the write creates by name fires its own RecordSaved (WR-06).
|
||||
l.reset()
|
||||
env.expect(t, http.StatusOK, http.MethodPut, "/_journal/api/v1/posts/"+id, token, map[string]any{
|
||||
"tags": []any{"Fresh event tag"},
|
||||
})
|
||||
got = l.savedEvents()
|
||||
tagMorph := (models.Tag{}).MorphName()
|
||||
var tagEvent *savedEvent
|
||||
for i := range got {
|
||||
if got[i].ev.Model == tagMorph {
|
||||
tagEvent = &got[i]
|
||||
}
|
||||
}
|
||||
if len(got) != 2 || tagEvent == nil || !tagEvent.ev.Created || tagEvent.ev.ID == "" || tagEvent.key != classes.MenuTypeTag {
|
||||
t.Fatalf("PUT with a new tag events = %+v, want the post and the created tag", got)
|
||||
}
|
||||
if c, ok := findChange(tagEvent.ev.Changes, "name", ""); !ok || c.New != "Fresh event tag" {
|
||||
t.Fatalf("tag name change = %+v (found %v)", c, ok)
|
||||
}
|
||||
l.reset()
|
||||
env.expect(t, http.StatusOK, http.MethodPut, "/_journal/api/v1/posts/"+id, token, map[string]any{
|
||||
"tags": []any{"Fresh event tag"},
|
||||
})
|
||||
if got = l.savedEvents(); len(got) != 1 {
|
||||
t.Fatalf("PUT with an existing tag events = %+v, want only the post", got)
|
||||
}
|
||||
|
||||
// A write that fails after the row is saved rolls the row back and
|
||||
// fires nothing (WR-04).
|
||||
l.reset()
|
||||
|
||||
Reference in New Issue
Block a user