Delete and rename conversations
This commit is contained in:
@@ -2,6 +2,7 @@ package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json/jsontext"
|
||||
"encoding/json/v2"
|
||||
"errors"
|
||||
@@ -134,6 +135,46 @@ func testConversation(t *testing.T, ctx context.Context, db *SQLite) {
|
||||
if len(conversations) != 1 {
|
||||
t.Fatalf("expected 1 conversation, got %d", len(conversations))
|
||||
}
|
||||
|
||||
// Rename the conversation. Insert a message first: the insert
|
||||
// trigger moves updated_at, so the rename can show that it
|
||||
// keeps the timestamp.
|
||||
if _, err := qw.InsertMessage(ctx, InsertMessageParams{
|
||||
ConversationId: c.Id,
|
||||
Sequence: 1,
|
||||
Role: MessageRoleUser,
|
||||
Content: jsontext.Value(`{"role":"user","content":"Hello"}`),
|
||||
}); err != nil {
|
||||
t.Fatalf("InsertMessage: %v", err)
|
||||
}
|
||||
before, err := qr.SelectConversationId(ctx, c.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("SelectConversationId: %v", err)
|
||||
}
|
||||
renamed, err := qw.UpdateConversationTitle(ctx, UpdateConversationTitleParams{
|
||||
Id: c.Id,
|
||||
Title: "renamed",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("UpdateConversationTitle: %v", err)
|
||||
}
|
||||
if renamed.Title == nil || *renamed.Title != "renamed" {
|
||||
t.Fatalf("Title = %v, want renamed", renamed.Title)
|
||||
}
|
||||
if !renamed.UpdatedAt.Equal(before.UpdatedAt) {
|
||||
t.Fatalf(
|
||||
"UpdatedAt = %v, want %v: a rename must not move updated_at",
|
||||
renamed.UpdatedAt, before.UpdatedAt,
|
||||
)
|
||||
}
|
||||
|
||||
// A rename of a missing conversation reports no rows.
|
||||
if _, err := qw.UpdateConversationTitle(ctx, UpdateConversationTitleParams{
|
||||
Id: "missing",
|
||||
Title: "renamed",
|
||||
}); !errors.Is(err, sql.ErrNoRows) {
|
||||
t.Fatalf("UpdateConversationTitle(missing) = %v, want sql.ErrNoRows", err)
|
||||
}
|
||||
}
|
||||
|
||||
func testMessaging(t *testing.T, ctx context.Context, db *SQLite) {
|
||||
|
||||
Reference in New Issue
Block a user