"""BankingDetailsMigration tests.""" from src.models import ( Address, BankFieldDetail, Company, Contact, PayeeDetails, PayoutMethod, ) from src.processors.banking_details.utils import ( map_row_to_payout_method, map_to_banking_details, ) def test_map_row_to_payout_method() -> None: row = { 'bankAccountType': 'checking', 'bankCountry': 'US', 'currency': 'USD', 'BankName': 'Privatbank', 'Swift': '123345', } result = map_row_to_payout_method(row) expected = PayoutMethod( bank_account_type='CHECKING', country='US', currency='USD', bank_field_details=[ BankFieldDetail(name='BankName', value='Privatbank'), BankFieldDetail(name='Swift', value='123345'), ], ) assert result == expected def test_map_row_to_payout_method_remap() -> None: row = { 'bankAccountType': 'checking', 'bankCountry': 'US', 'currency': 'USD', 'OtherBankName': 'Privatbank', 'OtherAccountType': 'SomeAccountType', 'Swift': '123345', } result = map_row_to_payout_method(row) expected = PayoutMethod( bank_account_type='CHECKING', country='US', currency='USD', bank_field_details=[ BankFieldDetail(name='Swift', value='123345'), BankFieldDetail(name='BankName', value='Privatbank'), BankFieldDetail(name='AccountType', value='SomeAccountType'), ], ) assert result == expected def test_map_row_to_payout_method_remap_keep() -> None: row = { 'bankAccountType': 'checking', 'bankCountry': 'US', 'currency': 'USD', 'BankName': 'Privatbank', 'AccountType': 'SomeAccountType', 'OtherBankName': 'Privatbank2', 'OtherAccountType': 'SomeAccountType2', 'Swift': '123345', } result = map_row_to_payout_method(row) expected = PayoutMethod( bank_account_type='CHECKING', country='US', currency='USD', bank_field_details=[ BankFieldDetail(name='BankName', value='Privatbank'), BankFieldDetail(name='Swift', value='123345'), BankFieldDetail(name='AccountType', value='SomeAccountType'), ], ) assert result == expected def test_map_row_to_banking_details() -> None: account_payee_id = 123 row = { 'vendorId': '123', 'payeeType': 'individual', 'firstName': 'John', 'lastName': 'Doe', 'dateOfBirth': '1990-01-01', 'email': 'john.doe@example.com', 'companyName': 'TechCorp', 'address1': '123 Main St', 'address2': 'Apt 4B', 'city': 'Metropolis', 'province': 'MetroState', 'postal_code': '12345', 'bankAccountType': 'checking', 'country': 'CO', 'bankCountry': 'US', 'currency': 'USD', 'BankName': 'Privatbank', 'Swift': '123345', } result = map_to_banking_details(row, account_payee_id) expected = PayeeDetails( account_payee_id=account_payee_id, type='INDIVIDUAL', contact=Contact( first_name='John', last_name='Doe', date_of_birth='1990-01-01', email='john.doe@example.com', ), company=Company(name='TechCorp'), address=Address( country_code='CO', address_1='123 Main St', address_2='Apt 4B', city='Metropolis', province='MetroState', zip='12345', ), payout_method=PayoutMethod( bank_account_type='CHECKING', country='US', currency='USD', bank_field_details=[ BankFieldDetail(name='BankName', value='Privatbank'), BankFieldDetail(name='Swift', value='123345'), ], ), ) assert result == expected def test_missing_first_name() -> None: account_payee_id = 123 row = { 'vendorId': '123', 'payeeType': 'individual', 'lastName': 'Doe', 'dateOfBirth': '1990-01-01', 'email': 'john.doe@example.com', 'companyName': 'TechCorp', 'address1': '123 Main St', 'address2': 'Apt 4B', 'city': 'Metropolis', 'state': 'MetroState', 'postal_code': '12345', 'bankAccountType': 'checking', 'country': 'CO', 'bankCountry': 'US', 'currency': 'USD', } result = map_to_banking_details(row, account_payee_id) expected = PayeeDetails( account_payee_id=account_payee_id, type='INDIVIDUAL', contact=Contact( first_name=None, # first_name is missing last_name='Doe', date_of_birth='1990-01-01', email='john.doe@example.com', ), company=Company(name='TechCorp'), address=Address( country_code='CO', address_1='123 Main St', address_2='Apt 4B', city='Metropolis', province='MetroState', zip='12345', ), payout_method=PayoutMethod( bank_account_type='CHECKING', country='US', currency='USD', bank_field_details=[], ), ) assert result == expected expected_json = { 'account_payee_id': account_payee_id, 'type': 'INDIVIDUAL', 'contact': { 'last_name': 'Doe', 'date_of_birth': '1990-01-01', 'email': 'john.doe@example.com', }, 'company': {'name': 'TechCorp'}, 'address': { 'country_code': 'CO', 'address_1': '123 Main St', 'address_2': 'Apt 4B', 'city': 'Metropolis', 'province': 'MetroState', 'zip': '12345', }, 'payout_method': { 'bank_account_type': 'CHECKING', 'country': 'US', 'currency': 'USD', 'bank_field_details': [], }, } assert result.model_dump() == expected_json def test_missing_type() -> None: account_payee_id = 123 row = { 'vendorId': '123', 'firstName': 'John', 'lastName': 'Doe', 'dateOfBirth': '1990-01-01', 'email': 'john.doe@example.com', 'companyName': 'TechCorp', 'address1': '123 Main St', 'address2': 'Apt 4B', 'city': 'Metropolis', 'province': 'MetroState', 'postal_code': '12345', 'bankAccountType': 'checking', 'country': 'CO', 'bankCountry': 'US', 'currency': 'USD', } result = map_to_banking_details(row, account_payee_id) expected = PayeeDetails( account_payee_id=account_payee_id, type=None, # type is missing contact=Contact( first_name='John', last_name='Doe', date_of_birth='1990-01-01', email='john.doe@example.com', ), company=Company(name='TechCorp'), address=Address( country_code='CO', address_1='123 Main St', address_2='Apt 4B', city='Metropolis', province='MetroState', zip='12345', ), payout_method=PayoutMethod( bank_account_type='CHECKING', country='US', currency='USD', bank_field_details=[], ), ) assert result == expected expected_json = { 'account_payee_id': account_payee_id, 'contact': { 'first_name': 'John', 'last_name': 'Doe', 'date_of_birth': '1990-01-01', 'email': 'john.doe@example.com', }, 'company': {'name': 'TechCorp'}, 'address': { 'country_code': 'CO', 'address_1': '123 Main St', 'address_2': 'Apt 4B', 'city': 'Metropolis', 'province': 'MetroState', 'zip': '12345', }, 'payout_method': { 'bank_account_type': 'CHECKING', 'country': 'US', 'currency': 'USD', 'bank_field_details': [], }, } assert result.model_dump() == expected_json def test_missing_address_2() -> None: account_payee_id = 123 row = { 'vendorId': '123', 'payeeType': 'individual', 'firstName': 'John', 'lastName': 'Doe', 'dateOfBirth': '1990-01-01', 'email': 'john.doe@example.com', 'companyName': 'TechCorp', 'address1': '123 Main St', 'city': 'Metropolis', 'province': 'MetroState', 'postal_code': '12345', 'bankAccountType': 'checking', 'country': 'CO', 'bankCountry': 'US', 'currency': 'USD', } result = map_to_banking_details(row, account_payee_id) expected = PayeeDetails( account_payee_id=account_payee_id, type='INDIVIDUAL', contact=Contact( first_name='John', last_name='Doe', date_of_birth='1990-01-01', email='john.doe@example.com', ), company=Company(name='TechCorp'), address=Address( country_code='CO', address_1='123 Main St', address_2=None, # address_2 is missing city='Metropolis', province='MetroState', zip='12345', ), payout_method=PayoutMethod( bank_account_type='CHECKING', country='US', currency='USD', bank_field_details=[], ), ) assert result == expected expected_json = { 'account_payee_id': account_payee_id, 'type': 'INDIVIDUAL', 'contact': { 'first_name': 'John', 'last_name': 'Doe', 'date_of_birth': '1990-01-01', 'email': 'john.doe@example.com', }, 'company': {'name': 'TechCorp'}, 'address': { 'country_code': 'CO', 'address_1': '123 Main St', 'city': 'Metropolis', 'province': 'MetroState', 'zip': '12345', }, 'payout_method': { 'bank_account_type': 'CHECKING', 'country': 'US', 'currency': 'USD', 'bank_field_details': [], }, } assert result.model_dump() == expected_json def test_missing_province() -> None: account_payee_id = 123 row = { 'vendorId': '123', 'payeeType': 'individual', 'firstName': 'John', 'lastName': 'Doe', 'dateOfBirth': '1990-01-01', 'email': 'john.doe@example.com', 'companyName': 'TechCorp', 'address1': '123 Main St', 'address2': 'Apt 4B', 'city': 'Metropolis', 'postal_code': '12345', 'bankAccountType': 'checking', 'country': 'CO', 'bankCountry': 'US', 'currency': 'USD', } result = map_to_banking_details(row, account_payee_id) expected = PayeeDetails( account_payee_id=account_payee_id, type='INDIVIDUAL', contact=Contact( first_name='John', last_name='Doe', date_of_birth='1990-01-01', email='john.doe@example.com', ), company=Company(name='TechCorp'), address=Address( country_code='CO', address_1='123 Main St', address_2='Apt 4B', city='Metropolis', province=None, # province is missing zip='12345', ), payout_method=PayoutMethod( bank_account_type='CHECKING', country='US', currency='USD', bank_field_details=[], ), ) assert result == expected expected_json = { 'account_payee_id': account_payee_id, 'type': 'INDIVIDUAL', 'contact': { 'first_name': 'John', 'last_name': 'Doe', 'date_of_birth': '1990-01-01', 'email': 'john.doe@example.com', }, 'company': {'name': 'TechCorp'}, 'address': { 'country_code': 'CO', 'address_1': '123 Main St', 'address_2': 'Apt 4B', 'city': 'Metropolis', 'zip': '12345', }, 'payout_method': { 'bank_account_type': 'CHECKING', 'country': 'US', 'currency': 'USD', 'bank_field_details': [], }, } assert result.model_dump() == expected_json def test_missing_company_name() -> None: account_payee_id = 123 row = { 'vendorId': '123', 'payeeType': 'individual', 'firstName': 'John', 'lastName': 'Doe', 'dateOfBirth': '1990-01-01', 'email': 'john.doe@example.com', 'address1': '123 Main St', 'address2': 'Apt 4B', 'city': 'Metropolis', 'province': 'MetroState', 'postal_code': '12345', 'bankAccountType': 'checking', 'country': 'CO', 'bankCountry': 'US', 'currency': 'USD', } result = map_to_banking_details(row, account_payee_id) expected = PayeeDetails( account_payee_id=account_payee_id, type='INDIVIDUAL', contact=Contact( first_name='John', last_name='Doe', date_of_birth='1990-01-01', email='john.doe@example.com', ), company=Company(name=None), # companyName is missing address=Address( country_code='CO', address_1='123 Main St', address_2='Apt 4B', city='Metropolis', province='MetroState', zip='12345', ), payout_method=PayoutMethod( bank_account_type='CHECKING', country='US', currency='USD', bank_field_details=[], ), ) assert result == expected expected_json = { 'account_payee_id': account_payee_id, 'type': 'INDIVIDUAL', 'contact': { 'first_name': 'John', 'last_name': 'Doe', 'date_of_birth': '1990-01-01', 'email': 'john.doe@example.com', }, 'address': { 'country_code': 'CO', 'address_1': '123 Main St', 'address_2': 'Apt 4B', 'city': 'Metropolis', 'province': 'MetroState', 'zip': '12345', }, 'payout_method': { 'bank_account_type': 'CHECKING', 'country': 'US', 'currency': 'USD', 'bank_field_details': [], }, } assert result.model_dump() == expected_json def test_missing_currency() -> None: account_payee_id = 123 row = { 'vendorId': '123', 'payeeType': 'individual', 'firstName': 'John', 'lastName': 'Doe', 'dateOfBirth': '1990-01-01', 'email': 'john.doe@example.com', 'companyName': 'TechCorp', 'address1': '123 Main St', 'address2': 'Apt 4B', 'city': 'Metropolis', 'province': 'MetroState', 'postal_code': '12345', 'bankAccountType': 'checking', 'country': 'CO', 'bankCountry': 'US', } result = map_to_banking_details(row, account_payee_id) expected = PayeeDetails( account_payee_id=account_payee_id, type='INDIVIDUAL', contact=Contact( first_name='John', last_name='Doe', date_of_birth='1990-01-01', email='john.doe@example.com', ), company=Company(name='TechCorp'), address=Address( country_code='CO', address_1='123 Main St', address_2='Apt 4B', city='Metropolis', province='MetroState', zip='12345', ), payout_method=PayoutMethod( bank_account_type='CHECKING', country='US', currency=None, # currency is missing bank_field_details=[], ), ) assert result == expected expected_json = { 'account_payee_id': account_payee_id, 'type': 'INDIVIDUAL', 'contact': { 'first_name': 'John', 'last_name': 'Doe', 'date_of_birth': '1990-01-01', 'email': 'john.doe@example.com', }, 'company': {'name': 'TechCorp'}, 'address': { 'country_code': 'CO', 'address_1': '123 Main St', 'address_2': 'Apt 4B', 'city': 'Metropolis', 'province': 'MetroState', 'zip': '12345', }, 'payout_method': { 'bank_account_type': 'CHECKING', 'country': 'US', 'bank_field_details': [], }, } assert result.model_dump() == expected_json def test_company_name_is_empty() -> None: account_payee_id = 123 row = { 'vendorId': '123', 'payeeType': 'individual', 'companyName': '', 'firstName': 'John', 'lastName': 'Doe', 'dateOfBirth': '1990-01-01', 'email': 'john.doe@example.com', 'address1': '123 Main St', 'address2': 'Apt 4B', 'city': 'Metropolis', 'province': 'MetroState', 'postal_code': '12345', 'bankAccountType': 'checking', 'country': 'CO', 'bankCountry': 'US', 'currency': 'USD', } result = map_to_banking_details(row, account_payee_id) expected = PayeeDetails( account_payee_id=account_payee_id, type='INDIVIDUAL', contact=Contact( first_name='John', last_name='Doe', date_of_birth='1990-01-01', email='john.doe@example.com', ), company=Company(name=''), # companyName is missing address=Address( country_code='CO', address_1='123 Main St', address_2='Apt 4B', city='Metropolis', province='MetroState', zip='12345', ), payout_method=PayoutMethod( bank_account_type='CHECKING', country='US', currency='USD', bank_field_details=[], ), ) assert result == expected expected_json = { 'account_payee_id': account_payee_id, 'type': 'INDIVIDUAL', 'contact': { 'first_name': 'John', 'last_name': 'Doe', 'date_of_birth': '1990-01-01', 'email': 'john.doe@example.com', }, 'address': { 'country_code': 'CO', 'address_1': '123 Main St', 'address_2': 'Apt 4B', 'city': 'Metropolis', 'province': 'MetroState', 'zip': '12345', }, 'payout_method': { 'bank_account_type': 'CHECKING', 'country': 'US', 'currency': 'USD', 'bank_field_details': [], }, } assert result.model_dump() == expected_json