mirror of
https://github.com/we-promise/sure.git
synced 2026-04-09 07:14:47 +00:00
* Reorganize import UI with Financial Tools / Raw Data tabs Split the flat list of import sources into two tabbed sections using DS::Tabs: "Financial Tools" (Mint, Quicken/QIF, YNAB coming soon) and "Raw Data" (transactions, investments, accounts, categories, rules, documents). This prepares for adding more tool-specific importers without cluttering the list. https://claude.ai/code/session_01BM4SBWNhATqoKTEvy3qTS3 * Fix import controller test to account for YNAB coming soon entry The new YNAB "coming soon" disabled entry adds a 5th aria-disabled element to the import dialog. https://claude.ai/code/session_01BM4SBWNhATqoKTEvy3qTS3 * Fix system tests to click Raw Data tab before selecting import type Transaction, trade, and account imports are now under the Raw Data tab and need an explicit tab click before the buttons are visible. https://claude.ai/code/session_01BM4SBWNhATqoKTEvy3qTS3 * feat: Add bulk import for NDJSON export files Implements an import flow that accepts the full all.ndjson file from data exports, allowing users to restore their complete data including: - Accounts with accountable types - Categories with parent relationships - Tags and merchants - Transactions with category, merchant, and tag references - Trades with securities - Valuations - Budgets and budget categories - Rules with conditions and actions (including compound conditions) Key changes: - Add BulkImport model extending Import base class - Add Family::DataImporter to handle NDJSON parsing and import logic - Update imports controller and views to support NDJSON workflow - Skip configuration/mapping steps for structured NDJSON imports - Add i18n translations for bulk import UI - Add tests for BulkImport and DataImporter * fix: Fix category import and test query issues - Add default lucide_icon ("shapes") for categories when not provided - Fix valuation test to use proper ActiveRecord joins syntax * Linter errors * fix: Add default color for tags when not provided in import * fix: Add default kind for transactions when not provided in import * Fix test * Fix tests * Fix remaining merge conflicts from PR 766 cherry-pick Resolve conflict markers in test fixtures and clean up BulkImport entry in new.html.erb to use the _import_option partial consistently. https://claude.ai/code/session_01BM4SBWNhATqoKTEvy3qTS3 * Import Sure `.ndjson` * Remove `.ndjson` import from raw data * Fix support for Sure "bulk" import from old branch * Linter * Fix CI test * Fix more CI tests * Fix tests * Fix tests / move PDF import to first tab * Remove redundant title --------- Co-authored-by: Claude <noreply@anthropic.com>
139 lines
4.0 KiB
Ruby
139 lines
4.0 KiB
Ruby
require "test_helper"
|
|
|
|
class ImportsControllerTest < ActionDispatch::IntegrationTest
|
|
setup do
|
|
sign_in @user = users(:family_admin)
|
|
end
|
|
|
|
test "gets index" do
|
|
get imports_url
|
|
|
|
assert_response :success
|
|
|
|
@user.family.imports.ordered.each do |import|
|
|
assert_select "#" + dom_id(import), count: 1
|
|
end
|
|
end
|
|
|
|
test "gets new" do
|
|
get new_import_url
|
|
|
|
assert_response :success
|
|
|
|
assert_select "turbo-frame#modal"
|
|
end
|
|
|
|
test "shows disabled account-dependent imports when family has no accounts" do
|
|
sign_in users(:empty)
|
|
|
|
get new_import_url
|
|
|
|
assert_response :success
|
|
assert_select "button", text: "Import accounts"
|
|
assert_select "button", text: "Import transactions", count: 0
|
|
assert_select "button", text: "Import investments", count: 0
|
|
assert_select "button", text: "Import from Mint", count: 1
|
|
assert_select "button", text: "Import from Quicken (QIF)", count: 1
|
|
assert_select "span", text: "Import accounts first to unlock this option.", count: 2
|
|
assert_select "div[aria-disabled=true]", count: 3
|
|
end
|
|
|
|
test "creates import" do
|
|
assert_difference "Import.count", 1 do
|
|
post imports_url, params: {
|
|
import: {
|
|
type: "TransactionImport"
|
|
}
|
|
}
|
|
end
|
|
|
|
assert_redirected_to import_upload_url(Import.all.ordered.first)
|
|
end
|
|
|
|
test "uploads supported non-pdf document for vector store without creating import" do
|
|
adapter = mock("vector_store_adapter")
|
|
adapter.stubs(:supported_extensions).returns(%w[.csv .pdf])
|
|
VectorStore::Registry.stubs(:adapter).returns(adapter)
|
|
|
|
family_document = family_documents(:tax_return)
|
|
Family.any_instance.expects(:upload_document).with do |file_content:, filename:, **|
|
|
assert_not_empty file_content
|
|
assert_equal "valid.csv", filename
|
|
true
|
|
end.returns(family_document)
|
|
|
|
assert_no_difference "Import.count" do
|
|
post imports_url, params: {
|
|
import: {
|
|
type: "DocumentImport",
|
|
import_file: file_fixture_upload("imports/valid.csv", "text/csv")
|
|
}
|
|
}
|
|
end
|
|
|
|
assert_redirected_to new_import_url
|
|
assert_equal I18n.t("imports.create.document_uploaded"), flash[:notice]
|
|
end
|
|
|
|
test "uploads pdf document as PdfImport when using DocumentImport option" do
|
|
adapter = mock("vector_store_adapter")
|
|
adapter.stubs(:supported_extensions).returns(%w[.pdf .txt])
|
|
VectorStore::Registry.stubs(:adapter).returns(adapter)
|
|
|
|
@user.family.expects(:upload_document).never
|
|
|
|
assert_difference "Import.count", 1 do
|
|
post imports_url, params: {
|
|
import: {
|
|
type: "DocumentImport",
|
|
import_file: file_fixture_upload("imports/sample_bank_statement.pdf", "application/pdf")
|
|
}
|
|
}
|
|
end
|
|
|
|
created_import = Import.order(:created_at).last
|
|
assert_equal "PdfImport", created_import.type
|
|
assert_redirected_to import_url(created_import)
|
|
assert_equal I18n.t("imports.create.pdf_processing"), flash[:notice]
|
|
end
|
|
|
|
test "rejects unsupported document type for DocumentImport option" do
|
|
adapter = mock("vector_store_adapter")
|
|
adapter.stubs(:supported_extensions).returns(%w[.pdf .txt])
|
|
VectorStore::Registry.stubs(:adapter).returns(adapter)
|
|
|
|
assert_no_difference "Import.count" do
|
|
post imports_url, params: {
|
|
import: {
|
|
type: "DocumentImport",
|
|
import_file: file_fixture_upload("profile_image.png", "image/png")
|
|
}
|
|
}
|
|
end
|
|
|
|
assert_redirected_to new_import_url
|
|
assert_equal I18n.t("imports.create.invalid_document_file_type"), flash[:alert]
|
|
end
|
|
|
|
test "publishes import" do
|
|
import = imports(:transaction)
|
|
|
|
TransactionImport.any_instance.expects(:publish_later).once
|
|
|
|
post publish_import_url(import)
|
|
|
|
assert_equal "Your import has started in the background.", flash[:notice]
|
|
assert_redirected_to import_path(import)
|
|
end
|
|
|
|
test "destroys import" do
|
|
import = imports(:transaction)
|
|
|
|
assert_difference "Import.count", -1 do
|
|
delete import_url(import)
|
|
end
|
|
|
|
assert_redirected_to imports_path
|
|
end
|
|
end
|