39 lines
1.9 KiB
Go
39 lines
1.9 KiB
Go
package isphere
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestSearchContactsFromMessagesMatchesBareJIDs(t *testing.T) {
|
|
messages := []Message{
|
|
{ID: "msg-1", SenderID: "alice@imopenfire1-lanzhou", ReceiverID: "bob@imopenfire1-lanzhou"},
|
|
{ID: "msg-2", SenderID: "alice@imopenfire1-lanzhou", ReceiverID: "carol@imopenfire1-lanzhou"},
|
|
}
|
|
|
|
got := SearchContactsFromMessages(messages, SearchContactsQuery{Query: "imopenfire1", Limit: 2})
|
|
want := SearchContactsResult{Contacts: []Contact{
|
|
{ContactID: "alice@imopenfire1-lanzhou", DisplayName: "alice@imopenfire1-lanzhou", Account: "alice@imopenfire1-lanzhou", Source: "local_readonly", Confidence: 0.6, RawRef: "message_jid"},
|
|
{ContactID: "bob@imopenfire1-lanzhou", DisplayName: "bob@imopenfire1-lanzhou", Account: "bob@imopenfire1-lanzhou", Source: "local_readonly", Confidence: 0.6, RawRef: "message_jid"},
|
|
}}
|
|
if !reflect.DeepEqual(got, want) {
|
|
t.Fatalf("SearchContactsFromMessages() = %#v, want %#v", got, want)
|
|
}
|
|
}
|
|
|
|
func TestSearchContactsRanksExactAndDeduplicates(t *testing.T) {
|
|
messages := []Message{
|
|
{ID: "msg-1", SenderID: "zzz-target@imopenfire1-lanzhou", ReceiverID: "target@imopenfire1-lanzhou"},
|
|
{ID: "msg-2", SenderID: "TARGET@imopenfire1-lanzhou", ReceiverID: "other@imopenfire1-lanzhou"},
|
|
}
|
|
|
|
got := SearchContactsFromMessages(messages, SearchContactsQuery{Query: "target@imopenfire1-lanzhou", Limit: 10})
|
|
want := SearchContactsResult{Contacts: []Contact{
|
|
{ContactID: "target@imopenfire1-lanzhou", DisplayName: "target@imopenfire1-lanzhou", Account: "target@imopenfire1-lanzhou", Source: "local_readonly", Confidence: 0.6, RawRef: "message_jid"},
|
|
{ContactID: "zzz-target@imopenfire1-lanzhou", DisplayName: "zzz-target@imopenfire1-lanzhou", Account: "zzz-target@imopenfire1-lanzhou", Source: "local_readonly", Confidence: 0.6, RawRef: "message_jid"},
|
|
}}
|
|
if !reflect.DeepEqual(got, want) {
|
|
t.Fatalf("SearchContactsFromMessages() = %#v, want %#v", got, want)
|
|
}
|
|
}
|