feat: implement multiple new job crawlers and add corresponding test suites
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
package netflix
|
||||
|
||||
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 TestNetflixCrawler_DiscoverAndFetch(t *testing.T) {
|
||||
mockClient := &http.Client{
|
||||
Transport: roundTripFunc(func(r *http.Request) *http.Response {
|
||||
if strings.Contains(r.URL.Path, "/api/search") {
|
||||
body := `{
|
||||
"records": {
|
||||
"total": 1,
|
||||
"postings": [
|
||||
{
|
||||
"id": 8192301,
|
||||
"external_id": "8192301",
|
||||
"text": "Senior Software Engineer - Cloud Platform",
|
||||
"location": "Seattle, WA, United States"
|
||||
}
|
||||
]
|
||||
}
|
||||
}`
|
||||
return &http.Response{
|
||||
StatusCode: http.StatusOK,
|
||||
Body: io.NopCloser(bytes.NewBufferString(body)),
|
||||
Header: make(http.Header),
|
||||
}
|
||||
}
|
||||
|
||||
if strings.Contains(r.URL.Path, "/postings/8192301") {
|
||||
body := `{
|
||||
"id": 8192301,
|
||||
"external_id": "8192301",
|
||||
"text": "Senior Software Engineer - Cloud Platform",
|
||||
"description": "<p>We are looking for senior engineers to evolve Netflix telemetry and control planes.</p>",
|
||||
"location": "Seattle, WA, United States"
|
||||
}`
|
||||
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 := NewNetflixCrawlerWithClient(mockClient)
|
||||
if !c.CanHandle("netflix") {
|
||||
t.Errorf("CanHandle should support netflix")
|
||||
}
|
||||
|
||||
discovered, err := c.DiscoverJobs(context.Background(), "https://jobs.netflix.com/api/search?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 != "netflix:8192301" {
|
||||
t.Errorf("unexpected canonical ID: %s", discovered[0].CanonicalID)
|
||||
}
|
||||
|
||||
extracted, err := c.FetchJobDetail(context.Background(), "https://jobs.netflix.com/jobs/8192301")
|
||||
if err != nil {
|
||||
t.Fatalf("FetchJobDetail failed: %v", err)
|
||||
}
|
||||
|
||||
if extracted.Title != "Senior Software Engineer - Cloud Platform" {
|
||||
t.Errorf("unexpected title: %s", extracted.Title)
|
||||
}
|
||||
if extracted.Company != "Netflix" {
|
||||
t.Errorf("unexpected company: %s", extracted.Company)
|
||||
}
|
||||
if extracted.Location != "Seattle, WA, United States" {
|
||||
t.Errorf("unexpected location: %s", extracted.Location)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNetflixCrawler_LiveIntegration(t *testing.T) {
|
||||
crawlertest.RunLiveIntegration(t, crawlertest.LiveTestConfig{
|
||||
PlatformName: "Netflix",
|
||||
Crawler: NewNetflixCrawler(),
|
||||
TargetURL: "https://jobs.netflix.com/api/search?q=Software+Engineer",
|
||||
ExpectedCanonicalPrefix: "netflix:",
|
||||
ExpectedCompany: "Netflix",
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user