Files
creator-hub/internal/platform/douyin/share_test.go
T

34 lines
1.2 KiB
Go

package douyin
import "testing"
func TestParseShareTargetHTML(t *testing.T) {
body := []byte(`<script>window._ROUTER_DATA = {
"loaderData": {"video_(id)/page": {"videoInfoRes": {"item_list": [{
"aweme_id": "7667952980074745151",
"author": {
"uid": "123456789",
"sec_uid": "MS4wLjABAAAAexample",
"unique_id": "muzi_code",
"nickname": "木子不写代码",
"avatar_thumb": {"url_list": ["https://example.com/avatar.jpg"]}
}
}]}}}
};</script>`)
profile, ok := ParseShareTargetHTML(body, "7667952980074745151")
if !ok {
t.Fatal("expected share author to parse")
}
if profile.SecUID != "MS4wLjABAAAAexample" || profile.UniqueID != "muzi_code" ||
profile.Nickname != "木子不写代码" || profile.AvatarURL != "https://example.com/avatar.jpg" {
t.Fatalf("unexpected share profile: %+v", profile)
}
}
func TestParseShareTargetHTMLRejectsWrongWork(t *testing.T) {
body := []byte(`<script>window._ROUTER_DATA = {"loaderData":{"video_(id)/page":{"videoInfoRes":{"item_list":[{"aweme_id":"1","author":{"sec_uid":"MS4wLjABAAAAexample"}}]}}}};</script>`)
if _, ok := ParseShareTargetHTML(body, "2"); ok {
t.Fatal("accepted a mismatched work id")
}
}