feat(contacts): index imported contacts
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user