Fix modal overflow and search timeout warning
build-push / docker (push) Successful in 4m1s

This commit is contained in:
AI Assistant
2026-03-17 12:05:44 +09:00
parent 70c975c231
commit 0b68feff80
11 changed files with 367 additions and 45 deletions
+60
View File
@@ -2,7 +2,12 @@ package services
import (
"encoding/base64"
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"strings"
"sync/atomic"
"testing"
"time"
)
@@ -176,3 +181,58 @@ func TestSearchServiceFetchCacheRoundTrip(t *testing.T) {
t.Fatalf("unexpected cached body: %q", body)
}
}
func TestSearchServiceSkipsArtgridAPIAfter403(t *testing.T) {
var apiRequests atomic.Int32
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch {
case strings.HasPrefix(r.URL.Path, "/api/clip/details"):
apiRequests.Add(1)
http.Error(w, "forbidden", http.StatusForbidden)
case strings.HasPrefix(r.URL.Path, "/clip/114756/"):
w.Header().Set("Content-Type", "text/html; charset=utf-8")
_, _ = fmt.Fprintf(w, `<html><head><title>Friendly Couple | Stock Video Footage - Artgrid.io</title><meta property="og:title" content="Friendly Couple"><meta property="og:description" content="A warm couple moment"></head><body><script>window.__clip="%s";</script></body></html>`, "114756")
default:
http.NotFound(w, r)
}
}))
defer server.Close()
service := NewSearchService(server.URL, "", "")
serverURL, err := url.Parse(server.URL)
if err != nil {
t.Fatalf("failed to parse test server url: %v", err)
}
service.Client = &http.Client{
Transport: roundTripperFunc(func(req *http.Request) (*http.Response, error) {
clone := req.Clone(req.Context())
if clone.URL.Host == "artgrid.io" {
clone.URL.Scheme = serverURL.Scheme
clone.URL.Host = serverURL.Host
clone.Host = serverURL.Host
}
return http.DefaultTransport.RoundTrip(clone)
}),
}
item := SearchResult{
Link: "https://artgrid.io/clip/114756/friendly-couple",
Source: "Artgrid",
}
first := service.enrichArtgrid(item)
second := service.enrichArtgrid(item)
if apiRequests.Load() != 1 {
t.Fatalf("expected artgrid API to be skipped after first 403, got %d requests", apiRequests.Load())
}
if first.Title == "" || second.Title == "" {
t.Fatalf("expected HTML fallback enrichment to preserve title, got %#v %#v", first, second)
}
}
type roundTripperFunc func(*http.Request) (*http.Response, error)
func (fn roundTripperFunc) RoundTrip(req *http.Request) (*http.Response, error) {
return fn(req)
}