mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-24 15:49:39 +02:00
CSV Imports Overhaul (Transactions, Trades, Accounts, and Mint import support) (#1209)
* Remove stale 1.0 import logic and model * Fresh start * Checkpoint before removing nav * First working prototype * Add trade, account, and mint import flows * Basic working version with tests * System tests for each import type * Clean up mappings flow * Clean up PR, refactor stale code, tests * Add back row validations * Row validations * Fix import job test * Fix import navigation * Fix mint import configuration form * Currency preset for new accounts
This commit is contained in:
parent
23786b444a
commit
398b246965
103 changed files with 2420 additions and 1689 deletions
|
@ -1,170 +1,157 @@
|
|||
require "application_system_test_case"
|
||||
|
||||
class ImportsTest < ApplicationSystemTestCase
|
||||
include ImportTestHelper
|
||||
include ActiveJob::TestHelper
|
||||
|
||||
setup do
|
||||
sign_in @user = users(:family_admin)
|
||||
|
||||
@imports = @user.family.imports.ordered.to_a
|
||||
end
|
||||
|
||||
test "can trigger new import from settings" do
|
||||
trigger_import_from_settings
|
||||
verify_import_modal
|
||||
test "transaction import" do
|
||||
visit new_import_path
|
||||
|
||||
click_on "Import transactions"
|
||||
|
||||
fill_in "import[raw_file_str]", with: file_fixture("imports/transactions.csv").read
|
||||
|
||||
find('input[type="submit"][value="Upload CSV"]').click
|
||||
|
||||
select "Date", from: "Date"
|
||||
select "YYYY-MM-DD", from: "Date format"
|
||||
select "Amount", from: "Amount"
|
||||
select "Account", from: "Account (optional)"
|
||||
select "Name", from: "Name (optional)"
|
||||
select "Category", from: "Category (optional)"
|
||||
select "Tags", from: "Tags (optional)"
|
||||
select "Notes", from: "Notes (optional)"
|
||||
|
||||
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 "can resume existing import from settings" do
|
||||
visit imports_url
|
||||
test "trade import" do
|
||||
visit new_import_path
|
||||
|
||||
within "#" + dom_id(@imports.first) do
|
||||
click_button
|
||||
click_link "Edit"
|
||||
end
|
||||
click_on "Import investments"
|
||||
|
||||
assert_current_path edit_import_path(@imports.first)
|
||||
fill_in "import[raw_file_str]", with: file_fixture("imports/trades.csv").read
|
||||
|
||||
find('input[type="submit"][value="Upload CSV"]').click
|
||||
|
||||
select "YYYY-MM-DD", from: "Date format"
|
||||
|
||||
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 "can resume latest import" do
|
||||
trigger_import_from_transactions
|
||||
verify_import_modal
|
||||
test "account import" do
|
||||
visit new_import_path
|
||||
|
||||
click_link "Resume latest import"
|
||||
click_on "Import accounts"
|
||||
|
||||
assert_current_path edit_import_path(@imports.first)
|
||||
end
|
||||
fill_in "import[raw_file_str]", with: file_fixture("imports/accounts.csv").read
|
||||
|
||||
test "can perform basic CSV import" do
|
||||
trigger_import_from_settings
|
||||
verify_import_modal
|
||||
find('input[type="submit"][value="Upload CSV"]').click
|
||||
|
||||
within "#modal" do
|
||||
click_link "New import from CSV"
|
||||
end
|
||||
click_on "Apply configuration"
|
||||
|
||||
# 1) Create import step
|
||||
assert_selector "h1", text: "New import"
|
||||
click_on "Next step"
|
||||
|
||||
within "form" do
|
||||
select "Checking Account", from: "import_account_id"
|
||||
end
|
||||
assert_selector "h1", text: "Assign your account types"
|
||||
|
||||
click_button "Next"
|
||||
|
||||
click_button "Copy & Paste"
|
||||
|
||||
# 2) Load Step
|
||||
assert_selector "h1", text: "Load import"
|
||||
|
||||
within "form" do
|
||||
fill_in "import_raw_file_str", with: <<-ROWS
|
||||
date,Custom Name Column,category,amount
|
||||
invalid_date,Starbucks drink,Food,-20.50
|
||||
2024-01-01,Amazon purchase,Shopping,-89.50
|
||||
ROWS
|
||||
end
|
||||
|
||||
click_button "Next"
|
||||
|
||||
# 3) Configure step
|
||||
assert_selector "h1", text: "Configure import"
|
||||
|
||||
within "form" do
|
||||
select "Custom Name Column", from: "import_column_mappings_name"
|
||||
end
|
||||
|
||||
click_button "Next"
|
||||
|
||||
# 4) Clean step
|
||||
assert_selector "h1", text: "Clean import"
|
||||
|
||||
# We have an invalid value, so user cannot click next yet
|
||||
assert_no_text "Next"
|
||||
|
||||
# Replace invalid date with valid date
|
||||
fill_in "cell-0-0", with: "2024-01-02"
|
||||
|
||||
# Trigger blur event so value saves
|
||||
find("body").click
|
||||
|
||||
click_link "Next"
|
||||
|
||||
# 5) Confirm step
|
||||
assert_selector "h1", text: "Confirm import"
|
||||
assert_selector "#new_account_entry", count: 2
|
||||
click_button "Import 2 transactions"
|
||||
assert_selector "h1", text: "Imports"
|
||||
end
|
||||
|
||||
test "can perform import by CSV upload" do
|
||||
trigger_import_from_settings
|
||||
verify_import_modal
|
||||
|
||||
within "#modal" do
|
||||
click_link "New import from CSV"
|
||||
end
|
||||
|
||||
# 1) Create import step
|
||||
assert_selector "h1", text: "New import"
|
||||
|
||||
within "form" do
|
||||
select "Checking Account", from: "import_account_id"
|
||||
end
|
||||
|
||||
click_button "Next"
|
||||
|
||||
click_button "Upload CSV"
|
||||
|
||||
find(".raw-file-drop-box").drop File.join(file_fixture_path, "transactions.csv")
|
||||
assert_selector "div.csv-preview", text: "transactions.csv"
|
||||
|
||||
click_button "Next"
|
||||
|
||||
# 3) Configure step
|
||||
assert_selector "h1", text: "Configure import"
|
||||
|
||||
within "form" do
|
||||
select "Custom Name Column", from: "import_column_mappings_name"
|
||||
end
|
||||
|
||||
click_button "Next"
|
||||
|
||||
# 4) Clean step
|
||||
assert_selector "h1", text: "Clean import"
|
||||
|
||||
# We have an invalid value, so user cannot click next yet
|
||||
assert_no_text "Next"
|
||||
|
||||
# Replace invalid date with valid date
|
||||
fill_in "cell-0-0", with: "2024-01-02"
|
||||
|
||||
# Trigger blur event so value saves
|
||||
find("body").click
|
||||
|
||||
click_link "Next"
|
||||
|
||||
# 5) Confirm step
|
||||
assert_selector "h1", text: "Confirm import"
|
||||
assert_selector "#new_account_entry", count: 2
|
||||
click_button "Import 2 transactions"
|
||||
assert_selector "h1", text: "Imports"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def trigger_import_from_settings
|
||||
visit imports_url
|
||||
click_link "New import"
|
||||
end
|
||||
|
||||
def trigger_import_from_transactions
|
||||
visit transactions_url
|
||||
click_link "Import"
|
||||
end
|
||||
|
||||
def verify_import_modal
|
||||
within "#modal" do
|
||||
assert_text "Import transactions"
|
||||
all("form").each do |form|
|
||||
within(form) do
|
||||
select = form.find("select")
|
||||
select "Depository", from: select["id"]
|
||||
sleep 1
|
||||
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
|
||||
|
||||
click_on "Import from Mint"
|
||||
|
||||
fill_in "import[raw_file_str]", with: file_fixture("imports/mint.csv").read
|
||||
|
||||
find('input[type="submit"][value="Upload CSV"]').click
|
||||
|
||||
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
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue