Add test got the import job

This commit is contained in:
Stanko K.R.
2026-02-02 13:03:26 +01:00
parent ccbf571be4
commit a6609e1bbc
2 changed files with 34 additions and 8 deletions
+4 -8
View File
@@ -4,20 +4,16 @@ class ImportAccountDataJob < ApplicationJob
queue_as :backend
def perform(import)
step :check do
step :check do |step|
import.check \
start: step.cursor,
callback: proc do |record_set:, file:|
step.set!([ record_set.model.name, file ])
end
callback: ->(record_set:, file:) { step.set!([ record_set.model.name, file ]) }
end
step :process do
step :process do |step|
import.process \
start: step.cursor,
callback: proc do |record_set:, files:|
step.set!([ record_set.model.name, files.last ])
end
callback: ->(record_set:, files:) { step.set!([ record_set.model.name, files.last ]) }
end
end
end
+30
View File
@@ -0,0 +1,30 @@
require "test_helper"
class ImportAccountDataJobTest < ActiveJob::TestCase
test "performs import via continuable steps" do
source_account = accounts("37s")
exporter = users(:david)
identity = exporter.identity
export = Account::Export.create!(account: source_account, user: exporter)
export.build
export_tempfile = Tempfile.new([ "export", ".zip" ])
export.file.open { |f| FileUtils.cp(f.path, export_tempfile.path) }
source_account.destroy!
target_account = Account.create_with_owner(account: { name: "Import Test" }, owner: { identity: identity, name: exporter.name })
import = Account::Import.create!(identity: identity, account: target_account)
Current.set(account: target_account) do
import.file.attach(io: File.open(export_tempfile.path), filename: "export.zip", content_type: "application/zip")
end
ImportAccountDataJob.perform_now(import)
assert import.reload.completed?
ensure
export_tempfile&.close
export_tempfile&.unlink
end
end