Files
TradarrV2/backend/internal/scraper/bloomberg/dates_ticket34_test.go

29 lines
1.2 KiB
Go

package bloomberg
import (
"context"
"io"
"net/http"
"strings"
"testing"
"time"
)
type dateTransport func(*http.Request) (*http.Response, error)
func (f dateTransport) RoundTrip(r *http.Request) (*http.Response, error) { return f(r) }
func TestTicket34BloombergUsesOnlyRealPublicationDates(t *testing.T) {
b := New("http://fixture.invalid")
b.client = &http.Client{Transport: dateTransport(func(*http.Request) (*http.Response, error) {
return &http.Response{StatusCode: 200, Body: io.NopCloser(strings.NewReader(`{"articles":[{"title":"fixture-a","url":"https://fixture.invalid/a","published_at":"2026-01-02T03:04:05.000Z"},{"title":"fixture-b","url":"https://fixture.invalid/b","published_at":null},{"title":"fixture-c","url":"https://fixture.invalid/c","published_at":"invalid"}]}`)), Header: make(http.Header)}, nil
})}
got, err := b.ScrapeWithCredentials(context.Background(), "fixture", "fixture", nil)
if err != nil || len(got) != 3 {
t.Fatal(err)
}
want := time.Date(2026, 1, 2, 3, 4, 5, 0, time.UTC)
if got[0].PublishedAt == nil || !got[0].PublishedAt.Equal(want) || got[1].PublishedAt != nil || got[2].PublishedAt != nil {
t.Fatal("publication date invented or lost")
}
}