Files
sure/test/system/imports_test.rb
ghost 6ea931f3fe feat(imports): add YNAB CSV import (#2361)
Adds YnabImport (mirroring ActualImport) for YNAB "Export budget" register CSVs:

- Amount — combines the split Outflow/Inflow columns into a single signed amount
  (inflow - |outflow|), stripping currency symbols and thousands separators. A
  single signed Amount column takes precedence when present.
- Category — resolves across export shapes: the combined "Category Group/Category"
  column, the split "Category Group" + "Category", or legacy YNAB 4
  "Master Category" + "Sub Category".
- Names — falls back from a blank Payee to the Memo, then the default row name.
- Validation — requires at least one amount source (Outflow/Inflow or Amount); a
  file exposing none leaves rows un-clean instead of importing zero-dollar entries.

Enables the previously-disabled YNAB option on the imports screen (using the YNAB
logo, like Mint) with its configuration partial, and removes the now-dead
imports.new.coming_soon locale key. Documents the type in the API import-type
enums (rswag request spec + swagger_helper + generated openapi.yaml).

Closes #1255.
2026-06-16 08:32:17 +02:00

267 lines
6.3 KiB
Ruby

require "application_system_test_case"
class ImportsTest < ApplicationSystemTestCase
include ActiveJob::TestHelper
setup do
sign_in @user = users(:family_admin)
# Trade securities will be imported as "offline" tickers
Security.stubs(:provider).returns(nil)
end
test "transaction import" do
visit new_import_path
click_on "Raw Data"
click_on "Import transactions"
within_testid("import-tabs") do
click_on "Copy & Paste"
end
fill_in "import[raw_file_str]", with: file_fixture("imports/transactions.csv").read
find_field("import[raw_file_str]").find(:xpath, "./ancestor::form").click_button("Upload CSV")
select "Date", from: "import[date_col_label]"
select "YYYY-MM-DD", from: "import[date_format]"
select "Amount", from: "import[amount_col_label]"
select "Account", from: "import[account_col_label]"
select "Name", from: "import[name_col_label]"
select "Category", from: "import[category_col_label]"
select "Tags", from: "import[tags_col_label]"
select "Notes", from: "import[notes_col_label]"
click_on "Apply configuration"
click_on "Next step"
assert_selector "h1", text: "Assign your categories"
click_on "Next"
assert_selector "h1", text: "Assign your tags"
click_on "Next"
assert_selector "h1", text: "Assign your accounts"
click_on "Next"
click_on "Publish import"
assert_text "Import in progress"
perform_enqueued_jobs
click_on "Check status"
assert_text "Import successful"
click_on "Back to dashboard"
end
test "trade import" do
visit new_import_path
click_on "Raw Data"
click_on "Import investments"
within_testid("import-tabs") do
click_on "Copy & Paste"
end
fill_in "import[raw_file_str]", with: file_fixture("imports/trades.csv").read
find_field("import[raw_file_str]").find(:xpath, "./ancestor::form").click_button("Upload CSV")
select "date", from: "import[date_col_label]"
select "YYYY-MM-DD", from: "import[date_format]"
select "qty", from: "import[qty_col_label]"
select "ticker", from: "import[ticker_col_label]"
select "price", from: "import[price_col_label]"
select "account", from: "import[account_col_label]"
click_on "Apply configuration"
click_on "Next step"
assert_selector "h1", text: "Assign your accounts"
click_on "Next"
click_on "Publish import"
assert_text "Import in progress"
perform_enqueued_jobs
click_on "Check status"
assert_text "Import successful"
click_on "Back to dashboard"
end
test "account import" do
visit new_import_path
click_on "Raw Data"
click_on "Import accounts"
within_testid("import-tabs") do
click_on "Copy & Paste"
end
fill_in "import[raw_file_str]", with: file_fixture("imports/accounts.csv").read
find_field("import[raw_file_str]").find(:xpath, "./ancestor::form").click_button("Upload CSV")
select "type", from: "import[entity_type_col_label]"
select "name", from: "import[name_col_label]"
select "amount", from: "import[amount_col_label]"
click_on "Apply configuration"
click_on "Next step"
assert_selector "h1", text: "Assign your account types"
all("form").each do |form|
within(form) do
select = form.find("select")
select "Depository", from: select["id"]
sleep 0.5
end
end
click_on "Next"
click_on "Publish import"
assert_text "Import in progress"
perform_enqueued_jobs
click_on "Check status"
assert_text "Import successful"
click_on "Back to dashboard"
end
test "mint import" do
visit new_import_path
# Pending CSV-style imports default the dialog to the Raw Data tab; Mint lives under Financial Tools.
click_on "Financial Tools"
click_on "Import from Mint"
within_testid("import-tabs") do
click_on "Copy & Paste"
end
fill_in "import[raw_file_str]", with: file_fixture("imports/mint.csv").read
find_field("import[raw_file_str]").find(:xpath, "./ancestor::form").click_button("Upload CSV")
click_on "Apply configuration"
click_on "Next step"
assert_selector "h1", text: "Assign your categories"
click_on "Next"
assert_selector "h1", text: "Assign your tags"
click_on "Next"
assert_selector "h1", text: "Assign your accounts"
click_on "Next"
click_on "Publish import"
assert_text "Import in progress"
perform_enqueued_jobs
click_on "Check status"
assert_text "Import successful"
click_on "Back to dashboard"
end
test "actual import" do
visit new_import_path
# Pending CSV-style imports default the dialog to the Raw Data tab; Actual lives under Financial Tools.
click_on "Financial Tools"
click_on "Import from Actual Budget"
within_testid("import-tabs") do
click_on "Copy & Paste"
end
fill_in "import[raw_file_str]", with: file_fixture("imports/actual.csv").read
find_field("import[raw_file_str]").find(:xpath, "./ancestor::form").click_button("Upload CSV")
click_on "Apply configuration"
click_on "Next step"
assert_selector "h1", text: "Assign your categories"
click_on "Next"
assert_selector "h1", text: "Assign your accounts"
click_on "Next"
click_on "Publish import"
assert_text "Import in progress"
perform_enqueued_jobs
click_on "Check status"
assert_text "Import successful"
click_on "Back to dashboard"
end
test "ynab import" do
visit new_import_path
# Pending CSV-style imports default the dialog to the Raw Data tab; YNAB lives under Financial Tools.
click_on "Financial Tools"
click_on "Import from YNAB"
within_testid("import-tabs") do
click_on "Copy & Paste"
end
fill_in "import[raw_file_str]", with: file_fixture("imports/ynab.csv").read
find_field("import[raw_file_str]").find(:xpath, "./ancestor::form").click_button("Upload CSV")
click_on "Apply configuration"
click_on "Next step"
assert_selector "h1", text: "Assign your categories"
click_on "Next"
assert_selector "h1", text: "Assign your accounts"
click_on "Next"
click_on "Publish import"
assert_text "Import in progress"
perform_enqueued_jobs
click_on "Check status"
assert_text "Import successful"
click_on "Back to dashboard"
end
end