36 lines
1.1 KiB
Go
36 lines
1.1 KiB
Go
package watchstate
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestMarkPlayedBatch_SingleUpsert(t *testing.T) {
|
|
sql, _ := buildMarkPlayedBatchSQL()
|
|
if !strings.Contains(sql, "INSERT INTO user_watch_progress") {
|
|
t.Fatalf("expected single INSERT INTO user_watch_progress; got:\n%s", sql)
|
|
}
|
|
if !strings.Contains(sql, "ON CONFLICT (user_id, profile_id, media_item_id) DO UPDATE") {
|
|
t.Fatalf("expected ON CONFLICT upsert; got:\n%s", sql)
|
|
}
|
|
if !strings.Contains(sql, "FROM unnest($3::text[])") {
|
|
t.Fatalf("expected UNNEST for batch IDs; got:\n%s", sql)
|
|
}
|
|
if !strings.Contains(sql, "completed = TRUE") {
|
|
t.Fatalf("expected completed flag set; got:\n%s", sql)
|
|
}
|
|
}
|
|
|
|
func TestMarkUnplayedBatch_BatchedUpdate(t *testing.T) {
|
|
sql, _ := buildMarkUnplayedBatchSQL()
|
|
if !strings.Contains(sql, "UPDATE user_watch_progress") {
|
|
t.Fatalf("expected UPDATE user_watch_progress; got:\n%s", sql)
|
|
}
|
|
if !strings.Contains(sql, "completed = FALSE") {
|
|
t.Fatalf("expected completed = FALSE; got:\n%s", sql)
|
|
}
|
|
if !strings.Contains(sql, "media_item_id = ANY($3::text[])") {
|
|
t.Fatalf("expected ANY(text[]) batch filter; got:\n%s", sql)
|
|
}
|
|
}
|