chore: Contact import improvements (CW-1362) (#6747)

Fixes: https://linear.app/chatwoot/issue/CW-1362/csv-imports-are-not-working-properly
Fixes: #3462

---------

Co-authored-by: Sojan <sojan@pepalo.com>
This commit is contained in:
Tejaswini Chile
2023-04-18 00:40:55 +05:30
committed by GitHub
parent 4505c5dda3
commit 905e77048f
9 changed files with 256 additions and 50 deletions

View File

@@ -0,0 +1,18 @@
module CsvSpecHelpers
# Generates a Rack::Test::UploadedFile object from an array of arrays
# data: Accepts an array of arrays as the only argument
def generate_csv_file(data)
# Create a temporary file
temp_file = Tempfile.new(['data', '.csv'])
# Write the array of arrays to the temporary file as CSV
CSV.open(temp_file.path, 'wb') do |csv|
data.each do |row|
csv << row
end
end
# Create and return a Rack::Test::UploadedFile object
Rack::Test::UploadedFile.new(temp_file.path, 'text/csv')
end
end