package nvidia 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 TestNvidiaCrawler_DiscoverAndFetch(t *testing.T) { mockClient := &http.Client{ Transport: roundTripFunc(func(r *http.Request) *http.Response { if strings.Contains(r.URL.Path, "/job/JR1982000") { body := `{ "jobPostingInfo": { "id": "JR1982000", "title": "Senior Systems Software Engineer - GPU Infrastructure", "jobDescription": "
NVIDIA is seeking senior systems software engineers to accelerate AI data centers.
", "location": "Redmond, WA", "additionalLocations": ["Seattle, WA"] } }` return &http.Response{ StatusCode: http.StatusOK, Body: io.NopCloser(bytes.NewBufferString(body)), Header: make(http.Header), } } if strings.HasSuffix(r.URL.Path, "/jobs") { body := `{ "total": 1, "jobPostings": [ { "title": "Senior Systems Software Engineer - GPU Infrastructure", "externalPath": "/job/JR1982000", "locationsText": "Redmond, WA", "jobPostingId": "JR1982000" } ] }` 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 := NewNvidiaCrawlerWithClient(mockClient) if !c.CanHandle("nvidia") { t.Errorf("CanHandle should support nvidia") } discovered, err := c.DiscoverJobs(context.Background(), "https://nvidia.wd5.myworkdayjobs.com/NVIDIAExternalCareerSite?q=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 != "nvidia:JR1982000" { t.Errorf("unexpected canonical ID: %s", discovered[0].CanonicalID) } extracted, err := c.FetchJobDetail(context.Background(), "https://nvidia.wd5.myworkdayjobs.com/en-US/NVIDIAExternalCareerSite/job/JR1982000") if err != nil { t.Fatalf("FetchJobDetail failed: %v", err) } if extracted.Title != "Senior Systems Software Engineer - GPU Infrastructure" { t.Errorf("unexpected title: %s", extracted.Title) } if extracted.Company != "NVIDIA" { t.Errorf("unexpected company: %s", extracted.Company) } if extracted.Location != "Redmond, WA; Seattle, WA" { t.Errorf("unexpected location: %s", extracted.Location) } } func TestNvidiaCrawler_LiveIntegration(t *testing.T) { crawlertest.RunLiveIntegration(t, crawlertest.LiveTestConfig{ PlatformName: "NVIDIA", Crawler: NewNvidiaCrawler(), TargetURL: "https://nvidia.wd5.myworkdayjobs.com/NVIDIAExternalCareerSite?q=Software+Engineer", ExpectedCanonicalPrefix: "nvidia:", ExpectedCompany: "NVIDIA", }) }