def test_create_account_command(client): user_id = "TEST_ID" create_account_command = { "type": "CREATE", "payload": { "balance": 0, "user_id": user_id } } r = client.post('/accounts/commands/', data=json.dumps(create_account_command)) account = Account.query.filter_by(user_id=user_id).first() assert account is not None, "New account not added" assert r.status == '202 ACCEPTED', "Response was not a 202" version = Constants.query.filter_by(key='accounts_version').first() assert version.value == 1, "Aggregate version not updated"
def test_delete_account_command(client): account_id = "TEST_ID" new_account = Account(id=account_id, balance=100, user_id="Bob") db.session.add(new_account) db.session.commit() delete_account_command = { "type": "DELETE", "payload": { "account_id": account_id } } r = client.post('/accounts/commands/', data=json.dumps(delete_account_command)) accounts = Account.query.all() assert len(accounts) == 0, "Account was not deleted" assert r.status == '202 ACCEPTED', "Response not 202" version = Constants.query.filter_by(key='accounts_version').first() assert version.value == 1, "Aggregate version not updated"
def test_deposit_created_event(client): new_account = Account(id="account_id", balance=100, user_id="Bob") db.session.add(new_account) db.session.commit() deposit_created_event = { "type": "DEPOSIT_CREATED", "command_id": "test", "payload": { "account_id": "account_id", "amount": 50, "transaction_id": "transaction_id" } } r = client.post('/accounts/events/', data=json.dumps(deposit_created_event)) account = Account.query.filter_by(id="account_id").first() assert account.balance == 150, "Account balance was not increased." assert r.status == '202 ACCEPTED', "Response not 202" version = Constants.query.filter_by(key='accounts_version').first() assert version.value == 1, "Aggregate version not updated"