Add owner inbox UI with address release
Web: "My listings" (listings, requests of a listing, conversation) in three panes on wide screens and one at a time on phones, and a sheet or dialog to release the exact address. Sign-in uses a link printed by `node run` (token in the URL fragment, kept in sessionStorage only). API: GET /api/v1/mine (own listings with request counts and whether an address is saved); inbox rows gain last_dir, needs_reply, preview, effort and grant_until, and can be filtered by listing. Docs: PROTOCOL.md and README describe the owner UI and login. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -155,6 +155,82 @@ func TestMessagingOverHTTP(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMineAndThreadSummaries(t *testing.T) {
|
||||
f := newFixture(t, token)
|
||||
l := f.publish(t)
|
||||
|
||||
// Nothing yet: the listing is there, with nothing in its inbox.
|
||||
var mine []mineView
|
||||
code, body := f.do(t, "GET", "/api/v1/mine", "", true)
|
||||
if code != 200 || json.Unmarshal(body, &mine) != nil || len(mine) != 1 {
|
||||
t.Fatalf("mine: %d %s", code, body)
|
||||
}
|
||||
if mine[0].ID != l.ID || mine[0].Title != l.Title || mine[0].Threads != 0 || mine[0].AddressSaved {
|
||||
t.Fatalf("empty listing: %+v", mine[0])
|
||||
}
|
||||
|
||||
// One readable request, one with a link (hidden).
|
||||
ok, bad := newThread(t), newThread(t)
|
||||
f.send(t, buyerHello(t, l, ok, "Ist die Wohnung noch frei?"))
|
||||
f.send(t, buyerHello(t, l, bad, "Schau auf https://evil.example"))
|
||||
f.do(t, "PUT", "/api/v1/listings/"+l.ID+"/address", `{"address":"Musterweg 7, 22765 Hamburg"}`, true)
|
||||
|
||||
code, body = f.do(t, "GET", "/api/v1/mine", "", true)
|
||||
if code != 200 || json.Unmarshal(body, &mine) != nil {
|
||||
t.Fatalf("mine: %d %s", code, body)
|
||||
}
|
||||
if m := mine[0]; m.Threads != 2 || m.NeedsReply != 1 || m.Hidden != 1 || !m.AddressSaved {
|
||||
t.Fatalf("counts: %+v", m)
|
||||
}
|
||||
|
||||
byThread := func() map[string]threadView {
|
||||
var ts []threadView
|
||||
code, body := f.do(t, "GET", "/api/v1/inbox?listing="+l.ID, "", true)
|
||||
if code != 200 || json.Unmarshal(body, &ts) != nil {
|
||||
t.Fatalf("inbox: %d %s", code, body)
|
||||
}
|
||||
out := map[string]threadView{}
|
||||
for _, v := range ts {
|
||||
out[v.Thread] = v
|
||||
}
|
||||
return out
|
||||
}
|
||||
ts := byThread()
|
||||
a, b := ts[ok.PublicHex()], ts[bad.PublicHex()]
|
||||
if !a.NeedsReply || a.LastDir != "in" || a.Preview != "Ist die Wohnung noch frei?" || a.Effort < msgDifficulty {
|
||||
t.Fatalf("readable request: %+v", a)
|
||||
}
|
||||
if b.NeedsReply || b.Preview != "" || b.Hidden != 1 {
|
||||
t.Fatalf("hidden request must not leak its text or ask for a reply: %+v", b)
|
||||
}
|
||||
|
||||
// Answer with an address: the request no longer needs a reply and shows the release.
|
||||
path := "/api/v1/inbox/" + l.ID + "/" + ok.PublicHex()
|
||||
if code, body := f.do(t, "POST", path, `{"type":"grant","note":"Samstag 10 Uhr","valid_days":7}`, true); code != 200 {
|
||||
t.Fatalf("grant: %d %s", code, body)
|
||||
}
|
||||
a = byThread()[ok.PublicHex()]
|
||||
if a.NeedsReply || a.LastDir != "out" || a.GrantUntil == 0 || a.Preview != "" {
|
||||
t.Fatalf("after the grant: %+v", a)
|
||||
}
|
||||
|
||||
// Another listing's filter returns nothing; the token is required.
|
||||
if code, body := f.do(t, "GET", "/api/v1/inbox?listing="+strings.Repeat("0", 32), "", true); code != 200 || strings.TrimSpace(string(body)) != "[]" {
|
||||
t.Fatalf("filter: %d %s", code, body)
|
||||
}
|
||||
if code, _ := f.do(t, "GET", "/api/v1/mine", "", false); code != 401 {
|
||||
t.Fatalf("mine without a token: %d", code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHexZeroBits(t *testing.T) {
|
||||
for h, want := range map[string]int{"": 0, "f": 0, "8": 0, "7": 1, "1": 3, "0": 4, "00f": 8, "0a": 4, "004": 9, "0000": 16, "zz": 0} {
|
||||
if got := hexZeroBits(h); got != want {
|
||||
t.Errorf("hexZeroBits(%q) = %d, want %d", h, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHiddenFirstMessageTextIsWithheld(t *testing.T) {
|
||||
f := newFixture(t, token)
|
||||
l := f.publish(t)
|
||||
|
||||
Reference in New Issue
Block a user