test(media): verify library-scoped tag suggestions

This commit is contained in:
Gabriel20xx committed 2026-11-13 21:20:50 +01:00
1 parent 60befcd883
commit 750e9b7a85
1 file changed
+12 -5
+12 -5
View File
@@ -348,10 +348,6 @@ func TestTagsAgainstPostgres(t *testing.T) {
t.Fatalf("tags = %v, want Funny at 1 ahead of Quiet at -1", tags)
}
suggestions := decode(t, h.do(http.MethodGet, "/tags/suggestions?limit=5", "", ""))["tags"].([]any)
if len(suggestions) == 0 {
t.Fatal("suggestions are empty")
}
// A tag keeps its rows after its media is hidden or leaves the library. Only the library's
// media is listed for the tag, so a tag's examples never point at a thumbnail that is not found.
h.insertMedia(t, "rt-tags", "video", "tagged/clip.mp4", true)
@@ -367,7 +363,18 @@ func TestTagsAgainstPostgres(t *testing.T) {
t.Fatalf("media for the tag = %v, want only rt-tags (the hidden and unprocessed items are not listed)", listed)
}
// Without a limit, suggestions list every tag, not only the first 1000.
// Suggestions count the library's media, so Funny and Quiet count rt-tags only: the hidden and
// unprocessed items above are not in the library.
suggestions := decode(t, h.do(http.MethodGet, "/tags/suggestions?limit=5", "", ""))["tags"].([]any)
if len(suggestions) != 2 || suggestions[0].(map[string]any)["tag"] != "Funny" || suggestions[0].(map[string]any)["count"] != float64(1) || suggestions[1].(map[string]any)["tag"] != "Quiet" || suggestions[1].(map[string]any)["count"] != float64(1) {
t.Fatalf("suggestions = %v, want Funny and Quiet at 1 each", suggestions)
}
// Without a limit, suggestions list every tag, not only the first 1000. The bulk tags sit on a
// library item, because a tag on media that is not in the library is not suggested.
if _, err := h.pool.Exec(context.Background(), `INSERT INTO media (media_key, media_type, file_path, active, content_scanner_processed) VALUES ('rt-many', 'video', 'many/clip.mp4', TRUE, TRUE)`); err != nil {
t.Fatalf("insert many media: %v", err)
}
if _, err := h.pool.Exec(context.Background(), `INSERT INTO media_tags (media_key, tag, user_id) SELECT 'rt-many', 'bulk ' || g, NULL FROM generate_series(1, 1001) AS g`); err != nil {
t.Fatalf("insert many tags: %v", err)
}