mirror of
https://github.com/we-promise/sure.git
synced 2026-04-07 22:34:47 +00:00
* Implement providers factory * Multiple providers sync support - Proper Multi-Provider Syncing: When you click sync on an account with multiple providers (e.g., both Plaid and SimpleFin), all provider items are synced - Better API: The existing account.providers method already returns all providers, and account.provider returns the first one for backward compatibility - Correct Holdings Deletion Logic: Holdings can only be deleted if ALL providers allow it, preventing accidental deletions that would be recreated on next sync TODO: validate this is the way we want to go? We would need to check holdings belong to which account, and then check provider allows deletion. More complex - Database Constraints: The existing validations ensure an account can have at most one provider of each type (one PlaidAccount, one SimplefinAccount, etc.) * Add generic provider_import_adapter * Finish unified import strategy * Update app/models/plaid_account.rb Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Signed-off-by: soky srm <sokysrm@gmail.com> * Update app/models/provider/factory.rb Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Signed-off-by: soky srm <sokysrm@gmail.com> * Fix account linked by plaid_id instead of external_id * Parse numerics to BigDecimal Parse numerics to BigDecimal before computing amount; guard nils. Avoid String * String and float drift; also normalize date. * Fix incorrect usage of assert_raises. * Fix linter * Fix processor test. * Update current_balance_manager.rb * Test fixes * Fix plaid linked account test * Add support for holding per account_provider * Fix proper account access Also fix account deletion for simpefin too * FIX match tests for consistency * Some more factory updates * Fix account schema for multipe providers Can do: - Account #1 → PlaidAccount + SimplefinAccount (multiple different providers) - Account #2 → PlaidAccount only - Account #3 → SimplefinAccount only Cannot do: - Account #1 → PlaidAccount + PlaidAccount (duplicate provider type) - PlaidAccount #123 → Account #1 + Account #2 (provider linked to multiple accounts) * Fix account setup - An account CAN have multiple providers (the schema shows account_providers with unique index on [account_id, provider_type]) - Each provider should maintain its own separate entries - We should NOT update one provider's entry when another provider syncs * Fix linter and guard migration * FIX linter issues. * Fixes - Remove duplicated index - Pass account_provider_id - Guard holdings call to avoid NoMethodError * Update schema and provider import fix * Plaid doesn't allow holdings deletion * Use ClimateControl for proper env setup * No need for this in .git --------- Signed-off-by: soky srm <sokysrm@gmail.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
141 lines
5.0 KiB
Ruby
141 lines
5.0 KiB
Ruby
# Shared test interface for all provider adapters
|
|
# Include this module in your provider adapter test to ensure it implements the required interface
|
|
#
|
|
# Usage:
|
|
# class Provider::AcmeAdapterTest < ActiveSupport::TestCase
|
|
# include ProviderAdapterTestInterface
|
|
#
|
|
# setup do
|
|
# @adapter = Provider::AcmeAdapter.new(...)
|
|
# end
|
|
#
|
|
# def adapter
|
|
# @adapter
|
|
# end
|
|
#
|
|
# test_provider_adapter_interface
|
|
# end
|
|
module ProviderAdapterTestInterface
|
|
extend ActiveSupport::Concern
|
|
|
|
class_methods do
|
|
# Tests the core provider adapter interface
|
|
# Call this method in your test class to run all interface tests
|
|
def test_provider_adapter_interface
|
|
test "adapter implements provider_name" do
|
|
assert_respond_to adapter, :provider_name
|
|
assert_kind_of String, adapter.provider_name
|
|
assert adapter.provider_name.present?, "provider_name should not be blank"
|
|
end
|
|
|
|
test "adapter implements provider_type" do
|
|
assert_respond_to adapter, :provider_type
|
|
assert_kind_of String, adapter.provider_type
|
|
assert adapter.provider_type.present?, "provider_type should not be blank"
|
|
end
|
|
|
|
test "adapter implements can_delete_holdings?" do
|
|
assert_respond_to adapter, :can_delete_holdings?
|
|
assert_includes [ true, false ], adapter.can_delete_holdings?
|
|
end
|
|
|
|
test "adapter implements metadata" do
|
|
assert_respond_to adapter, :metadata
|
|
metadata = adapter.metadata
|
|
|
|
assert_kind_of Hash, metadata
|
|
assert_includes metadata.keys, :provider_name
|
|
assert_includes metadata.keys, :provider_type
|
|
|
|
assert_equal adapter.provider_name, metadata[:provider_name]
|
|
assert_equal adapter.provider_type, metadata[:provider_type]
|
|
end
|
|
|
|
test "adapter implements raw_payload" do
|
|
assert_respond_to adapter, :raw_payload
|
|
# raw_payload can be nil or a Hash
|
|
assert adapter.raw_payload.nil? || adapter.raw_payload.is_a?(Hash)
|
|
end
|
|
|
|
test "adapter is registered with factory" do
|
|
provider_type = adapter.provider_type
|
|
assert_includes Provider::Factory.registered_provider_types, provider_type,
|
|
"#{provider_type} should be registered with Provider::Factory"
|
|
end
|
|
end
|
|
|
|
# Tests for adapters that include Provider::Syncable
|
|
def test_syncable_interface
|
|
test "syncable adapter implements sync_path" do
|
|
assert_respond_to adapter, :sync_path
|
|
assert_kind_of String, adapter.sync_path
|
|
assert adapter.sync_path.present?, "sync_path should not be blank"
|
|
end
|
|
|
|
test "syncable adapter implements item" do
|
|
assert_respond_to adapter, :item
|
|
assert_not_nil adapter.item, "item should not be nil for syncable providers"
|
|
end
|
|
|
|
test "syncable adapter implements syncing?" do
|
|
assert_respond_to adapter, :syncing?
|
|
assert_includes [ true, false ], adapter.syncing?
|
|
end
|
|
|
|
test "syncable adapter implements status" do
|
|
assert_respond_to adapter, :status
|
|
# status can be nil or a String
|
|
assert adapter.status.nil? || adapter.status.is_a?(String)
|
|
end
|
|
|
|
test "syncable adapter implements requires_update?" do
|
|
assert_respond_to adapter, :requires_update?
|
|
assert_includes [ true, false ], adapter.requires_update?
|
|
end
|
|
end
|
|
|
|
# Tests for adapters that include Provider::InstitutionMetadata
|
|
def test_institution_metadata_interface
|
|
test "institution metadata adapter implements institution_domain" do
|
|
assert_respond_to adapter, :institution_domain
|
|
# Can be nil or String
|
|
assert adapter.institution_domain.nil? || adapter.institution_domain.is_a?(String)
|
|
end
|
|
|
|
test "institution metadata adapter implements institution_name" do
|
|
assert_respond_to adapter, :institution_name
|
|
# Can be nil or String
|
|
assert adapter.institution_name.nil? || adapter.institution_name.is_a?(String)
|
|
end
|
|
|
|
test "institution metadata adapter implements institution_url" do
|
|
assert_respond_to adapter, :institution_url
|
|
# Can be nil or String
|
|
assert adapter.institution_url.nil? || adapter.institution_url.is_a?(String)
|
|
end
|
|
|
|
test "institution metadata adapter implements institution_color" do
|
|
assert_respond_to adapter, :institution_color
|
|
# Can be nil or String
|
|
assert adapter.institution_color.nil? || adapter.institution_color.is_a?(String)
|
|
end
|
|
|
|
test "institution metadata adapter implements institution_metadata" do
|
|
assert_respond_to adapter, :institution_metadata
|
|
metadata = adapter.institution_metadata
|
|
|
|
assert_kind_of Hash, metadata
|
|
# Metadata should only contain non-nil values
|
|
metadata.each do |key, value|
|
|
assert_not_nil value, "#{key} in institution_metadata should not be nil (it should be omitted instead)"
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
# Override this method in your test to provide the adapter instance
|
|
def adapter
|
|
raise NotImplementedError, "Test must implement #adapter method"
|
|
end
|
|
end
|