# -*- coding: utf-8 -*-
# Copyright (c) 2020, JINGROW
# See license.txt


import unittest

import jingrow

from jcloud.jcloud.pagetype.team.test_team import create_test_team


class TestBalanceTransaction(unittest.TestCase):
	def tearDown(self):
		jingrow.db.rollback()

	def test_team_balance(self):
		team = create_test_team()

		team.allocate_credit_amount(50, source="")
		self.assertEqual(team.get_balance(), 50)

		team.allocate_credit_amount(-10, source="")
		self.assertEqual(team.get_balance(), 40)

		team.allocate_credit_amount(100, source="")
		self.assertEqual(team.get_balance(), 140)

		self.assertEqual(jingrow.db.count("Balance Transaction", {"team": team.name}), 3)
