mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 16:34:46 +00:00
refactor(test): make loyalty point entry deterministic
This commit is contained in:
@@ -9,22 +9,13 @@ from erpnext.tests.utils import ERPNextTestSuite
|
|||||||
|
|
||||||
|
|
||||||
class TestLoyaltyPointEntry(ERPNextTestSuite):
|
class TestLoyaltyPointEntry(ERPNextTestSuite):
|
||||||
@classmethod
|
def setUp(self):
|
||||||
def setUpClass(cls):
|
|
||||||
super().setUpClass()
|
|
||||||
# Create test records
|
# Create test records
|
||||||
cls.loyalty_program_name = "Test Single Loyalty"
|
self.loyalty_program_name = "Test Single Loyalty"
|
||||||
cls.customer_name = "Test Loyalty Customer"
|
self.customer_name = "Test Loyalty Customer"
|
||||||
customer = frappe.get_doc("Customer", cls.customer_name)
|
customer = frappe.get_doc("Customer", self.customer_name)
|
||||||
customer.db_set("loyalty_program", cls.loyalty_program_name)
|
customer.loyalty_program = self.loyalty_program_name
|
||||||
|
customer.save()
|
||||||
@classmethod
|
|
||||||
def tearDownClass(cls):
|
|
||||||
# Delete all Loyalty Point Entries
|
|
||||||
frappe.db.sql("DELETE FROM `tabLoyalty Point Entry` WHERE customer = %s", cls.customer_name)
|
|
||||||
frappe.db.sql("DELETE FROM `tabSales Invoice` WHERE customer = %s", cls.customer_name)
|
|
||||||
frappe.db.commit()
|
|
||||||
# cls.customer.delete()
|
|
||||||
|
|
||||||
def create_test_invoice(self, redeem=None):
|
def create_test_invoice(self, redeem=None):
|
||||||
if redeem:
|
if redeem:
|
||||||
@@ -66,9 +57,10 @@ class TestLoyaltyPointEntry(ERPNextTestSuite):
|
|||||||
self.assertEqual(entry.discretionary_reason, "Customer Appreciation")
|
self.assertEqual(entry.discretionary_reason, "Customer Appreciation")
|
||||||
|
|
||||||
def test_redeem_loyalty_points(self):
|
def test_redeem_loyalty_points(self):
|
||||||
self.create_test_invoice(redeem=10)
|
self.create_test_invoice()
|
||||||
|
self.create_test_invoice(redeem=7)
|
||||||
doc = frappe.get_last_doc("Loyalty Point Entry")
|
doc = frappe.get_last_doc("Loyalty Point Entry")
|
||||||
self.assertEqual(doc.loyalty_points, -10)
|
self.assertEqual(doc.loyalty_points, -7)
|
||||||
|
|
||||||
# Check balance
|
# Check balance
|
||||||
balance = frappe.db.sql(
|
balance = frappe.db.sql(
|
||||||
@@ -80,4 +72,4 @@ class TestLoyaltyPointEntry(ERPNextTestSuite):
|
|||||||
(self.customer_name,),
|
(self.customer_name,),
|
||||||
)[0][0]
|
)[0][0]
|
||||||
|
|
||||||
self.assertEqual(balance, 75) # 85 added, 10 redeemed
|
self.assertEqual(balance, 3) # 10 added, 7 redeemed
|
||||||
|
|||||||
Reference in New Issue
Block a user