HTTP API: 404 for a chat id the list of chats leaves out (closes #5)
check / check (push) Successful in 1m19s

The chat client keeps contact records that GET /api/v1/chats does not
list, such as the bot's own profile (1 on a new profile) and a contact
it creates itself (2), and reads or sends in them when asked. The
message endpoints now look the id up, through chatID in
internal/api/chats.go, in the same list the chats endpoint answers
with, and answer 404 for any id not in it. The webhook endpoints can
call chatID too.

Model: opus-5-5
This commit is contained in:
2026-09-29 04:32:28 +00:00
parent 2ad0b68e35
commit 2ce8da766a
6 changed files with 140 additions and 69 deletions
+9 -7
View File
@@ -29,12 +29,14 @@ const (
var errChat = errors.New("sqlite: database is locked at /var/lib/simplexcalc")
// fakeClient stands in for the chat client. It answers with contacts,
// items or sent, or with err, and remembers what it was asked.
// items or sent, or with an error: contactsErr from Contacts, err from
// the others. It remembers what it was asked.
type fakeClient struct {
contacts []simplex.Contact
items []simplex.ChatItem
sent simplex.ChatItem
err error
contacts []simplex.Contact
items []simplex.ChatItem
sent simplex.ChatItem
contactsErr error
err error
userID, contactID int64
count int
@@ -48,7 +50,7 @@ func (f *fakeClient) Contacts(
f.userID = userID
_, f.hadDeadline = ctx.Deadline()
return f.contacts, f.err
return f.contacts, f.contactsErr
}
func (f *fakeClient) ChatItems(
@@ -269,7 +271,7 @@ func TestHeaders(t *testing.T) {
{&fakeClient{}, chatsPath, bearer},
{&fakeClient{}, chatsPath, ""},
{&fakeClient{}, "/nothing", bearer},
{&fakeClient{err: errChat}, chatsPath, bearer},
{&fakeClient{contactsErr: errChat}, chatsPath, bearer},
} {
rec := request(t, newAPI(credential, tc.client),
http.MethodGet, tc.path, tc.auth)