package uber import ( "bytes" "context" "io" "net/http" "strings" "testing" "github.com/hireme/hireme/internal/crawler/crawlertest" ) type roundTripFunc func(req *http.Request) *http.Response func (f roundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) { return f(req), nil } func TestUberCrawler_DiscoverAndFetch(t *testing.T) { mockClient := &http.Client{ Transport: roundTripFunc(func(r *http.Request) *http.Response { if strings.Contains(r.URL.Path, "loadSearchJobsResults") { body := `{ "status": "success", "data": { "totalResults": 1, "results": [ { "id": 139820, "title": "Software Engineer II - Core Compute & Storage", "location": "Seattle, WA", "city": "Seattle", "countryName": "USA" } ] } }` return &http.Response{ StatusCode: http.StatusOK, Body: io.NopCloser(bytes.NewBufferString(body)), Header: make(http.Header), } } if strings.Contains(r.URL.Path, "loadJobDetails") { body := `{ "data": { "id": 139820, "title": "Software Engineer II - Core Compute & Storage", "description": "

Uber Infra powers global dispatch and real-time computation.

", "whatYouWillDo": "
  • Architect scalable storage solutions using Go and Java.
  • ", "basicQualifications": "
  • 2+ years of backend software development experience.
  • ", "location": "Seattle, WA" } }` return &http.Response{ StatusCode: http.StatusOK, Body: io.NopCloser(bytes.NewBufferString(body)), Header: make(http.Header), } } return &http.Response{ StatusCode: http.StatusNotFound, Body: io.NopCloser(bytes.NewBufferString("not found")), Header: make(http.Header), } }), } c := NewUberCrawlerWithClient(mockClient) if !c.CanHandle("uber") { t.Errorf("CanHandle should support uber") } discovered, err := c.DiscoverJobs(context.Background(), "https://www.uber.com/global/en/careers/search/?query=Software+Engineer") if err != nil { t.Fatalf("DiscoverJobs failed: %v", err) } if len(discovered) != 1 { t.Fatalf("expected 1 discovered job, got %d", len(discovered)) } if discovered[0].CanonicalID != "uber:139820" { t.Errorf("unexpected canonical ID: %s", discovered[0].CanonicalID) } extracted, err := c.FetchJobDetail(context.Background(), "https://www.uber.com/global/en/careers/list/139820/") if err != nil { t.Fatalf("FetchJobDetail failed: %v", err) } if extracted.Title != "Software Engineer II - Core Compute & Storage" { t.Errorf("unexpected title: %s", extracted.Title) } if extracted.Company != "Uber" { t.Errorf("unexpected company: %s", extracted.Company) } if extracted.Location != "Seattle, WA" { t.Errorf("unexpected location: %s", extracted.Location) } } func TestUberCrawler_LiveIntegration(t *testing.T) { crawlertest.RunLiveIntegration(t, crawlertest.LiveTestConfig{ PlatformName: "Uber", Crawler: NewUberCrawler(), TargetURL: "https://www.uber.com/global/en/careers/search/?query=Software+Engineer", ExpectedCanonicalPrefix: "uber:", ExpectedCompany: "Uber", }) }