2024-08-23 08:47:08 -04:00
|
|
|
require "test_helper"
|
|
|
|
|
|
|
|
class PropertiesControllerTest < ActionDispatch::IntegrationTest
|
2024-11-04 20:27:31 -05:00
|
|
|
include AccountableResourceInterfaceTest
|
|
|
|
|
2024-08-23 08:47:08 -04:00
|
|
|
setup do
|
|
|
|
sign_in @user = users(:family_admin)
|
|
|
|
@account = accounts(:property)
|
|
|
|
end
|
|
|
|
|
2024-11-04 20:27:31 -05:00
|
|
|
test "creates with property details" do
|
2024-08-23 08:47:08 -04:00
|
|
|
assert_difference -> { Account.count } => 1,
|
|
|
|
-> { Property.count } => 1,
|
|
|
|
-> { Account::Valuation.count } => 2,
|
|
|
|
-> { Account::Entry.count } => 2 do
|
|
|
|
post properties_path, params: {
|
|
|
|
account: {
|
|
|
|
name: "Property",
|
|
|
|
balance: 500000,
|
|
|
|
currency: "USD",
|
|
|
|
accountable_type: "Property",
|
|
|
|
accountable_attributes: {
|
|
|
|
year_built: 2002,
|
|
|
|
area_value: 1000,
|
|
|
|
area_unit: "sqft",
|
|
|
|
address_attributes: {
|
|
|
|
line1: "123 Main St",
|
|
|
|
line2: "Apt 1",
|
|
|
|
locality: "Los Angeles",
|
|
|
|
region: "CA", # ISO3166-2 code
|
|
|
|
country: "US", # ISO3166-1 Alpha-2 code
|
|
|
|
postal_code: "90001"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
created_account = Account.order(:created_at).last
|
|
|
|
|
2024-11-04 20:27:31 -05:00
|
|
|
assert created_account.accountable.year_built.present?
|
|
|
|
assert created_account.accountable.address.line1.present?
|
2024-08-23 08:47:08 -04:00
|
|
|
|
2024-11-04 20:27:31 -05:00
|
|
|
assert_redirected_to created_account
|
|
|
|
assert_equal "Property account created", flash[:notice]
|
2024-08-23 08:47:08 -04:00
|
|
|
assert_enqueued_with(job: AccountSyncJob)
|
|
|
|
end
|
|
|
|
|
2024-11-04 20:27:31 -05:00
|
|
|
test "updates with property details" do
|
2024-10-08 17:16:37 -04:00
|
|
|
assert_no_difference [ "Account.count", "Property.count" ] do
|
2024-11-04 20:27:31 -05:00
|
|
|
patch account_path(@account), params: {
|
2024-08-23 08:47:08 -04:00
|
|
|
account: {
|
|
|
|
name: "Updated Property",
|
|
|
|
balance: 500000,
|
|
|
|
currency: "USD",
|
|
|
|
accountable_type: "Property",
|
|
|
|
accountable_attributes: {
|
|
|
|
id: @account.accountable_id,
|
|
|
|
year_built: 2002,
|
|
|
|
area_value: 1000,
|
|
|
|
area_unit: "sqft",
|
|
|
|
address_attributes: {
|
|
|
|
line1: "123 Main St",
|
|
|
|
line2: "Apt 1",
|
|
|
|
locality: "Los Angeles",
|
|
|
|
region: "CA", # ISO3166-2 code
|
|
|
|
country: "US", # ISO3166-1 Alpha-2 code
|
|
|
|
postal_code: "90001"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2024-11-04 20:27:31 -05:00
|
|
|
assert_redirected_to @account
|
|
|
|
assert_equal "Property account updated", flash[:notice]
|
2024-08-23 08:47:08 -04:00
|
|
|
assert_enqueued_with(job: AccountSyncJob)
|
|
|
|
end
|
|
|
|
end
|