fix: purge the host site cache on Journal API post writes
Admin saves purged the site cache; the token API's create, update, delete and featured-image writes did not, so API-published posts waited for the site's cache TTL.
This commit is contained in:
@@ -387,3 +387,36 @@ func TestCategoriesAdminFrameworkKeysWin(t *testing.T) {
|
||||
t.Fatalf("the deprecated Journal target got %d requests: %+v", len(got), got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestJournalAPIPurgesSiteCache proves the token API's post writes purge
|
||||
// the host site's cache like admin saves: create, update and delete each
|
||||
// send one purge with kind post and the post's slug.
|
||||
func TestJournalAPIPurgesSiteCache(t *testing.T) {
|
||||
recv := newPurgeReceiver(t)
|
||||
env := newPostsEnv(t, recv.env()...)
|
||||
recv.drainFrom(t, env.app)
|
||||
token := env.admin(t, controllers.PermissionAccessPosts)
|
||||
|
||||
rec := env.expect(t, http.StatusCreated, http.MethodPost, "/_journal/api/v1/posts", token, map[string]any{
|
||||
"title": "Api purge",
|
||||
"content": "Before",
|
||||
})
|
||||
var created struct {
|
||||
Data struct {
|
||||
ID uint `json:"id"`
|
||||
Slug string `json:"slug"`
|
||||
} `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &created); err != nil || created.Data.ID == 0 {
|
||||
t.Fatalf("create body %s: %v", rec.Body.String(), err)
|
||||
}
|
||||
slug := created.Data.Slug
|
||||
recv.expectOnePurge(t, "create", "post", slug)
|
||||
|
||||
itemPath := fmt.Sprintf("/_journal/api/v1/posts/%d", created.Data.ID)
|
||||
env.expect(t, http.StatusOK, http.MethodPut, itemPath, token, map[string]any{"content": "After"})
|
||||
recv.expectOnePurge(t, "update", "post", slug)
|
||||
|
||||
env.expect(t, http.StatusOK, http.MethodDelete, itemPath, token, nil)
|
||||
recv.expectOnePurge(t, "delete", "post", slug)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user