@@ -14,34 +14,39 @@ class TestPosInvoiceHooks(FrappeTestCase):
1414 def test_ensure_requires_transaction (self ):
1515 doc = SimpleNamespace (tse_transaction = None )
1616
17- with self .assertRaises (frappe .MandatoryError ):
18- pos_invoice_hooks .ensure_tse_transaction_present_and_finished (doc , None )
17+ with patch ("frappe.db.get_single_value" , return_value = 1 ):
18+ with self .assertRaises (frappe .MandatoryError ):
19+ pos_invoice_hooks .ensure_tse_transaction_present_and_finished (doc , None )
1920
2021 def test_ensure_requires_finished (self ):
2122 doc = SimpleNamespace (tse_transaction = "TX-1" )
2223
23- with patch ("frappe.get_doc" , return_value = SimpleNamespace (transaction_status = "ACTIVE" )):
24- with self .assertRaises (frappe .ValidationError ):
25- pos_invoice_hooks .ensure_tse_transaction_present_and_finished (doc , None )
24+ with patch ("frappe.db.get_single_value" , return_value = 1 ):
25+ with patch ("frappe.get_doc" , return_value = SimpleNamespace (transaction_status = "ACTIVE" )):
26+ with self .assertRaises (frappe .ValidationError ):
27+ pos_invoice_hooks .ensure_tse_transaction_present_and_finished (doc , None )
2628
2729 def test_ensure_passes_finished (self ):
2830 doc = SimpleNamespace (tse_transaction = "TX-1" )
2931
30- with patch ("frappe.get_doc" , return_value = SimpleNamespace (transaction_status = "FINISHED" )):
31- pos_invoice_hooks .ensure_tse_transaction_present_and_finished (doc , None )
32+ with patch ("frappe.db.get_single_value" , return_value = 1 ):
33+ with patch ("frappe.get_doc" , return_value = SimpleNamespace (transaction_status = "FINISHED" )):
34+ pos_invoice_hooks .ensure_tse_transaction_present_and_finished (doc , None )
3235
3336 def test_show_toast_requires_transaction (self ):
3437 doc = SimpleNamespace (tse_transaction = None )
3538
36- with self .assertRaises (frappe .ValidationError ):
37- pos_invoice_hooks .show_tse_signing_success_toast (doc )
39+ with patch ("frappe.db.get_single_value" , return_value = 1 ):
40+ with self .assertRaises (frappe .ValidationError ):
41+ pos_invoice_hooks .show_tse_signing_success_toast (doc )
3842
3943 def test_show_toast_success (self ):
4044 doc = SimpleNamespace (tse_transaction = "TX-1" )
4145 tse_doc = SimpleNamespace (name = "TX-1" , transaction_status = "FINISHED" )
4246
43- with patch ("frappe.get_doc" , return_value = tse_doc ), patch ("frappe.msgprint" ) as msgprint :
44- pos_invoice_hooks .show_tse_signing_success_toast (doc )
47+ with patch ("frappe.db.get_single_value" , return_value = 1 ):
48+ with patch ("frappe.get_doc" , return_value = tse_doc ), patch ("frappe.msgprint" ) as msgprint :
49+ pos_invoice_hooks .show_tse_signing_success_toast (doc )
4550
4651 _ , kwargs = msgprint .call_args
4752 self .assertEqual (kwargs .get ("indicator" ), "green" )
@@ -50,6 +55,19 @@ def test_show_toast_failure(self):
5055 doc = SimpleNamespace (tse_transaction = "TX-1" )
5156 tse_doc = SimpleNamespace (name = "TX-1" , transaction_status = "ACTIVE" )
5257
53- with patch ("frappe.get_doc" , return_value = tse_doc ):
54- with self .assertRaises (frappe .ValidationError ):
55- pos_invoice_hooks .show_tse_signing_success_toast (doc )
58+ with patch ("frappe.db.get_single_value" , return_value = 1 ):
59+ with patch ("frappe.get_doc" , return_value = tse_doc ):
60+ with self .assertRaises (frappe .ValidationError ):
61+ pos_invoice_hooks .show_tse_signing_success_toast (doc )
62+
63+ def test_ensure_skips_when_disabled (self ):
64+ doc = SimpleNamespace (tse_transaction = None )
65+
66+ with patch ("frappe.db.get_single_value" , return_value = 0 ):
67+ pos_invoice_hooks .ensure_tse_transaction_present_and_finished (doc , None )
68+
69+ def test_show_toast_skips_when_disabled (self ):
70+ doc = SimpleNamespace (tse_transaction = None )
71+
72+ with patch ("frappe.db.get_single_value" , return_value = 0 ):
73+ pos_invoice_hooks .show_tse_signing_success_toast (doc )
0 commit comments