Files
go-onlyoffice/crm_dedupe_plan_test.go
T
eSliderandCursor b79c097874 feat(crm): dedupe duplicates, fix deal titles, and add cleanup CLI
Merge duplicate companies/persons/deals by name, remove duplicate contact
info and opportunity members, and rename malformed " @ Company" titles.
Applications sync now avoids empty-position titles and duplicate members.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-24 12:34:14 +01:00

72 lines
1.9 KiB
Go

package onlyoffice
import (
"reflect"
"testing"
)
func TestPickCanonicalID(t *testing.T) {
if got := PickCanonicalID([]int64{908, 857, 900}); got != 857 {
t.Fatalf("got %d", got)
}
if got := PickCanonicalID(nil); got != 0 {
t.Fatalf("got %d", got)
}
}
func TestGroupCompaniesByName(t *testing.T) {
items := []map[string]any{
{"id": float64(857), "displayName": "contoso", "isCompany": true},
{"id": float64(908), "displayName": "contoso", "isCompany": true},
{"id": float64(1), "displayName": "Acme", "isCompany": true},
}
groups := GroupCompaniesByName(items)
if len(groups) != 2 {
t.Fatalf("groups: %d", len(groups))
}
key := NormalizeCompanyName("contoso")
if len(groups[key]) != 2 {
t.Fatalf("contoso group: %d", len(groups[key]))
}
}
func TestDedupeMembersByDisplayName(t *testing.T) {
members := []map[string]any{
{"id": float64(857), "displayName": "contoso"},
{"id": float64(908), "displayName": "contoso"},
{"id": float64(10), "displayName": "Acme"},
}
remove := DedupeMembersByDisplayName(members)
want := []int64{908}
if !reflect.DeepEqual(remove, want) {
t.Fatalf("remove %v want %v", remove, want)
}
}
func TestDedupeMemberIDs(t *testing.T) {
remove := DedupeMemberIDs([]int64{1, 2, 2, 3, 1})
if !reflect.DeepEqual(remove, []int64{2, 1}) {
t.Fatalf("got %v", remove)
}
}
func TestGroupContactInfoRows(t *testing.T) {
rows := []map[string]any{
{"id": float64(1), "infoType": "Email", "data": "a@b.com", "isPrimary": false},
{"id": float64(2), "infoType": "Email", "data": "a@b.com", "isPrimary": true},
}
remove := GroupContactInfoRows(rows)
if len(remove) != 1 || remove[0] != 1 {
t.Fatalf("remove %v", remove)
}
}
func TestDealTitleKey(t *testing.T) {
if got := DealTitleKey("Dev @ Acme", false); got != NormalizeOpportunityTitle("Dev @ Acme") {
t.Fatalf("got %q", got)
}
if got := DealTitleKey("Dev @ Acme", true); got != NormalizeOpportunityTitle("Dev") {
t.Fatalf("got %q", got)
}
}