39 lines
1.3 KiB
Go
39 lines
1.3 KiB
Go
|
|
package placement
|
||
|
|
|
||
|
|
import (
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
brandentity "haixun-backend/internal/model/brand/domain/entity"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestRecommendProductForPostPicksLaundryOverDefaultBodyWash(t *testing.T) {
|
||
|
|
products := []brandentity.Product{
|
||
|
|
{ID: "body", Label: "無香沐浴乳", MatchTags: []string{"沐浴乳", "無香", "敏感"}},
|
||
|
|
{ID: "laundry", Label: "天然洗衣精", MatchTags: []string{"洗衣精", "衣物", "污漬"}},
|
||
|
|
}
|
||
|
|
post := "最近衣服洗不乾淨,洗衣精有推薦嗎?污漬一直洗不掉"
|
||
|
|
got := RecommendProductForPost(products, "洗衣精 推薦", post, "body")
|
||
|
|
if got == nil || got.ID != "laundry" {
|
||
|
|
id := ""
|
||
|
|
if got != nil {
|
||
|
|
id = got.ID
|
||
|
|
}
|
||
|
|
t.Fatalf("expected laundry product, got %q", id)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestRecommendProductForPostPicksBodyWashForShowerPost(t *testing.T) {
|
||
|
|
products := []brandentity.Product{
|
||
|
|
{ID: "body", Label: "無香沐浴乳", MatchTags: []string{"沐浴乳", "無香", "敏感"}},
|
||
|
|
{ID: "laundry", Label: "天然洗衣精", MatchTags: []string{"洗衣精", "衣物", "污漬"}},
|
||
|
|
}
|
||
|
|
post := "化療後皮膚很乾,沐浴乳有推薦嗎?想要無香味"
|
||
|
|
got := RecommendProductForPost(products, "沐浴乳 推薦", post, "laundry")
|
||
|
|
if got == nil || got.ID != "body" {
|
||
|
|
id := ""
|
||
|
|
if got != nil {
|
||
|
|
id = got.ID
|
||
|
|
}
|
||
|
|
t.Fatalf("expected body wash product, got %q", id)
|
||
|
|
}
|
||
|
|
}
|