feat: implement multiple new job crawlers and add corresponding test suites

This commit is contained in:
2026-08-25 00:12:52 -07:00
parent 0de312edbd
commit 55d4f4a0d9
26 changed files with 4045 additions and 15 deletions
+119
View File
@@ -0,0 +1,119 @@
package bytedance
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 TestByteDanceCrawler_DiscoverAndFetch(t *testing.T) {
mockClient := &http.Client{
Transport: roundTripFunc(func(r *http.Request) *http.Response {
if strings.Contains(r.URL.Path, "/search/job/posts") {
body := `{
"code": 0,
"data": {
"count": 1,
"job_post_list": [
{
"id": "7198234123",
"title": "Software Engineer - Distributed Storage (Seattle/Bellevue)",
"city_info": {
"name": "Bellevue",
"en_name": "Bellevue, WA"
}
}
]
}
}`
return &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewBufferString(body)),
Header: make(http.Header),
}
}
if strings.Contains(r.URL.Path, "/job/posts/7198234123") {
body := `{
"code": 0,
"data": {
"job_post": {
"id": "7198234123",
"title": "Software Engineer - Distributed Storage (Seattle/Bellevue)",
"description": "<p>Build high-throughput storage engines for TikTok recommendation algorithms.</p>",
"requirement": "<li>BS/MS/PhD in CS and 3+ years experience with C++/Go.</li>",
"city_info": {
"en_name": "Bellevue, 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 := NewByteDanceCrawlerWithClient(mockClient)
if !c.CanHandle("bytedance") || !c.CanHandle("tiktok") {
t.Errorf("CanHandle should support bytedance and tiktok")
}
discovered, err := c.DiscoverJobs(context.Background(), "https://jobs.bytedance.com/api/v1/search/job/posts?keyword=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 != "bytedance:7198234123" {
t.Errorf("unexpected canonical ID: %s", discovered[0].CanonicalID)
}
extracted, err := c.FetchJobDetail(context.Background(), "https://jobs.bytedance.com/en/position/7198234123/detail")
if err != nil {
t.Fatalf("FetchJobDetail failed: %v", err)
}
if extracted.Title != "Software Engineer - Distributed Storage (Seattle/Bellevue)" {
t.Errorf("unexpected title: %s", extracted.Title)
}
if extracted.Company != "ByteDance" {
t.Errorf("unexpected company: %s", extracted.Company)
}
if extracted.Location != "Bellevue, WA" {
t.Errorf("unexpected location: %s", extracted.Location)
}
}
func TestByteDanceCrawler_LiveIntegration(t *testing.T) {
crawlertest.RunLiveIntegration(t, crawlertest.LiveTestConfig{
PlatformName: "ByteDance",
Crawler: NewByteDanceCrawler(),
TargetURL: "https://jobs.bytedance.com/api/v1/search/job/posts?keyword=Software+Engineer",
ExpectedCanonicalPrefix: "bytedance:",
ExpectedCompany: "ByteDance",
})
}