mirror of
https://github.com/we-promise/sure.git
synced 2026-05-07 12:54:04 +00:00
fix(imports): preserve account status from backups (#1603)
This commit is contained in:
@@ -92,7 +92,7 @@ class Family::DataImporter
|
||||
institution_name: data["institution_name"],
|
||||
institution_domain: data["institution_domain"],
|
||||
notes: data["notes"],
|
||||
status: "active"
|
||||
status: importable_account_status(data["status"])
|
||||
)
|
||||
|
||||
account.save!
|
||||
@@ -108,6 +108,10 @@ class Family::DataImporter
|
||||
end
|
||||
end
|
||||
|
||||
def importable_account_status(status)
|
||||
status.to_s.in?(%w[active disabled draft]) ? status.to_s : "active"
|
||||
end
|
||||
|
||||
def import_categories(records)
|
||||
# First pass: create all categories without parent relationships
|
||||
parent_mappings = {}
|
||||
|
||||
@@ -31,6 +31,52 @@ class Family::DataImporterTest < ActiveSupport::TestCase
|
||||
assert_equal "Depository", account.accountable_type
|
||||
end
|
||||
|
||||
test "imports non-destructive account status from ndjson" do
|
||||
ndjson = build_ndjson([
|
||||
{
|
||||
type: "Account",
|
||||
data: {
|
||||
id: "disabled-account",
|
||||
name: "Closed Checking",
|
||||
balance: "0.00",
|
||||
currency: "USD",
|
||||
accountable_type: "Depository",
|
||||
status: "disabled"
|
||||
}
|
||||
}
|
||||
])
|
||||
|
||||
importer = Family::DataImporter.new(@family, ndjson)
|
||||
result = importer.import!
|
||||
|
||||
account = result[:accounts].first
|
||||
assert_equal "Closed Checking", account.name
|
||||
assert_equal "disabled", account.status
|
||||
end
|
||||
|
||||
test "does not import pending deletion account status" do
|
||||
ndjson = build_ndjson([
|
||||
{
|
||||
type: "Account",
|
||||
data: {
|
||||
id: "pending-delete-account",
|
||||
name: "Pending Delete Checking",
|
||||
balance: "0.00",
|
||||
currency: "USD",
|
||||
accountable_type: "Depository",
|
||||
status: "pending_deletion"
|
||||
}
|
||||
}
|
||||
])
|
||||
|
||||
importer = Family::DataImporter.new(@family, ndjson)
|
||||
result = importer.import!
|
||||
|
||||
account = result[:accounts].first
|
||||
assert_equal "Pending Delete Checking", account.name
|
||||
assert_equal "active", account.status
|
||||
end
|
||||
|
||||
test "imports categories with parent relationships" do
|
||||
ndjson = build_ndjson([
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user