(t *testing.T)
| 45 | } |
| 46 | |
| 47 | func TestThreads(t *testing.T) { |
| 48 | // Get a posting from imbox to use as thread ID. |
| 49 | resp := heyJSON(t, "box", "imbox") |
| 50 | type Posting struct { |
| 51 | AppURL string `json:"app_url"` |
| 52 | ID int `json:"id"` |
| 53 | } |
| 54 | type BoxResp struct { |
| 55 | Postings []Posting `json:"postings"` |
| 56 | } |
| 57 | data := dataAs[BoxResp](t, resp) |
| 58 | if len(data.Postings) == 0 { |
| 59 | t.Fatal("no postings in imbox to test threads") |
| 60 | } |
| 61 | |
| 62 | // The thread ID in the CLI is the topic ID, extracted from app_url. |
| 63 | // app_url looks like "http://host/topics/12345", so we extract the topic ID. |
| 64 | topicID := extractTopicID(data.Postings[0].AppURL) |
| 65 | if topicID == "" { |
| 66 | t.Fatalf("could not extract topic ID from app_url: %s", data.Postings[0].AppURL) |
| 67 | } |
| 68 | |
| 69 | threadsResp := heyJSON(t, "thread", "read", topicID) |
| 70 | type Entry struct { |
| 71 | ID int `json:"id"` |
| 72 | Summary string `json:"summary"` |
| 73 | } |
| 74 | entries := dataAs[[]Entry](t, threadsResp) |
| 75 | if len(entries) == 0 { |
| 76 | t.Error("expected at least one entry in thread") |
| 77 | } |
| 78 | |
| 79 | // Cross-verify: the thread content should exist on the topic page. |
| 80 | html := fetchHTML(t, fmt.Sprintf("%s/topics/%s", baseURL, topicID)) |
| 81 | if len(entries) > 0 && entries[0].Summary != "" { |
| 82 | assertContains(t, html, entries[0].Summary) |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | func TestReply(t *testing.T) { |
| 87 | // First try to compose a message to get a thread. |
nothing calls this directly
no test coverage detected