Files
creator-hub/internal/controlplane/api/creator_share_test.go
T

63 lines
1.8 KiB
Go

package api
import (
"testing"
"git.ipao.vip/rogee/creator-hub/internal/creator"
)
func TestCompetitorSharePlatform(t *testing.T) {
for _, test := range []struct {
name string
url string
want string
}{
{name: "douyin short link", url: "https://v.douyin.com/abc123/", want: creator.PlatformDouyin},
{name: "douyin content", url: "https://www.douyin.com/video/123", want: creator.PlatformDouyin},
{name: "xiaohongshu note", url: "https://www.xiaohongshu.com/explore/note-1", want: creator.PlatformXiaohongshu},
} {
t.Run(test.name, func(t *testing.T) {
got, err := competitorSharePlatform(test.url)
if err != nil || got != test.want {
t.Fatalf("competitorSharePlatform(%q) = %q, %v; want %q", test.url, got, err, test.want)
}
})
}
for _, url := range []string{
"http://v.douyin.com/abc123/",
"https://www.douyin.com.evil/video/123",
"https://v.douyin.com/abc123/#fragment",
} {
t.Run(url, func(t *testing.T) {
if _, err := competitorSharePlatform(url); err == nil {
t.Fatalf("competitorSharePlatform(%q) unexpectedly succeeded", url)
}
})
}
}
func TestDouyinWorkKeyFromURL(t *testing.T) {
for _, test := range []struct {
url string
want string
}{
{url: "https://www.douyin.com/video/123", want: "123"},
{url: "https://www.douyin.com/video/123?previous_page=app_code_link", want: "123"},
} {
got, err := douyinWorkKeyFromURL(test.url)
if err != nil || got != test.want {
t.Fatalf("douyinWorkKeyFromURL(%q) = %q, %v; want %q", test.url, got, err, test.want)
}
}
for _, url := range []string{
"https://www.douyin.com/video/0",
"https://www.douyin.com/user/123",
"https://v.douyin.com/abc123",
} {
if _, err := douyinWorkKeyFromURL(url); err == nil {
t.Fatalf("douyinWorkKeyFromURL(%q) unexpectedly succeeded", url)
}
}
}