def test_transfer_funds_error_debit_account_closed(self): # Create two accounts and deposit funds. account_id1 = self.accounts.create_account() account_id2 = self.accounts.create_account() transaction_id = self.commands.deposit_funds(account_id1, Decimal("200.00")) # Check saga errored. self.assertSagaHasSucceeded(transaction_id) # Check balance. self.assertBalanceEquals(account_id1, Decimal("200.00")) # Close account. self.accounts.close_account(account_id1) # Fail to transfer funds - account closed. transaction_id = self.commands.transfer_funds( debit_account_id=account_id1, credit_account_id=account_id2, amount=Decimal("50.00"), ) # Check saga errored. self.assertSagaHasNotSucceeded( transaction_id, [AccountClosedError({"account_id": account_id1})]) # Check balances - should be unchanged. self.assertBalanceEquals(account_id1, Decimal("200.00")) self.assertBalanceEquals(account_id2, Decimal("0.00"))
def test_transfer_funds_error_credit_account_closed(self): # Create two accounts and deposit funds. account_id1 = self.accounts.create_account() account_id2 = self.accounts.create_account() self.commands.deposit_funds(account_id2, Decimal("200.00")) # Close account. self.accounts.close_account(account_id1) # Fail to transfer funds - account closed. transaction_id = self.commands.transfer_funds( debit_account_id=account_id2, credit_account_id=account_id1, amount=Decimal("50.00"), ) # Check saga errored. self.assertFalse(self.sagas.get_saga(transaction_id).has_succeeded) self.assertTrue(self.sagas.get_saga(transaction_id).has_errored) errors = self.sagas.get_saga(transaction_id).errors self.assertEqual(len(errors), 1) self.assertEqual(errors[0], AccountClosedError({"account_id": account_id1})) # Check balances - should be unchanged. self.assertEqual(self.accounts.get_balance(account_id1), Decimal("0.00")) self.assertEqual(self.accounts.get_balance(account_id2), Decimal("200.00"))
def test_deposit_funds_error_account_closed(self): # Create an account. account_id1 = self.accounts.create_account() # Close account. self.accounts.close_account(account_id1) # Deposit funds. transaction_id = self.commands.deposit_funds(account_id1, Decimal("200.00")) # Check saga errored. self.assertSagaHasNotSucceeded( transaction_id, [AccountClosedError({"account_id": account_id1})]) # Check balance. self.assertBalanceEquals(account_id1, Decimal("0.00"))
def test_withdraw_funds_error_account_closed(self): # Create an account and deposit funds. account_id1 = self.accounts.create_account() transaction_id = self.commands.deposit_funds(account_id1, Decimal("200.00")) self.assertSagaHasSucceeded(transaction_id) # Close account. self.accounts.close_account(account_id1) # Fail to withdraw funds - account closed. transaction_id = self.commands.withdraw_funds( debit_account_id=account_id1, amount=Decimal("50.00")) # Check saga errored. self.assertSagaHasNotSucceeded( transaction_id, [AccountClosedError({"account_id": account_id1})]) # Check balance. self.assertBalanceEquals(account_id1, Decimal("200.00"))
def test_deposit_funds_error_account_closed(self): # Create an account. account_id1 = self.accounts.create_account() # Close account. self.accounts.close_account(account_id1) # Deposit funds. transaction_id = self.commands.deposit_funds(account_id1, Decimal("200.00")) # Check saga errored. self.assertFalse(self.sagas.get_saga(transaction_id).has_succeeded) self.assertTrue(self.sagas.get_saga(transaction_id).has_errored) errors = self.sagas.get_saga(transaction_id).errors self.assertEqual(len(errors), 1) self.assertEqual(errors[0], AccountClosedError({"account_id": account_id1})) # Check balance. self.assertEqual(self.accounts.get_balance(account_id1), Decimal("0.00"))
def check_account_is_not_closed(self) -> None: if self.is_closed: raise AccountClosedError({"account_id": self.id})