2024-11-15 13:49:37 -05:00
|
|
|
require "test_helper"
|
|
|
|
require "ostruct"
|
|
|
|
|
|
|
|
class PlaidItemsControllerTest < ActionDispatch::IntegrationTest
|
|
|
|
setup do
|
|
|
|
sign_in @user = users(:family_admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "create" do
|
2025-01-31 17:04:26 -05:00
|
|
|
@plaid_provider = mock
|
|
|
|
PlaidItem.expects(:plaid_provider_for_region).with("us").returns(@plaid_provider)
|
|
|
|
|
2024-11-15 13:49:37 -05:00
|
|
|
public_token = "public-sandbox-1234"
|
|
|
|
|
|
|
|
@plaid_provider.expects(:exchange_public_token).with(public_token).returns(
|
|
|
|
OpenStruct.new(access_token: "access-sandbox-1234", item_id: "item-sandbox-1234")
|
|
|
|
)
|
|
|
|
|
|
|
|
assert_difference "PlaidItem.count", 1 do
|
|
|
|
post plaid_items_url, params: {
|
|
|
|
plaid_item: {
|
|
|
|
public_token: public_token,
|
2025-01-31 12:13:58 -06:00
|
|
|
region: "us",
|
2024-11-15 13:49:37 -05:00
|
|
|
metadata: { institution: { name: "Plaid Item Name" } }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal "Account linked successfully. Please wait for accounts to sync.", flash[:notice]
|
|
|
|
assert_redirected_to accounts_path
|
|
|
|
end
|
|
|
|
|
|
|
|
test "destroy" do
|
|
|
|
delete plaid_item_url(plaid_items(:one))
|
|
|
|
|
|
|
|
assert_equal "Accounts scheduled for deletion.", flash[:notice]
|
|
|
|
assert_enqueued_with job: DestroyJob
|
|
|
|
assert_redirected_to accounts_path
|
|
|
|
end
|
|
|
|
|
|
|
|
test "sync" do
|
|
|
|
plaid_item = plaid_items(:one)
|
|
|
|
PlaidItem.any_instance.expects(:sync_later).once
|
|
|
|
|
|
|
|
post sync_plaid_item_url(plaid_item)
|
|
|
|
|
|
|
|
assert_redirected_to accounts_path
|
|
|
|
end
|
|
|
|
end
|