feat(contacts): index imported contacts

This commit is contained in:
2026-06-07 05:51:07 +08:00
parent 7b232ce850
commit 6df3fead53
3 changed files with 16 additions and 4 deletions
+2
View File
@@ -1167,6 +1167,7 @@ func (s *ContactService) ImportCSV(ctx context.Context, accountID uint, r io.Rea
result.Failed++
continue
}
s.indexContact(ctx, existing)
result.Imported++
continue
}
@@ -1184,6 +1185,7 @@ func (s *ContactService) ImportCSV(ctx context.Context, accountID uint, r io.Rea
result.Failed++
continue
}
s.indexContact(ctx, contact)
result.Imported++
}
@@ -420,6 +420,8 @@ func TestContactService_ExportContacts_FiltersByLabelAndColumns(t *testing.T) {
func TestContactService_ImportCSV_ImportsValidRows(t *testing.T) {
db, _, svc := setupContactService(t)
indexer := &mockServiceSearchIndexer{}
svc.SetSearchIndexer(indexer)
account := createTestAccount(t, db)
csvData := "name,email,phone_number\nAlice,alice@test.com,+111\nBob,bob@test.com,+222\n"
@@ -433,6 +435,7 @@ func TestContactService_ImportCSV_ImportsValidRows(t *testing.T) {
var count int64
db.Model(&model.Contact{}).Where("account_id = ?", account.ID).Count(&count)
assert.Equal(t, int64(2), count)
assert.Equal(t, []string{"contact", "contact"}, indexer.indexed)
}
func TestContactService_ImportCSV_AllowsRowsWithoutNameWhenIdentityPresent(t *testing.T) {
@@ -449,6 +452,8 @@ func TestContactService_ImportCSV_AllowsRowsWithoutNameWhenIdentityPresent(t *te
func TestContactService_ImportCSV_MergesDuplicateEmail(t *testing.T) {
db, _, svc := setupContactService(t)
indexer := &mockServiceSearchIndexer{}
svc.SetSearchIndexer(indexer)
account := createTestAccount(t, db)
// Pre-create a contact with the same email
@@ -470,6 +475,7 @@ func TestContactService_ImportCSV_MergesDuplicateEmail(t *testing.T) {
var count int64
db.Model(&model.Contact{}).Where("account_id = ?", account.ID).Count(&count)
assert.Equal(t, int64(2), count)
assert.Equal(t, []string{"contact", "contact"}, indexer.indexed)
}
func TestContactService_ImportContacts_CreatesCompletedDataImport(t *testing.T) {