feat(qa): add synthesis conversations with source retention (#52)
This commit is contained in:
76
backend/internal/api/qa_ticket53_postgres_test.go
Normal file
76
backend/internal/api/qa_ticket53_postgres_test.go
Normal file
@ -0,0 +1,76 @@
|
||||
package api_test
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"github.com/tradarr/backend/internal/models"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTicket53RetentionPreferenceHasExplicitUnitAndDefault(t *testing.T) {
|
||||
f, ok := reflect.TypeOf(models.UserPreferences{}).FieldByName("SourceArticleRetentionDays")
|
||||
if !ok || f.Type.Kind() != reflect.Int || f.Tag.Get("json") != "source_article_retention_days" {
|
||||
t.Fatal("missing bounded source_article_retention_days preference")
|
||||
}
|
||||
}
|
||||
func TestTicket53NewStorageMigrationPreservesLegacyPostgres(t *testing.T) {
|
||||
db := ticket14DB(t)
|
||||
for _, q := range []string{
|
||||
`CREATE TABLE users(id UUID PRIMARY KEY)`,
|
||||
`CREATE TABLE summaries(id UUID PRIMARY KEY,user_id UUID REFERENCES users(id))`,
|
||||
`CREATE TABLE articles(id TEXT PRIMARY KEY,content TEXT)`,
|
||||
`CREATE TABLE report_messages(id TEXT PRIMARY KEY,content TEXT)`,
|
||||
`INSERT INTO articles VALUES('legacy','keep article')`,
|
||||
`INSERT INTO report_messages VALUES('legacy','keep message')`,
|
||||
`INSERT INTO users VALUES('` + ticket14UserA + `')`,
|
||||
} {
|
||||
if _, err := db.Exec(q); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
raw, err := os.ReadFile("../database/migrations/000024_summary_qa.up.sql")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = db.Exec(string(raw)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var days int
|
||||
if err = db.QueryRow(`SELECT source_article_retention_days FROM users`).Scan(&days); err != nil || days != 7 {
|
||||
t.Fatalf("retention=%d err=%v", days, err)
|
||||
}
|
||||
for _, days := range []int{0, 31} {
|
||||
if _, err = db.Exec(`UPDATE users SET source_article_retention_days=$1`, days); err == nil {
|
||||
t.Fatalf("invalid retention accepted: %d", days)
|
||||
}
|
||||
}
|
||||
for _, table := range []string{"summary_qa_conversations", "summary_qa_sources", "summary_qa_turns"} {
|
||||
var n int
|
||||
if err = db.QueryRow(`SELECT COUNT(*) FROM ` + table).Scan(&n); err != nil || n != 0 {
|
||||
t.Fatalf("new table %s: count=%d err=%v", table, n, err)
|
||||
}
|
||||
}
|
||||
for _, table := range []string{"articles", "report_messages"} {
|
||||
var n int
|
||||
if err = db.QueryRow(`SELECT COUNT(*) FROM ` + table).Scan(&n); err != nil || n != 1 {
|
||||
t.Fatal("legacy modified", table, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func installQATables53(t *testing.T, db *sql.DB) {
|
||||
t.Helper()
|
||||
raw, err := os.ReadFile("../database/migrations/000024_summary_qa.up.sql")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
parts := strings.SplitN(string(raw), "CREATE UNIQUE INDEX", 2)
|
||||
if len(parts) != 2 {
|
||||
t.Fatal("Q&A schema marker missing")
|
||||
}
|
||||
if _, err = db.Exec("CREATE UNIQUE INDEX" + parts[1]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user