mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-24 15:49:39 +02:00
Fix duplicate category creation on import (#791)
* Repro * Fix * Update signage
This commit is contained in:
parent
77f166a5f8
commit
41c991384a
4 changed files with 24 additions and 12 deletions
16
test/fixtures/imports.yml
vendored
16
test/fixtures/imports.yml
vendored
|
@ -6,12 +6,16 @@ loaded_import:
|
|||
account: checking
|
||||
raw_csv_str: |
|
||||
date,name,category,amount
|
||||
2024-01-01,Starbucks drink,Food,20
|
||||
2024-01-02,Amazon stuff,Shopping,200
|
||||
2024-01-01,Starbucks drink,Food & Drink,-8.55
|
||||
2024-01-01,Etsy,Shopping,-80.98
|
||||
2024-01-02,Amazon stuff,Shopping,-200
|
||||
2024-01-03,Paycheck,Income,1000
|
||||
normalized_csv_str: |
|
||||
date,name,category,amount
|
||||
2024-01-01,Starbucks drink,Food,20
|
||||
2024-01-02,Amazon stuff,Shopping,200
|
||||
2024-01-01,Starbucks drink,Food & Drink,-8.55
|
||||
2024-01-01,Etsy,Shopping,-80.98
|
||||
2024-01-02,Amazon stuff,Shopping,-200
|
||||
2024-01-03,Paycheck,Income,1000
|
||||
created_at: <%= 2.days.ago %>
|
||||
|
||||
completed_import:
|
||||
|
@ -23,10 +27,10 @@ completed_import:
|
|||
amount: amount
|
||||
raw_csv_str: |
|
||||
date,name,category,amount
|
||||
2024-01-01,Starbucks drink,Food,20
|
||||
2024-01-01,Starbucks drink,Food & Drink,-20
|
||||
normalized_csv_str: |
|
||||
date,name,category,amount
|
||||
2024-01-01,Starbucks drink,Food,20
|
||||
2024-01-01,Starbucks drink,Food & Drink,-20
|
||||
created_at: <%= 2.days.ago %>
|
||||
|
||||
|
||||
|
|
|
@ -39,7 +39,10 @@ class ImportTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
test "publishes a valid import" do
|
||||
assert_difference -> { Transaction::Category.count } => 2, -> { Transaction.count } => 2 do
|
||||
# Import has 3 unique categories: "Food & Drink", "Income", and "Shopping" (x2)
|
||||
# Fixtures already define "Food & Drink" and "Income", so these should not be created
|
||||
# "Shopping" is a new category, but should only be created 1x during import
|
||||
assert_difference -> { Transaction.count } => 4, -> { Transaction::Category.count } => 1 do
|
||||
@loaded_import.publish
|
||||
end
|
||||
|
||||
|
|
|
@ -2,8 +2,9 @@ module ImportTestHelper
|
|||
def valid_csv_str
|
||||
<<-ROWS
|
||||
date,name,category,amount
|
||||
2024-01-01,Starbucks drink,Food,20
|
||||
2024-01-02,Amazon stuff,Shopping,200
|
||||
2024-01-01,Starbucks drink,Food,-20
|
||||
2024-01-02,Amazon stuff,Shopping,-200
|
||||
2024-01-03,Paycheck,Income,1000
|
||||
ROWS
|
||||
end
|
||||
|
||||
|
@ -17,8 +18,8 @@ module ImportTestHelper
|
|||
def valid_csv_with_missing_data
|
||||
<<-ROWS
|
||||
date,name,category,"optional id",amount
|
||||
2024-01-01,Drink,Food,1234,200
|
||||
2024-01-02,,,,100
|
||||
2024-01-01,Drink,Food,1234,-200
|
||||
2024-01-02,,,,-100
|
||||
ROWS
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue