Move pages to and from the vault
A page, including a journal day, can be moved into the unlocked vault with its id kept. Links to it elsewhere become [[locked:id]], shown as Locked Page until the vault is unlocked, so its title is kept only in the vault. Move out reverses it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c08a8b8718
commit
994927c704
10 files changed
+443
-14
No files matched your search
@@ -834,3 +834,73 @@ func TestVaultNeedsSignInAndHeader(t *testing.T) {
|
||||
t.Fatalf("no header: %d", w.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMovePagesIntoAndOutOfTheVault(t *testing.T) {
|
||||
e := withVault(t)
|
||||
a := e.signIn(alice)
|
||||
var secret, notes, day struct{ ID, Body, Title string }
|
||||
jsonOf(t, e.do("POST", "/api/notes", map[string]string{"title": "Secret plan", "body": "the plan"}, a), &secret)
|
||||
jsonOf(t, e.do("POST", "/api/notes", map[string]string{"title": "Notes", "body": "see [[Secret plan]] and [[secret plan|it]]"}, a), ¬es)
|
||||
jsonOf(t, e.do("POST", "/api/daily", map[string]string{"date": "2026-10-31"}, a), &day)
|
||||
e.do("PUT", "/api/notes/"+day.ID, map[string]string{"body": "dear diary"}, a)
|
||||
|
||||
// there is nowhere to put it until the vault is open
|
||||
if w := e.do("POST", "/api/notes/"+secret.ID+"/vault", nil, a); w.Code != http.StatusLocked {
|
||||
t.Fatalf("moving with no vault: %d", w.Code)
|
||||
}
|
||||
w := e.do("POST", "/api/vault", map[string]string{"passphrase": "correct horse battery"}, a)
|
||||
open := vaultCookies(a, w)
|
||||
|
||||
for _, id := range []string{secret.ID, day.ID} {
|
||||
if w := e.do("POST", "/api/notes/"+id+"/vault", nil, open); w.Code != http.StatusOK {
|
||||
t.Fatalf("move %s in: %d %s", id, w.Code, w.Body)
|
||||
}
|
||||
}
|
||||
if w := e.do("GET", "/api/notes/"+secret.ID, nil, open); w.Code != http.StatusNotFound {
|
||||
t.Fatalf("the page is still in the notebook: %d", w.Code)
|
||||
}
|
||||
var in struct{ ID, Title, Body, Daily string }
|
||||
jsonOf(t, e.do("GET", "/api/vault/notes/"+secret.ID, nil, open), &in)
|
||||
if in.ID != secret.ID || in.Title != "Secret plan" || in.Body != "the plan" {
|
||||
t.Fatalf("in the vault: %+v", in)
|
||||
}
|
||||
jsonOf(t, e.do("GET", "/api/vault/notes/"+day.ID, nil, open), &in)
|
||||
if in.Daily != "2026-10-31" || in.Body != "dear diary" {
|
||||
t.Fatalf("the day in the vault: %+v", in)
|
||||
}
|
||||
|
||||
// the page that linked to it now shows a locked link and says nothing of the title
|
||||
var n struct{ Body string }
|
||||
jsonOf(t, e.do("GET", "/api/notes/"+notes.ID, nil, open), &n)
|
||||
if want := "see [[locked:" + secret.ID + "]] and [[locked:" + secret.ID + "]]"; n.Body != want {
|
||||
t.Fatalf("links: %q want %q", n.Body, want)
|
||||
}
|
||||
for _, path := range []string{"/api/notes", "/api/pages", "/api/find?q=Secret", "/api/find?q=diary"} {
|
||||
if w := e.do("GET", path, nil, open); strings.Contains(w.Body.String(), "Secret plan") || strings.Contains(w.Body.String(), "diary") {
|
||||
t.Fatalf("%s still shows the moved pages: %s", path, w.Body)
|
||||
}
|
||||
}
|
||||
|
||||
// the same day cannot be moved in twice
|
||||
var again struct{ ID string }
|
||||
jsonOf(t, e.do("POST", "/api/daily", map[string]string{"date": "2026-10-31"}, open), &again)
|
||||
if w := e.do("POST", "/api/notes/"+again.ID+"/vault", nil, open); w.Code != http.StatusConflict {
|
||||
t.Fatalf("a second journal page for the day: %d %s", w.Code, w.Body)
|
||||
}
|
||||
|
||||
// and back out: the links name the page again
|
||||
if w := e.do("POST", "/api/vault/notes/"+secret.ID+"/out", nil, open); w.Code != http.StatusOK {
|
||||
t.Fatalf("move out: %d %s", w.Code, w.Body)
|
||||
}
|
||||
if w := e.do("GET", "/api/vault/notes/"+secret.ID, nil, open); w.Code != http.StatusNotFound {
|
||||
t.Fatalf("the page is still in the vault: %d", w.Code)
|
||||
}
|
||||
jsonOf(t, e.do("GET", "/api/notes/"+secret.ID, nil, open), &in)
|
||||
if in.Title != "Secret plan" || in.Body != "the plan" {
|
||||
t.Fatalf("back in the notebook: %+v", in)
|
||||
}
|
||||
jsonOf(t, e.do("GET", "/api/notes/"+notes.ID, nil, open), &n)
|
||||
if n.Body != "see [[Secret plan]] and [[Secret plan]]" {
|
||||
t.Fatalf("links after coming back: %q", n.Body)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user