chore: Map country column during CSV import

This commit is contained in:
iamsivin
2026-05-08 12:37:10 +05:30
parent 53b2a517d7
commit cbc32f38d3
3 changed files with 60 additions and 28 deletions
+26
View File
@@ -188,6 +188,32 @@ RSpec.describe DataImportJob do
end
end
context 'when the data contains country column' do
let(:data_with_country) do
[
%w[id name email phone_number country],
['1', 'John Doe', 'john-country@example.com', '+918080808081', 'United States'],
['2', 'Jane Smith', 'jane-country@example.com', '+918080808082', 'India'],
['3', 'Bob Wilson', 'bob-country@example.com', '+918080808083', '']
]
end
let(:country_data_import) { create(:data_import, import_file: generate_csv_file(data_with_country)) }
it 'maps the country column to the standard country_code field' do
described_class.perform_now(country_data_import)
john = Contact.from_email('john-country@example.com')
expect(john.country_code).to eq('United States')
expect(john.additional_attributes['country']).to eq('United States')
jane = Contact.from_email('jane-country@example.com')
expect(jane.country_code).to eq('India')
bob = Contact.from_email('bob-country@example.com')
expect(bob.country_code).to eq('')
end
end
context 'when the data contains labels column' do
let(:data_with_labels) do
[