mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-03-03 11:13:06 +08:00
Fix test for repository ZIP export & return path for ZIP exports [SCI-2646]
This commit is contained in:
parent
ee611a45d9
commit
8fe0249f45
4 changed files with 17 additions and 6 deletions
|
@ -34,6 +34,8 @@ class TeamZipExport < ZipExport
|
|||
FileUtils.rm_rf([dir_to_zip, output_file], secure: true)
|
||||
generate_notification(user)
|
||||
end
|
||||
|
||||
zip_file.path
|
||||
end
|
||||
|
||||
handle_asynchronously :generate_exportable_zip
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'zip'
|
||||
require 'fileutils'
|
||||
require 'csv'
|
||||
|
@ -62,6 +64,8 @@ class ZipExport < ApplicationRecord
|
|||
FileUtils.rm_rf([dir_to_zip, output_file], secure: true)
|
||||
generate_notification(user)
|
||||
end
|
||||
|
||||
zip_file.path
|
||||
end
|
||||
|
||||
handle_asynchronously :generate_exportable_zip
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'csv'
|
||||
|
||||
module RepositoryZipExport
|
||||
def self.generate_zip(params, repository, current_user)
|
||||
# Fetch rows in the same order as in the currently viewed datatable
|
||||
|
|
|
@ -64,13 +64,15 @@ describe RepositoryZipExport, type: :background_job do
|
|||
end
|
||||
|
||||
it 'generates a zip with csv file with exported rows' do
|
||||
RepositoryZipExport.generate_zip(params, repository, user)
|
||||
zip = ZipExport.first.zip_file_file_name
|
||||
.gsub('export-', '')
|
||||
.gsub('.zip', '')
|
||||
csv_path = Rails.root.join('tmp', "temp-zip-#{zip}", 'export.csv').to_s
|
||||
csv_zip_path = RepositoryZipExport.generate_zip(params, repository, user)
|
||||
parsed_csv_content = Zip::File.open(csv_zip_path) do |zip_file|
|
||||
csv_file = zip_file.glob('*.csv').first
|
||||
csv_content = csv_file.get_input_stream.read
|
||||
CSV.parse(csv_content, headers: true)
|
||||
end
|
||||
index = 0
|
||||
CSV.foreach(csv_path, headers: true) do |row|
|
||||
|
||||
parsed_csv_content.each do |row|
|
||||
row_hash = row.to_h
|
||||
expect(row_hash.fetch('Sample group')).to eq 'item one'
|
||||
expect(row_hash.fetch('Custom items')).to eq 'custum column value'
|
||||
|
|
Loading…
Reference in a new issue