2024-08-09 11:22:57 -04:00
|
|
|
require "test_helper"
|
|
|
|
|
2025-04-14 11:40:34 -04:00
|
|
|
class ValuationsControllerTest < ActionDispatch::IntegrationTest
|
2024-11-27 16:01:50 -05:00
|
|
|
include EntryableResourceInterfaceTest
|
|
|
|
|
2024-08-09 11:22:57 -04:00
|
|
|
setup do
|
|
|
|
sign_in @user = users(:family_admin)
|
2025-04-14 11:40:34 -04:00
|
|
|
@entry = entries(:valuation)
|
2024-08-09 11:22:57 -04:00
|
|
|
end
|
|
|
|
|
2024-11-27 16:01:50 -05:00
|
|
|
test "error when valuation already exists for date" do
|
2025-04-14 11:40:34 -04:00
|
|
|
assert_no_difference [ "Entry.count", "Valuation.count" ] do
|
|
|
|
post valuations_url(@entry.account), params: {
|
|
|
|
entry: {
|
|
|
|
account_id: @entry.account_id,
|
2024-11-27 16:01:50 -05:00
|
|
|
amount: 19800,
|
|
|
|
date: @entry.date,
|
|
|
|
currency: "USD"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
2024-08-09 11:22:57 -04:00
|
|
|
|
2024-11-27 16:01:50 -05:00
|
|
|
assert_response :unprocessable_entity
|
2024-08-09 11:22:57 -04:00
|
|
|
end
|
|
|
|
|
2024-11-27 16:01:50 -05:00
|
|
|
test "creates entry with basic attributes" do
|
2025-04-14 11:40:34 -04:00
|
|
|
assert_difference [ "Entry.count", "Valuation.count" ], 1 do
|
|
|
|
post valuations_url, params: {
|
|
|
|
entry: {
|
2024-11-27 16:01:50 -05:00
|
|
|
name: "New entry",
|
|
|
|
amount: 10000,
|
|
|
|
currency: "USD",
|
2024-08-09 11:22:57 -04:00
|
|
|
date: Date.current,
|
2024-11-27 16:01:50 -05:00
|
|
|
account_id: @entry.account_id
|
2024-08-09 11:22:57 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2025-04-14 11:40:34 -04:00
|
|
|
created_entry = Entry.order(created_at: :desc).first
|
2024-11-27 16:01:50 -05:00
|
|
|
|
2024-11-15 13:49:37 -05:00
|
|
|
assert_enqueued_with job: SyncJob
|
2024-11-27 16:01:50 -05:00
|
|
|
|
|
|
|
assert_redirected_to account_url(created_entry.account)
|
2024-08-09 11:22:57 -04:00
|
|
|
end
|
|
|
|
|
2024-11-27 16:01:50 -05:00
|
|
|
test "updates entry with basic attributes" do
|
2025-04-14 11:40:34 -04:00
|
|
|
assert_no_difference [ "Entry.count", "Valuation.count" ] do
|
|
|
|
patch valuation_url(@entry), params: {
|
|
|
|
entry: {
|
2024-11-27 16:01:50 -05:00
|
|
|
name: "Updated entry",
|
|
|
|
amount: 20000,
|
|
|
|
currency: "USD",
|
|
|
|
date: Date.current
|
2024-08-09 11:22:57 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2024-11-27 16:01:50 -05:00
|
|
|
assert_enqueued_with job: SyncJob
|
|
|
|
|
|
|
|
assert_redirected_to account_url(@entry.account)
|
2024-08-09 11:22:57 -04:00
|
|
|
end
|
|
|
|
end
|