feat(16.2-07): purge the host site cache on every admin post and category write
- posts: FormAfterCreate/Update purge after the content_html translations, new FormAfterDelete; categories: FormAfterCreate and FormAfterDelete - NewSiteCachePurger refuses half configuration, non-http(s) URLs, user info, fragments, http to a non-loopback host and tokens under 32 chars; Boot logs the endpoint host and path once - TestPostsAdminPurgesSiteCache smoke test - README: Configuration section (keys, contract, timing, scope), API rows
This commit is contained in:
@@ -165,3 +165,38 @@ func TestCategoriesAdminPurgesSiteCache(t *testing.T) {
|
||||
t.Fatalf("the purge saw content %q, want the committed %q (purge before commit)", req.Seen, edited)
|
||||
}
|
||||
}
|
||||
|
||||
// TestPostsAdminPurgesSiteCache proves an admin update of a post sends one
|
||||
// authorized purge request with kind post after the save commits.
|
||||
func TestPostsAdminPurgesSiteCache(t *testing.T) {
|
||||
recv := newPurgeReceiver(t)
|
||||
env := newPostsEnv(t, recv.env()...)
|
||||
token := env.admin(t, controllers.PermissionAccessPosts)
|
||||
|
||||
rec := env.expect(t, http.StatusCreated, http.MethodPost, adminAPI(adminPostsPath), token, map[string]any{
|
||||
"title": map[string]any{"en": "Purge post", "pl": "Wpis"},
|
||||
"slug": map[string]any{"en": "purge-post", "pl": "wpis"},
|
||||
"content": map[string]any{"en": "<p>Before</p>"},
|
||||
"excerpt": map[string]any{"en": "Excerpt", "pl": "Wyjątek"},
|
||||
})
|
||||
id := adminCreatedID(t, rec)
|
||||
recv.take()
|
||||
|
||||
recv.setProbe(func() string {
|
||||
var post models.Post
|
||||
if err := env.gdb.First(&post, id).Error; err != nil {
|
||||
return "error: " + err.Error()
|
||||
}
|
||||
return post.ContentHTML
|
||||
})
|
||||
served := servedForm(t, env, token, id)
|
||||
const edited = "<p>After the edit</p>"
|
||||
body := servedBody(served, "title", "slug", "excerpt")
|
||||
body["content"] = map[string]any{"en": edited}
|
||||
env.expect(t, http.StatusOK, http.MethodPut, adminAPI(fmt.Sprintf("%s/%d", adminPostsPath, id)), token, body)
|
||||
|
||||
req := recv.expectOnePurge(t, "update", "post", "purge-post")
|
||||
if req.Seen != edited {
|
||||
t.Fatalf("the purge saw content_html %q, want the committed %q (purge before commit)", req.Seen, edited)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user